[llvm-commits] CVS: llvm/lib/Transforms/Utils/LoopSimplify.cpp
Chris Lattner
lattner at cs.uiuc.edu
Tue Feb 14 14:34:20 PST 2006
Changes in directory llvm/lib/Transforms/Utils:
LoopSimplify.cpp updated: 1.67 -> 1.68
---
Log message:
When splitting exit edges to canonicalize loops, make sure to put the new
block in the appropriate loop nest.
Third time is the charm, right?
---
Diffs of the changes: (+20 -18)
LoopSimplify.cpp | 38 ++++++++++++++++++++------------------
1 files changed, 20 insertions(+), 18 deletions(-)
Index: llvm/lib/Transforms/Utils/LoopSimplify.cpp
diff -u llvm/lib/Transforms/Utils/LoopSimplify.cpp:1.67 llvm/lib/Transforms/Utils/LoopSimplify.cpp:1.68
--- llvm/lib/Transforms/Utils/LoopSimplify.cpp:1.67 Sat Feb 11 19:59:10 2006
+++ llvm/lib/Transforms/Utils/LoopSimplify.cpp Tue Feb 14 16:34:08 2006
@@ -57,6 +57,7 @@
// AA - If we have an alias analysis object to update, this is it, otherwise
// this is null.
AliasAnalysis *AA;
+ LoopInfo *LI;
virtual bool runOnFunction(Function &F);
@@ -100,10 +101,10 @@
///
bool LoopSimplify::runOnFunction(Function &F) {
bool Changed = false;
- LoopInfo &LI = getAnalysis<LoopInfo>();
+ LI = &getAnalysis<LoopInfo>();
AA = getAnalysisToUpdate<AliasAnalysis>();
- for (LoopInfo::iterator I = LI.begin(), E = LI.end(); I != E; ++I)
+ for (LoopInfo::iterator I = LI->begin(), E = LI->end(); I != E; ++I)
Changed |= ProcessLoop(*I);
return Changed;
@@ -159,9 +160,8 @@
// predecessors from outside of the loop, split the edge now.
std::vector<BasicBlock*> ExitBlocks;
L->getExitBlocks(ExitBlocks);
-
+
SetVector<BasicBlock*> ExitBlockSet(ExitBlocks.begin(), ExitBlocks.end());
- LoopInfo &LI = getAnalysis<LoopInfo>();
for (SetVector<BasicBlock*>::iterator I = ExitBlockSet.begin(),
E = ExitBlockSet.end(); I != E; ++I) {
BasicBlock *ExitBlock = *I;
@@ -326,7 +326,7 @@
// We know that we have loop information to update... update it now.
if (Loop *Parent = L->getParentLoop())
- Parent->addBasicBlockToLoop(NewBB, getAnalysis<LoopInfo>());
+ Parent->addBasicBlockToLoop(NewBB, *LI);
DominatorSet &DS = getAnalysis<DominatorSet>(); // Update dominator info
DominatorTree &DT = getAnalysis<DominatorTree>();
@@ -414,8 +414,6 @@
/// blocks. This method is used to split exit blocks that have predecessors
/// outside of the loop.
BasicBlock *LoopSimplify::RewriteLoopExitBlock(Loop *L, BasicBlock *Exit) {
- DominatorSet &DS = getAnalysis<DominatorSet>();
-
std::vector<BasicBlock*> LoopBlocks;
for (pred_iterator I = pred_begin(Exit), E = pred_end(Exit); I != E; ++I)
if (L->contains(*I))
@@ -424,10 +422,16 @@
assert(!LoopBlocks.empty() && "No edges coming in from outside the loop?");
BasicBlock *NewBB = SplitBlockPredecessors(Exit, ".loopexit", LoopBlocks);
- // Update Loop Information - we know that the new block will be in the parent
- // loop of L.
- if (Loop *Parent = L->getParentLoop())
- Parent->addBasicBlockToLoop(NewBB, getAnalysis<LoopInfo>());
+ // Update Loop Information - we know that the new block will be in whichever
+ // loop the Exit block is in. Note that it may not be in that immediate loop,
+ // if the successor is some other loop header. In that case, we continue
+ // walking up the loop tree to find a loop that contains both the successor
+ // block and the predecessor block.
+ Loop *SuccLoop = LI->getLoopFor(Exit);
+ while (SuccLoop && !SuccLoop->contains(L->getHeader()))
+ SuccLoop = SuccLoop->getParentLoop();
+ if (SuccLoop)
+ SuccLoop->addBasicBlockToLoop(NewBB, *LI);
// Update dominator information (set, immdom, domtree, and domfrontier)
UpdateDomInfoForRevectoredPreds(NewBB, LoopBlocks);
@@ -511,17 +515,15 @@
// Create the new outer loop.
Loop *NewOuter = new Loop();
- LoopInfo &LI = getAnalysis<LoopInfo>();
-
// Change the parent loop to use the outer loop as its child now.
if (Loop *Parent = L->getParentLoop())
Parent->replaceChildLoopWith(L, NewOuter);
else
- LI.changeTopLevelLoop(L, NewOuter);
+ LI->changeTopLevelLoop(L, NewOuter);
// This block is going to be our new header block: add it to this loop and all
// parent loops.
- NewOuter->addBasicBlockToLoop(NewBB, getAnalysis<LoopInfo>());
+ NewOuter->addBasicBlockToLoop(NewBB, *LI);
// L is now a subloop of our outer loop.
NewOuter->addChildLoop(L);
@@ -553,8 +555,8 @@
if (!BlocksInL.count(BB)) {
// Move this block to the parent, updating the exit blocks sets
L->removeBlockFromLoop(BB);
- if (LI[BB] == L)
- LI.changeLoopFor(BB, NewOuter);
+ if ((*LI)[BB] == L)
+ LI->changeLoopFor(BB, NewOuter);
--i;
}
}
@@ -656,7 +658,7 @@
// Update Loop Information - we know that this block is now in the current
// loop and all parent loops.
- L->addBasicBlockToLoop(BEBlock, getAnalysis<LoopInfo>());
+ L->addBasicBlockToLoop(BEBlock, *LI);
// Update dominator information (set, immdom, domtree, and domfrontier)
UpdateDomInfoForRevectoredPreds(BEBlock, BackedgeBlocks);
More information about the llvm-commits
mailing list