diff options
author | Devang Patel <dpatel@apple.com> | 2007-07-30 23:07:10 +0000 |
---|---|---|
committer | Devang Patel <dpatel@apple.com> | 2007-07-30 23:07:10 +0000 |
commit | 6f62af6e64716a5add36531ccd1ffdfab7391224 (patch) | |
tree | 2427090b8ce81b25dab503d31aa7a5652b170e50 /lib | |
parent | 42346f58d810204606ea5ec3d2e583b0a6da2531 (diff) | |
download | external_llvm-6f62af6e64716a5add36531ccd1ffdfab7391224.zip external_llvm-6f62af6e64716a5add36531ccd1ffdfab7391224.tar.gz external_llvm-6f62af6e64716a5add36531ccd1ffdfab7391224.tar.bz2 |
If loop can be unswitched again, then do it yourself.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@40609 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Transforms/Scalar/LoopUnswitch.cpp | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/lib/Transforms/Scalar/LoopUnswitch.cpp b/lib/Transforms/Scalar/LoopUnswitch.cpp index 4dba14d..e8762dc 100644 --- a/lib/Transforms/Scalar/LoopUnswitch.cpp +++ b/lib/Transforms/Scalar/LoopUnswitch.cpp @@ -70,12 +70,14 @@ namespace { SmallPtrSet<Value *,8> UnswitchedVals; bool OptimizeForSize; + bool redoLoop; public: static char ID; // Pass ID, replacement for typeid LoopUnswitch(bool Os = false) : - LoopPass((intptr_t)&ID), OptimizeForSize(Os) {} + LoopPass((intptr_t)&ID), OptimizeForSize(Os), redoLoop(false) {} bool runOnLoop(Loop *L, LPPassManager &LPM); + bool processLoop(Loop *L); /// This transformation requires natural loop information & requires that /// loop preheaders be inserted into the CFG... @@ -152,11 +154,23 @@ static Value *FindLIVLoopCondition(Value *Cond, Loop *L, bool &Changed) { } bool LoopUnswitch::runOnLoop(Loop *L, LPPassManager &LPM_Ref) { - assert(L->isLCSSAForm()); LI = &getAnalysis<LoopInfo>(); LPM = &LPM_Ref; bool Changed = false; - + + do { + redoLoop = false; + Changed |= processLoop(L); + } while(redoLoop); + + return Changed; +} + +/// processLoop - Do actual work and unswitch loop if possible and profitable. +bool LoopUnswitch::processLoop(Loop *L) { + assert(L->isLCSSAForm()); + bool Changed = false; + // Loop over all of the basic blocks in the loop. If we find an interior // block that is branching on a loop-invariant condition, we can unswitch this // loop. @@ -576,7 +590,7 @@ void LoopUnswitch::UnswitchTrivialCondition(Loop *L, Value *Cond, OrigPH->getTerminator()->eraseFromParent(); // We need to reprocess this loop, it could be unswitched again. - LPM->redoLoop(L); + redoLoop = true; // Now that we know that the loop is never entered when this condition is a // particular value, rewrite the loop with this info. We know that this will @@ -740,7 +754,7 @@ void LoopUnswitch::UnswitchNontrivialCondition(Value *LIC, Constant *Val, OldBR->eraseFromParent(); LoopProcessWorklist.push_back(NewLoop); - LPM->redoLoop(L); + redoLoop = true; // Now we rewrite the original code to know that the condition is true and the // new code to know that the condition is false. |