Skip to content

Commit b47afec

Browse files
committed
RedundantLoadElimination: support bisecting individual optimized loads when debugging this pass.
1 parent 6a4f37b commit b47afec

File tree

1 file changed

+26
-11
lines changed

1 file changed

+26
-11
lines changed

lib/SILOptimizer/Transforms/RedundantLoadElimination.cpp

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -431,8 +431,7 @@ class RLEContext {
431431
/// Function currently processing.
432432
SILFunction *Fn;
433433

434-
/// The passmanager we are using.
435-
SILPassManager *PM;
434+
SILFunctionTransform *parentTransform;
436435

437436
/// The alias analysis that we will use during all computations.
438437
AliasAnalysis *AA;
@@ -500,7 +499,7 @@ class RLEContext {
500499
#endif
501500

502501
public:
503-
RLEContext(SILFunction *F, SILPassManager *PM,
502+
RLEContext(SILFunction *F, SILFunctionTransform *parentTransform,
504503
bool disableArrayLoads, bool onlyImmutableLoads);
505504

506505
RLEContext(const RLEContext &) = delete;
@@ -1149,7 +1148,8 @@ getProcessFunctionKind(unsigned LoadCount, unsigned StoreCount) {
11491148
// the basic blocks in the functions are iterated in post order.
11501149
// Then this function can be processed in one iteration, i.e. no
11511150
// need to generate the genset and killset.
1152-
auto *PO = PM->getAnalysis<PostOrderAnalysis>()->get(Fn);
1151+
auto *PO = parentTransform->getPassManager()->
1152+
getAnalysis<PostOrderAnalysis>()->get(Fn);
11531153
BasicBlockSet HandledBBs(Fn);
11541154
for (SILBasicBlock *B : PO->getReversePostOrder()) {
11551155
++BBCount;
@@ -1215,12 +1215,13 @@ void BlockState::dump(RLEContext &Ctx) {
12151215
// RLEContext Implementation
12161216
//===----------------------------------------------------------------------===//
12171217

1218-
RLEContext::RLEContext(SILFunction *F, SILPassManager *PM,
1218+
RLEContext::RLEContext(SILFunction *F, SILFunctionTransform *parentTransform,
12191219
bool disableArrayLoads, bool onlyImmutableLoads)
1220-
: Fn(F), PM(PM), AA(PM->getAnalysis<AliasAnalysis>(F)),
1221-
TE(PM->getAnalysis<TypeExpansionAnalysis>()),
1222-
PO(PM->getAnalysis<PostOrderAnalysis>()->get(F)),
1223-
EAFI(PM->getAnalysis<EpilogueARCAnalysis>()->get(F)),
1220+
: Fn(F), parentTransform(parentTransform),
1221+
AA(parentTransform->getPassManager()->getAnalysis<AliasAnalysis>(F)),
1222+
TE(parentTransform->getPassManager()->getAnalysis<TypeExpansionAnalysis>()),
1223+
PO(parentTransform->getPassManager()->getAnalysis<PostOrderAnalysis>()->get(F)),
1224+
EAFI(parentTransform->getPassManager()->getAnalysis<EpilogueARCAnalysis>()->get(F)),
12241225
BBToLocState(F), BBWithLoads(F),
12251226
ArrayType(disableArrayLoads
12261227
? F->getModule().getASTContext().getArrayDecl()
@@ -1628,6 +1629,9 @@ bool RLEContext::run() {
16281629
// Set up the load forwarding.
16291630
processBasicBlocksForRLE(Optimistic);
16301631

1632+
if (!parentTransform->continueWithNextSubpassRun(nullptr))
1633+
return false;
1634+
16311635
// Finally, perform the redundant load replacements.
16321636
llvm::SmallVector<SILInstruction *, 16> InstsToDelete;
16331637
bool SILChanged = false;
@@ -1648,6 +1652,10 @@ bool RLEContext::run() {
16481652
auto Iter = Loads.find(V);
16491653
if (Iter == Loads.end())
16501654
continue;
1655+
1656+
if (!parentTransform->continueWithNextSubpassRun(V))
1657+
return SILChanged;
1658+
16511659
LLVM_DEBUG(llvm::dbgs() << "Replacing " << SILValue(Iter->first)
16521660
<< "With " << Iter->second);
16531661
auto *origLoad = cast<LoadInst>(Iter->first);
@@ -1666,6 +1674,10 @@ bool RLEContext::run() {
16661674
// Erase the instructions recursively, this way, we get rid of pass
16671675
// dependence on DCE.
16681676
for (auto &X : InstsToDelete) {
1677+
1678+
if (!parentTransform->continueWithNextSubpassRun(X))
1679+
return SILChanged;
1680+
16691681
// It is possible that the instruction still has uses, because it could be
16701682
// used as the replacement Value, i.e. F.second, for some other RLE pairs.
16711683
//
@@ -1700,16 +1712,19 @@ class RedundantLoadElimination : public SILFunctionTransform {
17001712
LLVM_DEBUG(llvm::dbgs() << "*** RLE on function: " << F->getName()
17011713
<< " ***\n");
17021714

1703-
RLEContext RLE(F, PM, disableArrayLoads,
1715+
RLEContext RLE(F, this, disableArrayLoads,
17041716
/*onlyImmutableLoads*/ false);
17051717
if (RLE.run()) {
17061718
invalidateAnalysis(SILAnalysis::InvalidationKind::Instructions);
17071719
}
1720+
if (!continueWithNextSubpassRun(nullptr))
1721+
return;
1722+
17081723
if (RLE.shouldOptimizeImmutableLoads()) {
17091724
/// Re-running RLE with cutting base addresses off at
17101725
/// `ref_element_addr [immutable]` or `ref_tail_addr [immutable]` can
17111726
/// expose additional opportunities.
1712-
RLEContext RLE2(F, PM, disableArrayLoads,
1727+
RLEContext RLE2(F, this, disableArrayLoads,
17131728
/*onlyImmutableLoads*/ true);
17141729
if (RLE2.run()) {
17151730
invalidateAnalysis(SILAnalysis::InvalidationKind::Instructions);

0 commit comments

Comments
 (0)