[llvm] r354314 - [NFC] API for signaling that the current loop is being deleted
Max Kazantsev via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 19 03:14:05 PST 2019
Author: mkazantsev
Date: Tue Feb 19 03:14:05 2019
New Revision: 354314
URL: http://llvm.org/viewvc/llvm-project?rev=354314&view=rev
Log:
[NFC] API for signaling that the current loop is being deleted
We are planning to be able to delete the current loop in LoopSimplifyCFG
in the future. Add API to notify the loop pass manager that it happened.
Modified:
llvm/trunk/lib/Transforms/Scalar/LoopSimplifyCFG.cpp
Modified: llvm/trunk/lib/Transforms/Scalar/LoopSimplifyCFG.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/LoopSimplifyCFG.cpp?rev=354314&r1=354313&r2=354314&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/LoopSimplifyCFG.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/LoopSimplifyCFG.cpp Tue Feb 19 03:14:05 2019
@@ -596,6 +596,10 @@ public:
return true;
}
+
+ bool foldingBreaksCurrentLoop() const {
+ return DeleteCurrentLoop;
+ }
};
} // namespace
@@ -603,7 +607,8 @@ public:
/// branches.
static bool constantFoldTerminators(Loop &L, DominatorTree &DT, LoopInfo &LI,
ScalarEvolution &SE,
- MemorySSAUpdater *MSSAU) {
+ MemorySSAUpdater *MSSAU,
+ bool &IsLoopDeleted) {
if (!EnableTermFolding)
return false;
@@ -613,7 +618,9 @@ static bool constantFoldTerminators(Loop
return false;
ConstantTerminatorFoldingImpl BranchFolder(L, LI, DT, SE, MSSAU);
- return BranchFolder.run();
+ bool Changed = BranchFolder.run();
+ IsLoopDeleted = Changed && BranchFolder.foldingBreaksCurrentLoop();
+ return Changed;
}
static bool mergeBlocksIntoPredecessors(Loop &L, DominatorTree &DT,
@@ -645,11 +652,15 @@ static bool mergeBlocksIntoPredecessors(
}
static bool simplifyLoopCFG(Loop &L, DominatorTree &DT, LoopInfo &LI,
- ScalarEvolution &SE, MemorySSAUpdater *MSSAU) {
+ ScalarEvolution &SE, MemorySSAUpdater *MSSAU,
+ bool &isLoopDeleted) {
bool Changed = false;
// Constant-fold terminators with known constant conditions.
- Changed |= constantFoldTerminators(L, DT, LI, SE, MSSAU);
+ Changed |= constantFoldTerminators(L, DT, LI, SE, MSSAU, isLoopDeleted);
+
+ if (isLoopDeleted)
+ return true;
// Eliminate unconditional branches by merging blocks into their predecessors.
Changed |= mergeBlocksIntoPredecessors(L, DT, LI, MSSAU);
@@ -662,14 +673,19 @@ static bool simplifyLoopCFG(Loop &L, Dom
PreservedAnalyses LoopSimplifyCFGPass::run(Loop &L, LoopAnalysisManager &AM,
LoopStandardAnalysisResults &AR,
- LPMUpdater &) {
+ LPMUpdater &LPMU) {
Optional<MemorySSAUpdater> MSSAU;
if (EnableMSSALoopDependency && AR.MSSA)
MSSAU = MemorySSAUpdater(AR.MSSA);
+ bool DeleteCurrentLoop = false;
if (!simplifyLoopCFG(L, AR.DT, AR.LI, AR.SE,
- MSSAU.hasValue() ? MSSAU.getPointer() : nullptr))
+ MSSAU.hasValue() ? MSSAU.getPointer() : nullptr,
+ DeleteCurrentLoop))
return PreservedAnalyses::all();
+ if (DeleteCurrentLoop)
+ LPMU.markLoopAsDeleted(L, "loop-simplifycfg");
+
return getLoopPassPreservedAnalyses();
}
@@ -681,7 +697,7 @@ public:
initializeLoopSimplifyCFGLegacyPassPass(*PassRegistry::getPassRegistry());
}
- bool runOnLoop(Loop *L, LPPassManager &) override {
+ bool runOnLoop(Loop *L, LPPassManager &LPM) override {
if (skipLoop(L))
return false;
@@ -695,8 +711,13 @@ public:
if (VerifyMemorySSA)
MSSA->verifyMemorySSA();
}
- return simplifyLoopCFG(*L, DT, LI, SE,
- MSSAU.hasValue() ? MSSAU.getPointer() : nullptr);
+ bool DeleteCurrentLoop = false;
+ bool Changed = simplifyLoopCFG(
+ *L, DT, LI, SE, MSSAU.hasValue() ? MSSAU.getPointer() : nullptr,
+ DeleteCurrentLoop);
+ if (DeleteCurrentLoop)
+ LPM.markLoopAsDeleted(*L);
+ return Changed;
}
void getAnalysisUsage(AnalysisUsage &AU) const override {
More information about the llvm-commits
mailing list