62
62
#include " swift/SIL/InstructionUtils.h"
63
63
#include " swift/SIL/Projection.h"
64
64
#include " swift/SIL/LoopInfo.h"
65
+ #include " swift/SIL/SILBitfield.h"
65
66
#include " swift/SIL/SILCloner.h"
66
67
#include " llvm/ADT/SmallSet.h"
67
68
#include " llvm/Support/CommandLine.h"
@@ -86,18 +87,20 @@ class ArrayPropertiesAnalysis {
86
87
llvm::DenseMap<SILFunction *, uint32_t > InstCountCache;
87
88
llvm::SmallSet<SILValue, 16 > HoistableArray;
88
89
89
- SmallPtrSet<SILBasicBlock *, 16 > ReachingBlocks;
90
- SmallPtrSet <SILBasicBlock *, 16 > CachedExitingBlocks;
90
+ BasicBlockSet ReachingBlocks;
91
+ SmallVector <SILBasicBlock *, 16 > CachedExitingBlocks;
91
92
92
93
// This controls the max instructions the analysis can scan before giving up
93
94
const uint32_t AnalysisThreshold = 5000 ;
94
95
// This controls the max threshold for instruction count in the loop
95
96
const uint32_t LoopInstCountThreshold = 500 ;
96
97
98
+ bool reachingBlocksComputed = false ;
99
+
97
100
public:
98
101
ArrayPropertiesAnalysis (SILLoop *L, DominanceAnalysis *DA)
99
102
: Fun(L->getHeader ()->getParent()), Loop(L), Preheader(nullptr ),
100
- DomTree(DA->get (Fun)) {}
103
+ DomTree(DA->get (Fun)), ReachingBlocks(Fun) {}
101
104
102
105
// / Check if it is profitable to specialize a loop when you see an apply
103
106
// / instruction. We consider it is not profitable to specialize the loop when:
@@ -239,18 +242,19 @@ class ArrayPropertiesAnalysis {
239
242
return V;
240
243
}
241
244
242
- SmallPtrSetImpl<SILBasicBlock *> &getReachingBlocks () {
243
- if (ReachingBlocks. empty () ) {
245
+ BasicBlockSet &getReachingBlocks () {
246
+ if (!reachingBlocksComputed ) {
244
247
SmallVector<SILBasicBlock *, 8 > Worklist;
245
248
ReachingBlocks.insert (Preheader);
246
249
Worklist.push_back (Preheader);
247
250
while (!Worklist.empty ()) {
248
251
SILBasicBlock *BB = Worklist.pop_back_val ();
249
252
for (auto PI = BB->pred_begin (), PE = BB->pred_end (); PI != PE; ++PI) {
250
- if (ReachingBlocks.insert (*PI). second )
253
+ if (ReachingBlocks.insert (*PI))
251
254
Worklist.push_back (*PI);
252
255
}
253
256
}
257
+ reachingBlocksComputed = true ;
254
258
}
255
259
return ReachingBlocks;
256
260
}
@@ -279,7 +283,7 @@ class ArrayPropertiesAnalysis {
279
283
280
284
// Check if this escape can reach the current loop.
281
285
if (!Loop->contains (UseInst->getParent ()) &&
282
- !getReachingBlocks ().count (UseInst->getParent ())) {
286
+ !getReachingBlocks ().contains (UseInst->getParent ())) {
283
287
continue ;
284
288
}
285
289
LLVM_DEBUG (llvm::dbgs ()
@@ -356,12 +360,10 @@ class ArrayPropertiesAnalysis {
356
360
return false ;
357
361
}
358
362
359
- SmallPtrSetImpl <SILBasicBlock *> &getLoopExitingBlocks () {
363
+ SmallVectorImpl <SILBasicBlock *> &getLoopExitingBlocks () {
360
364
if (!CachedExitingBlocks.empty ())
361
365
return CachedExitingBlocks;
362
- SmallVector<SILBasicBlock *, 16 > ExitingBlocks;
363
- Loop->getExitingBlocks (ExitingBlocks);
364
- CachedExitingBlocks.insert (ExitingBlocks.begin (), ExitingBlocks.end ());
366
+ Loop->getExitingBlocks (CachedExitingBlocks);
365
367
return CachedExitingBlocks;
366
368
}
367
369
0 commit comments