speed up CGP a bit by scanning predecessors through phi operands

instead of with pred_begin/end.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@96078 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner
2010-02-13 04:04:42 +00:00
parent b779033a23
commit 3f65b5e733

View File

@@ -315,13 +315,12 @@ static void SplitEdgeNicely(TerminatorInst *TI, unsigned SuccNum,
BasicBlock *Dest = TI->getSuccessor(SuccNum); BasicBlock *Dest = TI->getSuccessor(SuccNum);
assert(isa<PHINode>(Dest->begin()) && assert(isa<PHINode>(Dest->begin()) &&
"This should only be called if Dest has a PHI!"); "This should only be called if Dest has a PHI!");
PHINode *DestPHI = cast<PHINode>(Dest->begin());
// Do not split edges to EH landing pads. // Do not split edges to EH landing pads.
if (InvokeInst *Invoke = dyn_cast<InvokeInst>(TI)) { if (InvokeInst *Invoke = dyn_cast<InvokeInst>(TI))
if (Invoke->getSuccessor(1) == Dest) if (Invoke->getSuccessor(1) == Dest)
return; return;
}
// As a hack, never split backedges of loops. Even though the copy for any // As a hack, never split backedges of loops. Even though the copy for any
// PHIs inserted on the backedge would be dead for exits from the loop, we // PHIs inserted on the backedge would be dead for exits from the loop, we
@@ -336,8 +335,8 @@ static void SplitEdgeNicely(TerminatorInst *TI, unsigned SuccNum,
// Check to see if Dest has any blocks that can be used as a split edge for // Check to see if Dest has any blocks that can be used as a split edge for
// this terminator. // this terminator.
for (pred_iterator PI = pred_begin(Dest), E = pred_end(Dest); PI != E; ++PI) { for (unsigned pi = 0, e = DestPHI->getNumIncomingValues(); pi != e; ++pi) {
BasicBlock *Pred = *PI; BasicBlock *Pred = DestPHI->getIncomingBlock(pi);
// To be usable, the pred has to end with an uncond branch to the dest. // To be usable, the pred has to end with an uncond branch to the dest.
BranchInst *PredBr = dyn_cast<BranchInst>(Pred->getTerminator()); BranchInst *PredBr = dyn_cast<BranchInst>(Pred->getTerminator());
if (!PredBr || !PredBr->isUnconditional()) if (!PredBr || !PredBr->isUnconditional())
@@ -346,10 +345,10 @@ static void SplitEdgeNicely(TerminatorInst *TI, unsigned SuccNum,
BasicBlock::iterator I = Pred->begin(); BasicBlock::iterator I = Pred->begin();
while (isa<DbgInfoIntrinsic>(I)) while (isa<DbgInfoIntrinsic>(I))
I++; I++;
if (dyn_cast<Instruction>(I) != PredBr) if (&*I != PredBr)
continue; continue;
// Cannot be the entry block; its label does not get emitted. // Cannot be the entry block; its label does not get emitted.
if (Pred == &(Dest->getParent()->getEntryBlock())) if (Pred == &Dest->getParent()->getEntryBlock())
continue; continue;
// Finally, since we know that Dest has phi nodes in it, we have to make // Finally, since we know that Dest has phi nodes in it, we have to make
@@ -392,13 +391,15 @@ static void SplitEdgeNicely(TerminatorInst *TI, unsigned SuccNum,
TIPHIValues.push_back(PN->getIncomingValueForBlock(TIBB)); TIPHIValues.push_back(PN->getIncomingValueForBlock(TIBB));
SmallVector<BasicBlock*, 8> IdenticalPreds; SmallVector<BasicBlock*, 8> IdenticalPreds;
for (pred_iterator PI = pred_begin(Dest), E = pred_end(Dest); PI != E; ++PI) {
BasicBlock *Pred = *PI; for (unsigned pi = 0, e = DestPHI->getNumIncomingValues(); pi != e; ++pi) {
BasicBlock *Pred = DestPHI->getIncomingBlock(pi);
if (BackEdges.count(std::make_pair(Pred, Dest))) if (BackEdges.count(std::make_pair(Pred, Dest)))
continue; continue;
if (PI == TIBB) if (Pred == TIBB) {
IdenticalPreds.push_back(Pred); IdenticalPreds.push_back(Pred);
else { continue;
}
bool Identical = true; bool Identical = true;
unsigned PHINo = 0; unsigned PHINo = 0;
for (BasicBlock::iterator I = Dest->begin(); for (BasicBlock::iterator I = Dest->begin();
@@ -410,7 +411,6 @@ static void SplitEdgeNicely(TerminatorInst *TI, unsigned SuccNum,
if (Identical) if (Identical)
IdenticalPreds.push_back(Pred); IdenticalPreds.push_back(Pred);
} }
}
assert(!IdenticalPreds.empty()); assert(!IdenticalPreds.empty());
SplitBlockPredecessors(Dest, &IdenticalPreds[0], IdenticalPreds.size(), SplitBlockPredecessors(Dest, &IdenticalPreds[0], IdenticalPreds.size(),