mirror of
https://github.com/RPCS3/llvm.git
synced 2024-12-14 23:48:56 +00:00
Dramatically simplify building of natural loops and fix a bug where the BBMap
was not correctly computed. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@5606 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
3a9a56e7b2
commit
420df9bc78
@ -60,6 +60,7 @@ void Loop::print(std::ostream &OS) const {
|
|||||||
getSubLoops()[i]->print(OS);
|
getSubLoops()[i]->print(OS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
// LoopInfo implementation
|
// LoopInfo implementation
|
||||||
//
|
//
|
||||||
@ -101,6 +102,12 @@ void LoopInfo::getAnalysisUsage(AnalysisUsage &AU) const {
|
|||||||
void LoopInfo::print(std::ostream &OS) const {
|
void LoopInfo::print(std::ostream &OS) const {
|
||||||
for (unsigned i = 0; i < TopLevelLoops.size(); ++i)
|
for (unsigned i = 0; i < TopLevelLoops.size(); ++i)
|
||||||
TopLevelLoops[i]->print(OS);
|
TopLevelLoops[i]->print(OS);
|
||||||
|
#if 0
|
||||||
|
for (std::map<BasicBlock*, Loop*>::const_iterator I = BBMap.begin(),
|
||||||
|
E = BBMap.end(); I != E; ++I)
|
||||||
|
OS << "BB '" << I->first->getName() << "' level = "
|
||||||
|
<< I->second->LoopDepth << "\n";
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
Loop *LoopInfo::ConsiderForLoop(BasicBlock *BB, const DominatorSet &DS) {
|
Loop *LoopInfo::ConsiderForLoop(BasicBlock *BB, const DominatorSet &DS) {
|
||||||
@ -132,45 +139,24 @@ Loop *LoopInfo::ConsiderForLoop(BasicBlock *BB, const DominatorSet &DS) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add the basic blocks that comprise this loop to the BBMap so that this
|
// If there are any loops nested within this loop, create them now!
|
||||||
// loop can be found for them. Also check subsidary basic blocks to see if
|
for (std::vector<BasicBlock*>::iterator I = L->Blocks.begin(),
|
||||||
// they start subloops of their own.
|
E = L->Blocks.end(); I != E; ++I)
|
||||||
//
|
if (Loop *NewLoop = ConsiderForLoop(*I, DS)) {
|
||||||
for (std::vector<BasicBlock*>::reverse_iterator I = L->Blocks.rbegin(),
|
L->SubLoops.push_back(NewLoop);
|
||||||
E = L->Blocks.rend(); I != E; ++I)
|
NewLoop->ParentLoop = L;
|
||||||
|
}
|
||||||
|
|
||||||
// Check to see if this block starts a new loop
|
|
||||||
if (*I != BB)
|
// Add the basic blocks that comprise this loop to the BBMap so that this
|
||||||
if (Loop *NewLoop = ConsiderForLoop(*I, DS)) {
|
// loop can be found for them.
|
||||||
L->SubLoops.push_back(NewLoop);
|
//
|
||||||
NewLoop->ParentLoop = L;
|
for (std::vector<BasicBlock*>::iterator I = L->Blocks.begin(),
|
||||||
} else {
|
E = L->Blocks.end(); I != E; ++I) {
|
||||||
std::map<BasicBlock*, Loop*>::iterator BBMI = BBMap.lower_bound(*I);
|
std::map<BasicBlock*, Loop*>::iterator BBMI = BBMap.lower_bound(*I);
|
||||||
if (BBMI == BBMap.end() || BBMI->first != *I) { // Not in map yet...
|
if (BBMI == BBMap.end() || BBMI->first != *I) // Not in map yet...
|
||||||
BBMap.insert(BBMI, std::make_pair(*I, L));
|
BBMap.insert(BBMI, std::make_pair(*I, L)); // Must be at this level
|
||||||
} 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;
|
|
||||||
if (SubLoop->getHeader() == *I) { // Only do this once for the loop...
|
|
||||||
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;
|
return L;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user