53
53
#define DEBUG_TYPE " array-property-opt"
54
54
55
55
#include " ArrayOpt.h"
56
- #include " swift/SILOptimizer/Analysis/ArraySemantic.h"
57
- #include " swift/SILOptimizer/Analysis/LoopAnalysis.h"
58
- #include " swift/SILOptimizer/PassManager/Transforms.h"
59
- #include " swift/SILOptimizer/Utils/CFGOptUtils.h"
60
- #include " swift/SILOptimizer/Utils/SILSSAUpdater.h"
56
+ #include " swift/SIL/BasicBlockBits.h"
61
57
#include " swift/SIL/CFG.h"
62
58
#include " swift/SIL/DebugUtils.h"
63
59
#include " swift/SIL/InstructionUtils.h"
64
- #include " swift/SIL/Projection.h"
65
60
#include " swift/SIL/LoopInfo.h"
66
- #include " swift/SIL/BasicBlockBits .h"
61
+ #include " swift/SIL/Projection .h"
67
62
#include " swift/SIL/SILCloner.h"
63
+ #include " swift/SILOptimizer/Analysis/ArraySemantic.h"
64
+ #include " swift/SILOptimizer/Analysis/LoopAnalysis.h"
65
+ #include " swift/SILOptimizer/PassManager/Transforms.h"
66
+ #include " swift/SILOptimizer/Utils/BasicBlockOptUtils.h"
67
+ #include " swift/SILOptimizer/Utils/CFGOptUtils.h"
68
+ #include " swift/SILOptimizer/Utils/SILSSAUpdater.h"
68
69
#include " llvm/ADT/SmallSet.h"
69
70
#include " llvm/Support/CommandLine.h"
70
71
#include " llvm/Support/Debug.h"
@@ -85,6 +86,8 @@ class ArrayPropertiesAnalysis {
85
86
SILBasicBlock *Preheader;
86
87
DominanceInfo *DomTree;
87
88
89
+ SinkAddressProjections sinkProj;
90
+
88
91
llvm::DenseMap<SILFunction *, uint32_t > InstCountCache;
89
92
llvm::SmallSet<SILValue, 16 > HoistableArray;
90
93
@@ -168,13 +171,18 @@ class ArrayPropertiesAnalysis {
168
171
169
172
bool FoundHoistable = false ;
170
173
uint32_t LoopInstCount = 0 ;
174
+
171
175
for (auto *BB : Loop->getBlocks ()) {
172
176
for (auto &Inst : *BB) {
173
177
// Can't clone alloc_stack instructions whose dealloc_stack is outside
174
178
// the loop.
175
179
if (!Loop->canDuplicate (&Inst))
176
180
return false ;
177
181
182
+ if (!sinkProj.analyzeAddressProjections (&Inst)) {
183
+ return false ;
184
+ }
185
+
178
186
ArraySemanticsCall ArrayPropsInst (&Inst, " array.props" , true );
179
187
if (!ArrayPropsInst)
180
188
continue ;
@@ -536,10 +544,15 @@ class RegionCloner : public SILCloner<RegionCloner> {
536
544
for (auto *arg : origBB->getArguments ())
537
545
updateSSAForValue (origBB, arg, SSAUp);
538
546
547
+ SinkAddressProjections sinkProj;
539
548
// Update outside used instruction values.
540
549
for (auto &inst : *origBB) {
541
- for (auto result : inst.getResults ())
550
+ for (auto result : inst.getResults ()) {
551
+ bool success = sinkProj.analyzeAddressProjections (&inst);
552
+ assert (success);
553
+ sinkProj.cloneProjections ();
542
554
updateSSAForValue (origBB, result, SSAUp);
555
+ }
543
556
}
544
557
}
545
558
}
0 commit comments