mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
SILOptimizer: use BasicBlockSet instead of SmallPtrSet in various transformations.
It reduces compile time.
This commit is contained in:
@@ -62,6 +62,7 @@
|
||||
#include "swift/SIL/InstructionUtils.h"
|
||||
#include "swift/SIL/Projection.h"
|
||||
#include "swift/SIL/LoopInfo.h"
|
||||
#include "swift/SIL/SILBitfield.h"
|
||||
#include "swift/SIL/SILCloner.h"
|
||||
#include "llvm/ADT/SmallSet.h"
|
||||
#include "llvm/Support/CommandLine.h"
|
||||
@@ -86,18 +87,20 @@ class ArrayPropertiesAnalysis {
|
||||
llvm::DenseMap<SILFunction *, uint32_t> InstCountCache;
|
||||
llvm::SmallSet<SILValue, 16> HoistableArray;
|
||||
|
||||
SmallPtrSet<SILBasicBlock *, 16> ReachingBlocks;
|
||||
SmallPtrSet<SILBasicBlock *, 16> CachedExitingBlocks;
|
||||
BasicBlockSet ReachingBlocks;
|
||||
SmallVector<SILBasicBlock *, 16> CachedExitingBlocks;
|
||||
|
||||
// This controls the max instructions the analysis can scan before giving up
|
||||
const uint32_t AnalysisThreshold = 5000;
|
||||
// This controls the max threshold for instruction count in the loop
|
||||
const uint32_t LoopInstCountThreshold = 500;
|
||||
|
||||
bool reachingBlocksComputed = false;
|
||||
|
||||
public:
|
||||
ArrayPropertiesAnalysis(SILLoop *L, DominanceAnalysis *DA)
|
||||
: Fun(L->getHeader()->getParent()), Loop(L), Preheader(nullptr),
|
||||
DomTree(DA->get(Fun)) {}
|
||||
DomTree(DA->get(Fun)), ReachingBlocks(Fun) {}
|
||||
|
||||
/// Check if it is profitable to specialize a loop when you see an apply
|
||||
/// instruction. We consider it is not profitable to specialize the loop when:
|
||||
@@ -239,18 +242,19 @@ private:
|
||||
return V;
|
||||
}
|
||||
|
||||
SmallPtrSetImpl<SILBasicBlock *> &getReachingBlocks() {
|
||||
if (ReachingBlocks.empty()) {
|
||||
BasicBlockSet &getReachingBlocks() {
|
||||
if (!reachingBlocksComputed) {
|
||||
SmallVector<SILBasicBlock *, 8> Worklist;
|
||||
ReachingBlocks.insert(Preheader);
|
||||
Worklist.push_back(Preheader);
|
||||
while (!Worklist.empty()) {
|
||||
SILBasicBlock *BB = Worklist.pop_back_val();
|
||||
for (auto PI = BB->pred_begin(), PE = BB->pred_end(); PI != PE; ++PI) {
|
||||
if (ReachingBlocks.insert(*PI).second)
|
||||
if (ReachingBlocks.insert(*PI))
|
||||
Worklist.push_back(*PI);
|
||||
}
|
||||
}
|
||||
reachingBlocksComputed = true;
|
||||
}
|
||||
return ReachingBlocks;
|
||||
}
|
||||
@@ -279,7 +283,7 @@ private:
|
||||
|
||||
// Check if this escape can reach the current loop.
|
||||
if (!Loop->contains(UseInst->getParent()) &&
|
||||
!getReachingBlocks().count(UseInst->getParent())) {
|
||||
!getReachingBlocks().contains(UseInst->getParent())) {
|
||||
continue;
|
||||
}
|
||||
LLVM_DEBUG(llvm::dbgs()
|
||||
@@ -356,12 +360,10 @@ private:
|
||||
return false;
|
||||
}
|
||||
|
||||
SmallPtrSetImpl<SILBasicBlock *> &getLoopExitingBlocks() {
|
||||
SmallVectorImpl<SILBasicBlock *> &getLoopExitingBlocks() {
|
||||
if (!CachedExitingBlocks.empty())
|
||||
return CachedExitingBlocks;
|
||||
SmallVector<SILBasicBlock *, 16> ExitingBlocks;
|
||||
Loop->getExitingBlocks(ExitingBlocks);
|
||||
CachedExitingBlocks.insert(ExitingBlocks.begin(), ExitingBlocks.end());
|
||||
Loop->getExitingBlocks(CachedExitingBlocks);
|
||||
return CachedExitingBlocks;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user