Switch loopinfo to using ETForest instead of DominatorSet to compute itself.

Patch by Daniel Berlin!


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25199 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner
2006-01-11 05:08:29 +00:00
parent bf0945877e
commit 45a0e9b04d

View File

@@ -90,7 +90,7 @@ void LoopInfo::stub() {}
bool LoopInfo::runOnFunction(Function &) { bool LoopInfo::runOnFunction(Function &) {
releaseMemory(); releaseMemory();
Calculate(getAnalysis<DominatorSet>()); // Update Calculate(getAnalysis<ETForest>()); // Update
return false; return false;
} }
@@ -104,18 +104,18 @@ void LoopInfo::releaseMemory() {
} }
void LoopInfo::Calculate(const DominatorSet &DS) { void LoopInfo::Calculate(const ETForest &EF) {
BasicBlock *RootNode = DS.getRoot(); BasicBlock *RootNode = EF.getRoot();
for (df_iterator<BasicBlock*> NI = df_begin(RootNode), for (df_iterator<BasicBlock*> NI = df_begin(RootNode),
NE = df_end(RootNode); NI != NE; ++NI) NE = df_end(RootNode); NI != NE; ++NI)
if (Loop *L = ConsiderForLoop(*NI, DS)) if (Loop *L = ConsiderForLoop(*NI, EF))
TopLevelLoops.push_back(L); TopLevelLoops.push_back(L);
} }
void LoopInfo::getAnalysisUsage(AnalysisUsage &AU) const { void LoopInfo::getAnalysisUsage(AnalysisUsage &AU) const {
AU.setPreservesAll(); AU.setPreservesAll();
AU.addRequired<DominatorSet>(); AU.addRequired<ETForest>();
} }
void LoopInfo::print(std::ostream &OS, const Module* ) const { void LoopInfo::print(std::ostream &OS, const Module* ) const {
@@ -135,7 +135,7 @@ static bool isNotAlreadyContainedIn(Loop *SubLoop, Loop *ParentLoop) {
return isNotAlreadyContainedIn(SubLoop->getParentLoop(), ParentLoop); return isNotAlreadyContainedIn(SubLoop->getParentLoop(), ParentLoop);
} }
Loop *LoopInfo::ConsiderForLoop(BasicBlock *BB, const DominatorSet &DS) { Loop *LoopInfo::ConsiderForLoop(BasicBlock *BB, const ETForest &EF) {
if (BBMap.find(BB) != BBMap.end()) return 0; // Haven't processed this node? if (BBMap.find(BB) != BBMap.end()) return 0; // Haven't processed this node?
std::vector<BasicBlock *> TodoStack; std::vector<BasicBlock *> TodoStack;
@@ -143,7 +143,7 @@ Loop *LoopInfo::ConsiderForLoop(BasicBlock *BB, const DominatorSet &DS) {
// Scan the predecessors of BB, checking to see if BB dominates any of // Scan the predecessors of BB, checking to see if BB dominates any of
// them. This identifies backedges which target this node... // them. This identifies backedges which target this node...
for (pred_iterator I = pred_begin(BB), E = pred_end(BB); I != E; ++I) for (pred_iterator I = pred_begin(BB), E = pred_end(BB); I != E; ++I)
if (DS.dominates(BB, *I)) // If BB dominates it's predecessor... if (EF.dominates(BB, *I)) // If BB dominates it's predecessor...
TodoStack.push_back(*I); TodoStack.push_back(*I);
if (TodoStack.empty()) return 0; // No backedges to this block... if (TodoStack.empty()) return 0; // No backedges to this block...
@@ -159,7 +159,7 @@ Loop *LoopInfo::ConsiderForLoop(BasicBlock *BB, const DominatorSet &DS) {
TodoStack.pop_back(); TodoStack.pop_back();
if (!L->contains(X) && // As of yet unprocessed?? if (!L->contains(X) && // As of yet unprocessed??
DS.dominates(EntryBlock, X)) { // X is reachable from entry block? EF.dominates(EntryBlock, X)) { // X is reachable from entry block?
// Check to see if this block already belongs to a loop. If this occurs // Check to see if this block already belongs to a loop. If this occurs
// then we have a case where a loop that is supposed to be a child of the // then we have a case where a loop that is supposed to be a child of the
// current loop was processed before the current loop. When this occurs, // current loop was processed before the current loop. When this occurs,
@@ -191,7 +191,7 @@ Loop *LoopInfo::ConsiderForLoop(BasicBlock *BB, const DominatorSet &DS) {
// If there are any loops nested within this loop, create them now! // If there are any loops nested within this loop, create them now!
for (std::vector<BasicBlock*>::iterator I = L->Blocks.begin(), for (std::vector<BasicBlock*>::iterator I = L->Blocks.begin(),
E = L->Blocks.end(); I != E; ++I) E = L->Blocks.end(); I != E; ++I)
if (Loop *NewLoop = ConsiderForLoop(*I, DS)) { if (Loop *NewLoop = ConsiderForLoop(*I, EF)) {
L->SubLoops.push_back(NewLoop); L->SubLoops.push_back(NewLoop);
NewLoop->ParentLoop = L; NewLoop->ParentLoop = L;
} }