diff options
Diffstat (limited to 'contrib/llvm-project/llvm/lib/Transforms/Utils/FixIrreducible.cpp')
-rw-r--r-- | contrib/llvm-project/llvm/lib/Transforms/Utils/FixIrreducible.cpp | 32 |
1 files changed, 23 insertions, 9 deletions
diff --git a/contrib/llvm-project/llvm/lib/Transforms/Utils/FixIrreducible.cpp b/contrib/llvm-project/llvm/lib/Transforms/Utils/FixIrreducible.cpp index 460ba9e97fc6..44af95eef67d 100644 --- a/contrib/llvm-project/llvm/lib/Transforms/Utils/FixIrreducible.cpp +++ b/contrib/llvm-project/llvm/lib/Transforms/Utils/FixIrreducible.cpp @@ -66,6 +66,7 @@ // //===----------------------------------------------------------------------===// +#include "llvm/Transforms/Utils/FixIrreducible.h" #include "llvm/ADT/SCCIterator.h" #include "llvm/Analysis/LoopIterator.h" #include "llvm/InitializePasses.h" @@ -104,7 +105,7 @@ FunctionPass *llvm::createFixIrreduciblePass() { return new FixIrreducible(); } INITIALIZE_PASS_BEGIN(FixIrreducible, "fix-irreducible", "Convert irreducible control-flow into natural loops", false /* Only looks at CFG */, false /* Analysis Pass */) -INITIALIZE_PASS_DEPENDENCY(LowerSwitch) +INITIALIZE_PASS_DEPENDENCY(LowerSwitchLegacyPass) INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass) INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass) INITIALIZE_PASS_END(FixIrreducible, "fix-irreducible", @@ -304,11 +305,9 @@ static bool makeReducible(LoopInfo &LI, DominatorTree &DT, Graph &&G) { return Changed; } -bool FixIrreducible::runOnFunction(Function &F) { +static bool FixIrreducibleImpl(Function &F, LoopInfo &LI, DominatorTree &DT) { LLVM_DEBUG(dbgs() << "===== Fix irreducible control-flow in function: " << F.getName() << "\n"); - auto &LI = getAnalysis<LoopInfoWrapperPass>().getLoopInfo(); - auto &DT = getAnalysis<DominatorTreeWrapperPass>().getDomTree(); bool Changed = false; SmallVector<Loop *, 8> WorkList; @@ -318,13 +317,10 @@ bool FixIrreducible::runOnFunction(Function &F) { // Any SCCs reduced are now already in the list of top-level loops, so simply // add them all to the worklist. - for (auto L : LI) { - WorkList.push_back(L); - } + append_range(WorkList, LI); while (!WorkList.empty()) { - auto L = WorkList.back(); - WorkList.pop_back(); + auto L = WorkList.pop_back_val(); LLVM_DEBUG(dbgs() << "visiting loop with header " << L->getHeader()->getName() << "\n"); Changed |= makeReducible(LI, DT, *L); @@ -335,3 +331,21 @@ bool FixIrreducible::runOnFunction(Function &F) { return Changed; } + +bool FixIrreducible::runOnFunction(Function &F) { + auto &LI = getAnalysis<LoopInfoWrapperPass>().getLoopInfo(); + auto &DT = getAnalysis<DominatorTreeWrapperPass>().getDomTree(); + return FixIrreducibleImpl(F, LI, DT); +} + +PreservedAnalyses FixIrreduciblePass::run(Function &F, + FunctionAnalysisManager &AM) { + auto &LI = AM.getResult<LoopAnalysis>(F); + auto &DT = AM.getResult<DominatorTreeAnalysis>(F); + if (!FixIrreducibleImpl(F, LI, DT)) + return PreservedAnalyses::all(); + PreservedAnalyses PA; + PA.preserve<LoopAnalysis>(); + PA.preserve<DominatorTreeAnalysis>(); + return PA; +} |