aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Transforms/Utils
diff options
context:
space:
mode:
authorDan Gohman <gohman@apple.com>2009-11-09 18:28:24 +0000
committerDan Gohman <gohman@apple.com>2009-11-09 18:28:24 +0000
commit2fb4ae554502621f3d5b3945f650e6b5ee66ffc7 (patch)
tree58ab51b1ba4d7d87bc54ad867dd93f6fd1c93ddf /lib/Transforms/Utils
parentaf255824880d1a779f31df72f5a52e1419f773f7 (diff)
downloadexternal_llvm-2fb4ae554502621f3d5b3945f650e6b5ee66ffc7.zip
external_llvm-2fb4ae554502621f3d5b3945f650e6b5ee66ffc7.tar.gz
external_llvm-2fb4ae554502621f3d5b3945f650e6b5ee66ffc7.tar.bz2
Generalize LCSSA to handle loops with exits with predecessors outside
the loop. This is needed because with indirectbr it may not be possible for LoopSimplify to guarantee that all loop exit predecessors are inside the loop. This fixes PR5437. LCCSA no longer actually requires LoopSimplify form, but for now it must still have the dependency because the PassManager doesn't know how to schedule LoopSimplify otherwise. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@86569 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Utils')
-rw-r--r--lib/Transforms/Utils/LCSSA.cpp16
1 files changed, 14 insertions, 2 deletions
diff --git a/lib/Transforms/Utils/LCSSA.cpp b/lib/Transforms/Utils/LCSSA.cpp
index a8813eb..b4afeda 100644
--- a/lib/Transforms/Utils/LCSSA.cpp
+++ b/lib/Transforms/Utils/LCSSA.cpp
@@ -63,6 +63,9 @@ namespace {
///
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
AU.setPreservesCFG();
+
+ // LCSSA doesn't actually require LoopSimplify, but the PassManager
+ // doesn't know how to schedule LoopSimplify by itself.
AU.addRequiredID(LoopSimplifyID);
AU.addPreservedID(LoopSimplifyID);
AU.addRequiredTransitive<LoopInfo>();
@@ -214,7 +217,7 @@ bool LCSSA::ProcessInstruction(Instruction *Inst,
SSAUpdate.Initialize(Inst);
// Insert the LCSSA phi's into all of the exit blocks dominated by the
- // value., and add them to the Phi's map.
+ // value, and add them to the Phi's map.
for (SmallVectorImpl<BasicBlock*>::const_iterator BBI = ExitBlocks.begin(),
BBE = ExitBlocks.end(); BBI != BBE; ++BBI) {
BasicBlock *ExitBB = *BBI;
@@ -228,8 +231,17 @@ bool LCSSA::ProcessInstruction(Instruction *Inst,
PN->reserveOperandSpace(PredCache.GetNumPreds(ExitBB));
// Add inputs from inside the loop for this PHI.
- for (BasicBlock **PI = PredCache.GetPreds(ExitBB); *PI; ++PI)
+ for (BasicBlock **PI = PredCache.GetPreds(ExitBB); *PI; ++PI) {
PN->addIncoming(Inst, *PI);
+
+ // If the exit block has a predecessor not within the loop, arrange for
+ // the incomging value use corresponding to that predecessor to be
+ // rewritten in terms of a different LCSSA PHI.
+ if (!inLoop(*PI))
+ UsesToRewrite.push_back(
+ &PN->getOperandUse(
+ PN->getOperandNumForIncomingValue(PN->getNumIncomingValues()-1)));
+ }
// Remember that this phi makes the value alive in this block.
SSAUpdate.AddAvailableValue(ExitBB, PN);