summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/Utils/LoopSimplify.cpp
diff options
context:
space:
mode:
authorNick Lewycky <nicholas@mxc.ca>2008-03-09 05:24:34 +0000
committerNick Lewycky <nicholas@mxc.ca>2008-03-09 05:24:34 +0000
commit11fc6f87651936281e22d58530a9425cc77341d4 (patch)
treeaab56c07a21cd9909d6f20f8fec4c5b0c4ded4de /llvm/lib/Transforms/Utils/LoopSimplify.cpp
parentebe5c8520c1330896f8cb018830986a25f1bdf1a (diff)
downloadbcm5719-llvm-11fc6f87651936281e22d58530a9425cc77341d4.tar.gz
bcm5719-llvm-11fc6f87651936281e22d58530a9425cc77341d4.zip
Update the block cloner which fixes bugpoint on code using unwind_to (phew!)
and also update the cloning interface's major user, the loop optimizations. llvm-svn: 48088
Diffstat (limited to 'llvm/lib/Transforms/Utils/LoopSimplify.cpp')
-rw-r--r--llvm/lib/Transforms/Utils/LoopSimplify.cpp20
1 files changed, 13 insertions, 7 deletions
diff --git a/llvm/lib/Transforms/Utils/LoopSimplify.cpp b/llvm/lib/Transforms/Utils/LoopSimplify.cpp
index e25ff90b477..16cb30ca9c2 100644
--- a/llvm/lib/Transforms/Utils/LoopSimplify.cpp
+++ b/llvm/lib/Transforms/Utils/LoopSimplify.cpp
@@ -126,18 +126,17 @@ bool LoopSimplify::runOnFunction(Function &F) {
if (LI->getLoopFor(BB)) continue;
bool BlockUnreachable = false;
- TerminatorInst *TI = BB->getTerminator();
// Check to see if any successors of this block are non-loop-header loops
// that are not the header.
- for (unsigned i = 0, e = TI->getNumSuccessors(); i != e; ++i) {
+ for (succ_iterator I = succ_begin(BB), E = succ_end(BB); I != E; ++I) {
// If this successor is not in a loop, BB is clearly ok.
- Loop *L = LI->getLoopFor(TI->getSuccessor(i));
+ Loop *L = LI->getLoopFor(*I);
if (!L) continue;
// If the succ is the loop header, and if L is a top-level loop, then this
// is an entrance into a loop through the header, which is also ok.
- if (L->getHeader() == TI->getSuccessor(i) && L->getParentLoop() == 0)
+ if (L->getHeader() == *I && L->getParentLoop() == 0)
continue;
// Otherwise, this is an entrance into a loop from some place invalid.
@@ -155,10 +154,11 @@ bool LoopSimplify::runOnFunction(Function &F) {
// loop by replacing the terminator.
// Remove PHI entries from the successors.
- for (unsigned i = 0, e = TI->getNumSuccessors(); i != e; ++i)
- TI->getSuccessor(i)->removePredecessor(BB);
+ for (succ_iterator I = succ_begin(BB), E = succ_end(BB); I != E; ++I)
+ (*I)->removePredecessor(BB);
// Add a new unreachable instruction before the old terminator.
+ TerminatorInst *TI = BB->getTerminator();
new UnreachableInst(TI);
// Delete the dead terminator.
@@ -342,6 +342,9 @@ BasicBlock *LoopSimplify::SplitBlockPredecessors(BasicBlock *BB,
for (unsigned s = 0, e = TI->getNumSuccessors(); s != e; ++s)
if (TI->getSuccessor(s) == BB)
TI->setSuccessor(s, NewBB);
+
+ if (Preds[i]->getUnwindDest() == BB)
+ Preds[i]->setUnwindDest(NewBB);
}
} else { // Otherwise the loop is dead...
@@ -681,12 +684,15 @@ void LoopSimplify::InsertUniqueBackedgeBlock(Loop *L) {
}
// Now that all of the PHI nodes have been inserted and adjusted, modify the
- // backedge blocks to just to the BEBlock instead of the header.
+ // backedge blocks to branch to the BEBlock instead of the header.
for (unsigned i = 0, e = BackedgeBlocks.size(); i != e; ++i) {
TerminatorInst *TI = BackedgeBlocks[i]->getTerminator();
for (unsigned Op = 0, e = TI->getNumSuccessors(); Op != e; ++Op)
if (TI->getSuccessor(Op) == Header)
TI->setSuccessor(Op, BEBlock);
+
+ if (BackedgeBlocks[i]->getUnwindDest() == Header)
+ BackedgeBlocks[i]->setUnwindDest(BEBlock);
}
//===--- Update all analyses which we must preserve now -----------------===//
OpenPOWER on IntegriCloud