mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-14 11:32:34 +00:00
Refactor code a bit to make it simpler and eliminate the goto
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12888 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
6491340bc1
commit
1f62f82b05
@ -469,6 +469,28 @@ static void VerifyExitBlocks(Loop *L) {
|
|||||||
VerifyExitBlocks(*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) {
|
||||||
|
for (BasicBlock::iterator I = L->getHeader()->begin();
|
||||||
|
PHINode *PN = dyn_cast<PHINode>(I); ) {
|
||||||
|
++I;
|
||||||
|
if (Value *V = hasConstantValue(PN)) {
|
||||||
|
// This is a degenerate PHI already, don't modify it!
|
||||||
|
PN->replaceAllUsesWith(V);
|
||||||
|
PN->getParent()->getInstList().erase(PN);
|
||||||
|
} else {
|
||||||
|
// Scan this PHI node looking for a use of the PHI node by itself.
|
||||||
|
for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i)
|
||||||
|
if (PN->getIncomingValue(i) == PN &&
|
||||||
|
L->contains(PN->getIncomingBlock(i)))
|
||||||
|
// We found something tasty to remove.
|
||||||
|
return PN;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/// SeparateNestedLoop - If this loop has multiple backedges, try to pull one of
|
/// SeparateNestedLoop - If this loop has multiple backedges, try to pull one of
|
||||||
/// them out into a nested loop. This is important for code that looks like
|
/// them out into a nested loop. This is important for code that looks like
|
||||||
/// this:
|
/// this:
|
||||||
@ -488,36 +510,18 @@ static void VerifyExitBlocks(Loop *L) {
|
|||||||
///
|
///
|
||||||
Loop *LoopSimplify::SeparateNestedLoop(Loop *L) {
|
Loop *LoopSimplify::SeparateNestedLoop(Loop *L) {
|
||||||
BasicBlock *Header = L->getHeader();
|
BasicBlock *Header = L->getHeader();
|
||||||
|
PHINode *PN = FindPHIToPartitionLoops(L);
|
||||||
|
if (PN == 0) return 0; // No known way to partition.
|
||||||
|
|
||||||
|
// Pull out all predecessors that have varying values in the loop. This
|
||||||
|
// handles the case when a PHI node has multiple instances of itself as
|
||||||
|
// arguments.
|
||||||
std::vector<BasicBlock*> OuterLoopPreds;
|
std::vector<BasicBlock*> OuterLoopPreds;
|
||||||
for (BasicBlock::iterator I = Header->begin();
|
for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i)
|
||||||
PHINode *PN = dyn_cast<PHINode>(I); ) {
|
if (PN->getIncomingValue(i) != PN ||
|
||||||
++I;
|
!L->contains(PN->getIncomingBlock(i)))
|
||||||
if (Value *V = hasConstantValue(PN)) {
|
OuterLoopPreds.push_back(PN->getIncomingBlock(i));
|
||||||
// This is a degenerate PHI already, don't modify it!
|
|
||||||
PN->replaceAllUsesWith(V);
|
|
||||||
Header->getInstList().erase(PN);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Scan this PHI node looking for a use of the PHI node by itself.
|
|
||||||
for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i)
|
|
||||||
if (PN->getIncomingValue(i) == PN &&
|
|
||||||
L->contains(PN->getIncomingBlock(i))) {
|
|
||||||
// Wow, we found something tasty to remove. Pull out all predecessors
|
|
||||||
// that have varying values in the loop. This handles the case when a
|
|
||||||
// PHI node has multiple instances of itself as arguments.
|
|
||||||
for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i)
|
|
||||||
if (PN->getIncomingValue(i) != PN ||
|
|
||||||
!L->contains(PN->getIncomingBlock(i)))
|
|
||||||
OuterLoopPreds.push_back(PN->getIncomingBlock(i));
|
|
||||||
goto FoundExtraction;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0; // Nothing looks appetizing to separate out
|
|
||||||
|
|
||||||
FoundExtraction:
|
|
||||||
BasicBlock *NewBB = SplitBlockPredecessors(Header, ".outer", OuterLoopPreds);
|
BasicBlock *NewBB = SplitBlockPredecessors(Header, ".outer", OuterLoopPreds);
|
||||||
|
|
||||||
// Update dominator information (set, immdom, domtree, and domfrontier)
|
// Update dominator information (set, immdom, domtree, and domfrontier)
|
||||||
|
Loading…
Reference in New Issue
Block a user