[llvm-commits] CVS: llvm/lib/Analysis/LoopInfo.cpp
Chris Lattner
lattner at cs.uiuc.edu
Wed Feb 19 18:18:00 PST 2003
Changes in directory llvm/lib/Analysis:
LoopInfo.cpp updated: 1.26 -> 1.27
---
Log message:
Fix bug: 2003-02-19-LoopInfoNestingBug.ll
---
Diffs of the changes:
Index: llvm/lib/Analysis/LoopInfo.cpp
diff -u llvm/lib/Analysis/LoopInfo.cpp:1.26 llvm/lib/Analysis/LoopInfo.cpp:1.27
--- llvm/lib/Analysis/LoopInfo.cpp:1.26 Fri Oct 11 00:30:13 2002
+++ llvm/lib/Analysis/LoopInfo.cpp Wed Feb 19 18:17:17 2003
@@ -37,13 +37,12 @@
unsigned numBackEdges = 0;
BasicBlock *header = Blocks.front();
- for (std::vector<BasicBlock*>::const_iterator i = Blocks.begin(), e = Blocks.end();
- i != e; ++i) {
- for (BasicBlock::succ_iterator Successor = succ_begin(*i), SEnd = succ_end(*i);
- Successor != SEnd; ++Successor) {
- if (header == *Successor)
+ for (std::vector<BasicBlock*>::const_iterator I = Blocks.begin(),
+ E = Blocks.end(); I != E; ++I) {
+ for (BasicBlock::succ_iterator SI = succ_begin(*I), SE = succ_end(*I);
+ SI != SE; ++SI)
+ if (header == *SI)
++numBackEdges;
- }
}
return numBackEdges;
}
@@ -138,17 +137,38 @@
// they start subloops of their own.
//
for (std::vector<BasicBlock*>::reverse_iterator I = L->Blocks.rbegin(),
- E = L->Blocks.rend(); I != E; ++I) {
+ E = L->Blocks.rend(); I != E; ++I)
// Check to see if this block starts a new loop
- if (Loop *NewLoop = ConsiderForLoop(*I, DS)) {
- L->SubLoops.push_back(NewLoop);
- NewLoop->ParentLoop = L;
- }
-
- if (BBMap.find(*I) == BBMap.end())
- BBMap.insert(std::make_pair(*I, L));
- }
+ if (*I != BB)
+ if (Loop *NewLoop = ConsiderForLoop(*I, DS)) {
+ L->SubLoops.push_back(NewLoop);
+ NewLoop->ParentLoop = L;
+ } else {
+ std::map<BasicBlock*, Loop*>::iterator BBMI = BBMap.lower_bound(*I);
+ if (BBMI == BBMap.end() || BBMI->first != *I) { // Not in map yet...
+ BBMap.insert(BBMI, std::make_pair(*I, L));
+ } else {
+ // If this is already in the BBMap then this means that we already added
+ // a loop for it, but incorrectly added the loop to a higher level loop
+ // instead of the current loop we are creating. Fix this now by moving
+ // the loop into the correct subloop.
+ //
+ Loop *SubLoop = BBMI->second;
+ Loop *OldSubLoopParent = SubLoop->getParentLoop();
+ if (OldSubLoopParent != L) {
+ // Remove SubLoop from OldSubLoopParent's list of subloops...
+ std::vector<Loop*>::iterator I =
+ std::find(OldSubLoopParent->SubLoops.begin(),
+ OldSubLoopParent->SubLoops.end(), SubLoop);
+ assert(I != OldSubLoopParent->SubLoops.end()
+ && "Loop parent doesn't contain loop?");
+ OldSubLoopParent->SubLoops.erase(I);
+ SubLoop->ParentLoop = L;
+ L->SubLoops.push_back(SubLoop);
+ }
+ }
+ }
return L;
}
More information about the llvm-commits
mailing list