Skip to content

Commit f3893f0

Browse files
authored
Merge pull request #19541 from eeckstein/fix-licm
2 parents f729903 + 87cf7ef commit f3893f0

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

lib/SILOptimizer/LoopTransforms/LICM.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,14 @@
3939

4040
using namespace swift;
4141

42+
namespace {
43+
4244
/// Instructions which can be hoisted:
4345
/// loads, function calls without side effects and (some) exclusivity checks
4446
using InstSet = llvm::SmallPtrSet<SILInstruction *, 8>;
4547

48+
using InstVector = llvm::SmallVector<SILInstruction *, 8>;
49+
4650
/// A subset of instruction which may have side effects.
4751
/// Doesn't contain ones that have special handling (e.g. fix_lifetime)
4852
using WriteSet = SmallPtrSet<SILInstruction *, 8>;
@@ -188,7 +192,6 @@ static bool hoistInstructions(SILLoop *Loop, DominanceInfo *DT,
188192
return Changed;
189193
}
190194

191-
namespace {
192195
/// \brief Summary of may writes occurring in the loop tree rooted at \p
193196
/// Loop. This includes all writes of the sub loops and the loop itself.
194197
struct LoopNestSummary {
@@ -290,7 +293,7 @@ static bool sinkInstruction(DominanceInfo *DT,
290293

291294
static bool sinkInstructions(std::unique_ptr<LoopNestSummary> &LoopSummary,
292295
DominanceInfo *DT, SILLoopInfo *LI,
293-
InstSet &SinkDownSet) {
296+
InstVector &SinkDownSet) {
294297
auto *Loop = LoopSummary->Loop;
295298
LLVM_DEBUG(llvm::errs() << " Sink instructions attempt\n");
296299
SmallVector<SILBasicBlock *, 8> domBlocks;
@@ -323,7 +326,7 @@ static void getEndAccesses(BeginAccessInst *BI,
323326

324327
static bool
325328
hoistSpecialInstruction(std::unique_ptr<LoopNestSummary> &LoopSummary,
326-
DominanceInfo *DT, SILLoopInfo *LI, InstSet &Special) {
329+
DominanceInfo *DT, SILLoopInfo *LI, InstVector &Special) {
327330
auto *Loop = LoopSummary->Loop;
328331
LLVM_DEBUG(llvm::errs() << " Hoist and Sink pairs attempt\n");
329332
auto Preheader = Loop->getLoopPreheader();
@@ -376,11 +379,11 @@ class LoopTreeOptimization {
376379
InstSet HoistUp;
377380

378381
/// Instructions that we may be able to sink down
379-
InstSet SinkDown;
382+
InstVector SinkDown;
380383

381384
/// Hoistable Instructions that need special treatment
382385
/// e.g. begin_access
383-
InstSet SpecialHoist;
386+
InstVector SpecialHoist;
384387

385388
public:
386389
LoopTreeOptimization(SILLoop *TopLevelLoop, SILLoopInfo *LI,
@@ -657,7 +660,7 @@ void LoopTreeOptimization::analyzeCurrentLoop(
657660
}
658661
case SILInstructionKind::RefElementAddrInst: {
659662
auto *REA = static_cast<RefElementAddrInst *>(&Inst);
660-
SpecialHoist.insert(REA);
663+
SpecialHoist.push_back(REA);
661664
break;
662665
}
663666
case swift::SILInstructionKind::CondFailInst: {
@@ -715,7 +718,7 @@ void LoopTreeOptimization::analyzeCurrentLoop(
715718
continue;
716719
}
717720
if (!mayWriteTo(AA, MayWrites, FL) || !mayWritesMayRelease) {
718-
SinkDown.insert(FL);
721+
SinkDown.push_back(FL);
719722
}
720723
}
721724
for (auto *BI : BeginAccesses) {
@@ -726,7 +729,7 @@ void LoopTreeOptimization::analyzeCurrentLoop(
726729
}
727730
if (analyzeBeginAccess(BI, BeginAccesses, fullApplies, MayWrites, ASA,
728731
DomTree)) {
729-
SpecialHoist.insert(BI);
732+
SpecialHoist.push_back(BI);
730733
}
731734
}
732735
}

0 commit comments

Comments
 (0)