[llvm-commits] CVS: llvm/lib/Transforms/Scalar/IndVarSimplify.cpp LoopSimplify.cpp LoopUnroll.cpp
Chris Lattner
lattner at cs.uiuc.edu
Sun Apr 18 17:14:51 PDT 2004
Changes in directory llvm/lib/Transforms/Scalar:
IndVarSimplify.cpp updated: 1.58 -> 1.59
LoopSimplify.cpp updated: 1.42 -> 1.43
LoopUnroll.cpp updated: 1.6 -> 1.7
---
Log message:
Change the ExitBlocks list from being explicitly contained in the Loop
structure to being dynamically computed on demand. This makes updating
loop information MUCH easier.
---
Diffs of the changes: (+13 -105)
Index: llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
diff -u llvm/lib/Transforms/Scalar/IndVarSimplify.cpp:1.58 llvm/lib/Transforms/Scalar/IndVarSimplify.cpp:1.59
--- llvm/lib/Transforms/Scalar/IndVarSimplify.cpp:1.58 Sat Apr 17 13:44:09 2004
+++ llvm/lib/Transforms/Scalar/IndVarSimplify.cpp Sun Apr 18 17:14:10 2004
@@ -185,8 +185,10 @@
ScalarEvolutionRewriter &RW) {
// Find the exit block for the loop. We can currently only handle loops with
// a single exit.
- if (L->getExitBlocks().size() != 1) return;
- BasicBlock *ExitBlock = L->getExitBlocks()[0];
+ std::vector<BasicBlock*> ExitBlocks;
+ L->getExitBlocks(ExitBlocks);
+ if (ExitBlocks.size() != 1) return;
+ BasicBlock *ExitBlock = ExitBlocks[0];
// Make sure there is only one predecessor block in the loop.
BasicBlock *ExitingBlock = 0;
@@ -269,8 +271,10 @@
// We insert the code into the preheader of the loop if the loop contains
// multiple exit blocks, or in the exit block if there is exactly one.
BasicBlock *BlockToInsertInto;
- if (L->getExitBlocks().size() == 1)
- BlockToInsertInto = L->getExitBlocks()[0];
+ std::vector<BasicBlock*> ExitBlocks;
+ L->getExitBlocks(ExitBlocks);
+ if (ExitBlocks.size() == 1)
+ BlockToInsertInto = ExitBlocks[0];
else
BlockToInsertInto = Preheader;
BasicBlock::iterator InsertPt = BlockToInsertInto->begin();
Index: llvm/lib/Transforms/Scalar/LoopSimplify.cpp
diff -u llvm/lib/Transforms/Scalar/LoopSimplify.cpp:1.42 llvm/lib/Transforms/Scalar/LoopSimplify.cpp:1.43
--- llvm/lib/Transforms/Scalar/LoopSimplify.cpp:1.42 Tue Apr 13 11:23:25 2004
+++ llvm/lib/Transforms/Scalar/LoopSimplify.cpp Sun Apr 18 17:14:10 2004
@@ -151,8 +151,10 @@
// predecessors that are inside of the loop. This check guarantees that the
// loop preheader/header will dominate the exit blocks. If the exit block has
// predecessors from outside of the loop, split the edge now.
- for (unsigned i = 0, e = L->getExitBlocks().size(); i != e; ++i) {
- BasicBlock *ExitBlock = L->getExitBlocks()[i];
+ std::vector<BasicBlock*> ExitBlocks;
+ L->getExitBlocks(ExitBlocks);
+ for (unsigned i = 0, e = ExitBlocks.size(); i != e; ++i) {
+ BasicBlock *ExitBlock = ExitBlocks[i];
for (pred_iterator PI = pred_begin(ExitBlock), PE = pred_end(ExitBlock);
PI != PE; ++PI)
if (!L->contains(*PI)) {
@@ -269,19 +271,6 @@
return NewBB;
}
-// ChangeExitBlock - This recursive function is used to change any exit blocks
-// that use OldExit to use NewExit instead. This is recursive because children
-// may need to be processed as well.
-//
-static void ChangeExitBlock(Loop *L, BasicBlock *OldExit, BasicBlock *NewExit) {
- if (L->hasExitBlock(OldExit)) {
- L->changeExitBlock(OldExit, NewExit);
- for (Loop::iterator I = L->begin(), E = L->end(); I != E; ++I)
- ChangeExitBlock(*I, OldExit, NewExit);
- }
-}
-
-
/// InsertPreheaderForLoop - Once we discover that a loop doesn't have a
/// preheader, this method is called to insert one. This method has two phases:
/// preheader insertion and analysis updating.
@@ -323,11 +312,6 @@
ParentLoopsE = getAnalysis<LoopInfo>().end();
}
- // Loop over all sibling loops, performing the substitution (recursively to
- // include child loops)...
- for (; ParentLoops != ParentLoopsE; ++ParentLoops)
- ChangeExitBlock(*ParentLoops, Header, NewBB);
-
DominatorSet &DS = getAnalysis<DominatorSet>(); // Update dominator info
DominatorTree &DT = getAnalysis<DominatorTree>();
@@ -405,8 +389,6 @@
/// outside of the loop.
void LoopSimplify::RewriteLoopExitBlock(Loop *L, BasicBlock *Exit) {
DominatorSet &DS = getAnalysis<DominatorSet>();
- assert(std::find(L->getExitBlocks().begin(), L->getExitBlocks().end(), Exit)
- != L->getExitBlocks().end() && "Not a current exit block!");
std::vector<BasicBlock*> LoopBlocks;
for (pred_iterator I = pred_begin(Exit), E = pred_end(Exit); I != E; ++I)
@@ -421,11 +403,6 @@
if (Loop *Parent = L->getParentLoop())
Parent->addBasicBlockToLoop(NewBB, getAnalysis<LoopInfo>());
- // Replace any instances of Exit with NewBB in this and any nested loops...
- for (df_iterator<Loop*> I = df_begin(L), E = df_end(L); I != E; ++I)
- if (I->hasExitBlock(Exit))
- I->changeExitBlock(Exit, NewBB); // Update exit block information
-
// Update dominator information (set, immdom, domtree, and domfrontier)
UpdateDomInfoForRevectoredPreds(NewBB, LoopBlocks);
}
@@ -442,33 +419,6 @@
AddBlockAndPredsToSet(*I, StopBlock, Blocks);
}
-static void ReplaceExitBlocksOfLoopAndParents(Loop *L, BasicBlock *Old,
- BasicBlock *New) {
- if (!L->hasExitBlock(Old)) return;
- L->changeExitBlock(Old, New);
- ReplaceExitBlocksOfLoopAndParents(L->getParentLoop(), Old, New);
-}
-
-/// VerifyExitBlocks - This is a function which can be useful for hacking on the
-/// LoopSimplify Code.
-static void VerifyExitBlocks(Loop *L) {
- std::vector<BasicBlock*> ExitBlocks;
- for (unsigned i = 0, e = L->getBlocks().size(); i != e; ++i) {
- BasicBlock *BB = L->getBlocks()[i];
- for (succ_iterator SI = succ_begin(BB), E = succ_end(BB); SI != E; ++SI)
- if (!L->contains(*SI))
- ExitBlocks.push_back(*SI);
- }
-
- std::vector<BasicBlock*> EB = L->getExitBlocks();
- std::sort(EB.begin(), EB.end());
- std::sort(ExitBlocks.begin(), ExitBlocks.end());
- assert(EB == ExitBlocks && "Exit blocks were incorrectly updated!");
-
- for (Loop::iterator I = L->begin(), E = L->end(); I != E; ++I)
- VerifyExitBlocks(*I);
-}
-
/// FindPHIToPartitionLoops - The first part of loop-nestification is to find a
/// PHI node that tells us how to partition the loops.
static PHINode *FindPHIToPartitionLoops(Loop *L) {
@@ -545,16 +495,6 @@
// L is now a subloop of our outer loop.
NewOuter->addChildLoop(L);
- // Add all of L's exit blocks to the outer loop.
- for (unsigned i = 0, e = L->getExitBlocks().size(); i != e; ++i)
- NewOuter->addExitBlock(L->getExitBlocks()[i]);
-
- // Add temporary exit block entries for NewBB. Add one for each edge in L
- // that goes to NewBB.
- for (pred_iterator PI = pred_begin(NewBB), E = pred_end(NewBB); PI != E; ++PI)
- if (L->contains(*PI))
- L->addExitBlock(NewBB);
-
for (unsigned i = 0, e = L->getBlocks().size(); i != e; ++i)
NewOuter->addBlockEntry(L->getBlocks()[i]);
@@ -588,16 +528,6 @@
}
}
- // Check all subloops of this loop, replacing any exit blocks that got
- // revectored with the new basic block.
- for (pred_iterator I = pred_begin(NewBB), E = pred_end(NewBB); I != E; ++I)
- if (NewOuter->contains(*I)) {
- // Change any exit blocks that used to go to Header to go to NewBB
- // instead.
- ReplaceExitBlocksOfLoopAndParents((Loop*)LI[*I], Header, NewBB);
- }
-
- //VerifyExitBlocks(NewOuter);
return NewOuter;
}
@@ -692,11 +622,6 @@
// Update Loop Information - we know that this block is now in the current
// loop and all parent loops.
L->addBasicBlockToLoop(BEBlock, getAnalysis<LoopInfo>());
-
- // Replace any instances of Exit with NewBB in this and any nested loops...
- for (df_iterator<Loop*> I = df_begin(L), E = df_end(L); I != E; ++I)
- if (I->hasExitBlock(Header))
- I->changeExitBlock(Header, BEBlock); // Update exit block information
// Update dominator information (set, immdom, domtree, and domfrontier)
UpdateDomInfoForRevectoredPreds(BEBlock, BackedgeBlocks);
Index: llvm/lib/Transforms/Scalar/LoopUnroll.cpp
diff -u llvm/lib/Transforms/Scalar/LoopUnroll.cpp:1.6 llvm/lib/Transforms/Scalar/LoopUnroll.cpp:1.7
--- llvm/lib/Transforms/Scalar/LoopUnroll.cpp:1.6 Sun Apr 18 13:06:14 2004
+++ llvm/lib/Transforms/Scalar/LoopUnroll.cpp Sun Apr 18 17:14:10 2004
@@ -109,18 +109,6 @@
}
}
-static void ChangeExitBlocksFromTo(Loop::iterator I, Loop::iterator E,
- BasicBlock *Old, BasicBlock *New) {
- for (; I != E; ++I) {
- Loop *L = *I;
- if (L->hasExitBlock(Old)) {
- L->changeExitBlock(Old, New);
- ChangeExitBlocksFromTo(L->begin(), L->end(), Old, New);
- }
- }
-}
-
-
bool LoopUnroll::visitLoop(Loop *L) {
bool Changed = false;
@@ -157,8 +145,7 @@
}
DEBUG(std::cerr << "UNROLLING!\n");
- assert(L->getExitBlocks().size() == 1 && "Must have exactly one exit block!");
- BasicBlock *LoopExit = L->getExitBlocks()[0];
+ BasicBlock *LoopExit = BI->getSuccessor(L->contains(BI->getSuccessor(0)));
// Create a new basic block to temporarily hold all of the cloned code.
BasicBlock *NewBlock = new BasicBlock();
@@ -291,14 +278,6 @@
// Remove BB and LoopExit from our analyses.
LI->removeBlock(Preheader);
LI->removeBlock(BB);
-
- // If any loops used Preheader as an exit block, update them to use LoopExit.
- if (Parent)
- ChangeExitBlocksFromTo(Parent->begin(), Parent->end(),
- Preheader, LoopExit);
- else
- ChangeExitBlocksFromTo(LI->begin(), LI->end(),
- Preheader, LoopExit);
// If the preheader was the entry block of this function, move the exit block
// to be the new entry of the loop.
More information about the llvm-commits
mailing list