[llvm-commits] CVS: llvm/lib/Analysis/LoopInfo.cpp ScalarEvolution.cpp
Chris Lattner
lattner at cs.uiuc.edu
Sun Apr 18 17:14:20 PDT 2004
Changes in directory llvm/lib/Analysis:
LoopInfo.cpp updated: 1.51 -> 1.52
ScalarEvolution.cpp updated: 1.14 -> 1.15
---
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: (+20 -46)
Index: llvm/lib/Analysis/LoopInfo.cpp
diff -u llvm/lib/Analysis/LoopInfo.cpp:1.51 llvm/lib/Analysis/LoopInfo.cpp:1.52
--- llvm/lib/Analysis/LoopInfo.cpp:1.51 Sun Apr 18 01:54:48 2004
+++ llvm/lib/Analysis/LoopInfo.cpp Sun Apr 18 17:13:35 2004
@@ -63,14 +63,6 @@
if (i) OS << ",";
WriteAsOperand(OS, getBlocks()[i], false);
}
- if (!ExitBlocks.empty()) {
- OS << "\tExitBlocks: ";
- for (unsigned i = 0; i < getExitBlocks().size(); ++i) {
- if (i) OS << ",";
- WriteAsOperand(OS, getExitBlocks()[i], false);
- }
- }
-
OS << "\n";
for (iterator I = begin(), E = end(); I != E; ++I)
@@ -248,14 +240,6 @@
}
}
- // Now that we know all of the blocks that make up this loop, see if there are
- // any branches to outside of the loop... building the ExitBlocks list.
- for (std::vector<BasicBlock*>::iterator BI = L->Blocks.begin(),
- BE = L->Blocks.end(); BI != BE; ++BI)
- for (succ_iterator I = succ_begin(*BI), E = succ_end(*BI); I != E; ++I)
- if (!L->contains(*I)) // Not in current loop?
- L->ExitBlocks.push_back(*I); // It must be an exit block...
-
return L;
}
@@ -344,6 +328,18 @@
// APIs for simple analysis of the loop.
//
+/// getExitBlocks - Return all of the successor blocks of this loop. These
+/// are the blocks _outside of the current loop_ which are branched to.
+///
+void Loop::getExitBlocks(std::vector<BasicBlock*> &Blocks) const {
+ for (std::vector<BasicBlock*>::const_iterator BI = Blocks.begin(),
+ BE = Blocks.end(); BI != BE; ++BI)
+ for (succ_iterator I = succ_begin(*BI), E = succ_end(*BI); I != E; ++I)
+ if (!contains(*I)) // Not in current loop?
+ Blocks.push_back(*I); // It must be an exit block...
+}
+
+
/// getLoopPreheader - If there is a preheader for this loop, return it. A
/// loop has a preheader if there is only one edge to the header of the loop
/// from outside of the loop. If this is the case, the block branching to the
@@ -481,22 +477,6 @@
}
}
-/// changeExitBlock - This method is used to update loop information. All
-/// instances of the specified Old basic block are removed from the exit list
-/// and replaced with New.
-///
-void Loop::changeExitBlock(BasicBlock *Old, BasicBlock *New) {
- assert(Old != New && "Cannot changeExitBlock to the same thing!");
- assert(Old && New && "Cannot changeExitBlock to or from a null node!");
- assert(hasExitBlock(Old) && "Old exit block not found!");
- std::vector<BasicBlock*>::iterator
- I = std::find(ExitBlocks.begin(), ExitBlocks.end(), Old);
- while (I != ExitBlocks.end()) {
- *I = New;
- I = std::find(I+1, ExitBlocks.end(), Old);
- }
-}
-
/// replaceChildLoopWith - This is used when splitting loops up. It replaces
/// the OldChild entry in our children list with NewChild, and updates the
/// parent pointers of the two loops as appropriate.
@@ -550,15 +530,4 @@
/// does not update the mapping in the LoopInfo class.
void Loop::removeBlockFromLoop(BasicBlock *BB) {
RemoveFromVector(Blocks, BB);
-
- // If this block branched out of this loop, remove any exit blocks entries due
- // to it.
- for (succ_iterator SI = succ_begin(BB), E = succ_end(BB); SI != E; ++SI)
- if (!contains(*SI) && *SI != BB)
- RemoveFromVector(ExitBlocks, *SI);
-
- // If any blocks in this loop branch to BB, add it to the exit blocks set.
- for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI)
- if (contains(*PI))
- ExitBlocks.push_back(BB);
}
Index: llvm/lib/Analysis/ScalarEvolution.cpp
diff -u llvm/lib/Analysis/ScalarEvolution.cpp:1.14 llvm/lib/Analysis/ScalarEvolution.cpp:1.15
--- llvm/lib/Analysis/ScalarEvolution.cpp:1.14 Sat Apr 17 17:58:41 2004
+++ llvm/lib/Analysis/ScalarEvolution.cpp Sun Apr 18 17:13:35 2004
@@ -1452,11 +1452,13 @@
/// will iterate.
SCEVHandle ScalarEvolutionsImpl::ComputeIterationCount(const Loop *L) {
// If the loop has a non-one exit block count, we can't analyze it.
- if (L->getExitBlocks().size() != 1) return UnknownValue;
+ std::vector<BasicBlock*> ExitBlocks;
+ L->getExitBlocks(ExitBlocks);
+ if (ExitBlocks.size() != 1) return UnknownValue;
// Okay, there is one exit block. Try to find the condition that causes the
// loop to be exited.
- BasicBlock *ExitBlock = L->getExitBlocks()[0];
+ BasicBlock *ExitBlock = ExitBlocks[0];
BasicBlock *ExitingBlock = 0;
for (pred_iterator PI = pred_begin(ExitBlock), E = pred_end(ExitBlock);
@@ -2293,7 +2295,10 @@
PrintLoopInfo(OS, SE, *I);
std::cerr << "Loop " << L->getHeader()->getName() << ": ";
- if (L->getExitBlocks().size() != 1)
+
+ std::vector<BasicBlock*> ExitBlocks;
+ L->getExitBlocks(ExitBlocks);
+ if (ExitBlocks.size() != 1)
std::cerr << "<multiple exits> ";
if (SE->hasLoopInvariantIterationCount(L)) {
More information about the llvm-commits
mailing list