mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-01-16 16:48:02 +00:00
Speed up codegen prepare from 3.58s to 0.488s.
llvm-svn: 96081
This commit is contained in:
parent
975da20868
commit
9c797fdf1d
@ -192,22 +192,46 @@ BasicBlock *llvm::SplitCriticalEdge(TerminatorInst *TI, unsigned SuccNum,
|
|||||||
|
|
||||||
// If there are any PHI nodes in DestBB, we need to update them so that they
|
// If there are any PHI nodes in DestBB, we need to update them so that they
|
||||||
// merge incoming values from NewBB instead of from TIBB.
|
// merge incoming values from NewBB instead of from TIBB.
|
||||||
//
|
if (PHINode *APHI = dyn_cast<PHINode>(DestBB->begin())) {
|
||||||
|
// This conceptually does:
|
||||||
|
// foreach (PHINode *PN in DestBB)
|
||||||
|
// PN->setIncomingBlock(PN->getIncomingBlock(TIBB), NewBB);
|
||||||
|
// but is optimized for two cases.
|
||||||
|
|
||||||
|
if (APHI->getNumIncomingValues() <= 8) { // Small # preds case.
|
||||||
unsigned BBIdx = 0;
|
unsigned BBIdx = 0;
|
||||||
for (BasicBlock::iterator I = DestBB->begin(); isa<PHINode>(I); ++I) {
|
for (BasicBlock::iterator I = DestBB->begin(); isa<PHINode>(I); ++I) {
|
||||||
// We no longer enter through TIBB, now we come in through NewBB. Revector
|
// We no longer enter through TIBB, now we come in through NewBB.
|
||||||
// exactly one entry in the PHI node that used to come from TIBB to come
|
// Revector exactly one entry in the PHI node that used to come from
|
||||||
// from NewBB.
|
// TIBB to come from NewBB.
|
||||||
PHINode *PN = cast<PHINode>(I);
|
PHINode *PN = cast<PHINode>(I);
|
||||||
|
|
||||||
// Reuse the previous value of BBIdx if it lines up. In cases where we have
|
// Reuse the previous value of BBIdx if it lines up. In cases where we
|
||||||
// multiple phi nodes with *lots* of predecessors, this is a speed win
|
// have multiple phi nodes with *lots* of predecessors, this is a speed
|
||||||
// because we don't have to scan the PHI looking for TIBB. This happens
|
// win because we don't have to scan the PHI looking for TIBB. This
|
||||||
// because the BB list of PHI nodes are usually in the same order.
|
// happens because the BB list of PHI nodes are usually in the same
|
||||||
|
// order.
|
||||||
if (PN->getIncomingBlock(BBIdx) != TIBB)
|
if (PN->getIncomingBlock(BBIdx) != TIBB)
|
||||||
BBIdx = PN->getBasicBlockIndex(TIBB);
|
BBIdx = PN->getBasicBlockIndex(TIBB);
|
||||||
PN->setIncomingBlock(BBIdx, NewBB);
|
PN->setIncomingBlock(BBIdx, NewBB);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// However, the foreach loop is slow for blocks with lots of predecessors
|
||||||
|
// because PHINode::getIncomingBlock is O(n) in # preds. Instead, walk
|
||||||
|
// the user list of TIBB to find the PHI nodes.
|
||||||
|
SmallPtrSet<PHINode*, 16> UpdatedPHIs;
|
||||||
|
|
||||||
|
for (Value::use_iterator UI = TIBB->use_begin(), E = TIBB->use_end();
|
||||||
|
UI != E; ) {
|
||||||
|
Value::use_iterator Use = UI++;
|
||||||
|
if (PHINode *PN = dyn_cast<PHINode>(Use)) {
|
||||||
|
// Remove one entry from each PHI.
|
||||||
|
if (PN->getParent() == DestBB && UpdatedPHIs.insert(PN))
|
||||||
|
PN->setOperand(Use.getOperandNo(), NewBB);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// If there are any other edges from TIBB to DestBB, update those to go
|
// If there are any other edges from TIBB to DestBB, update those to go
|
||||||
// through the split block, making those edges non-critical as well (and
|
// through the split block, making those edges non-critical as well (and
|
||||||
@ -229,6 +253,15 @@ BasicBlock *llvm::SplitCriticalEdge(TerminatorInst *TI, unsigned SuccNum,
|
|||||||
// If we don't have a pass object, we can't update anything...
|
// If we don't have a pass object, we can't update anything...
|
||||||
if (P == 0) return NewBB;
|
if (P == 0) return NewBB;
|
||||||
|
|
||||||
|
DominatorTree *DT = P->getAnalysisIfAvailable<DominatorTree>();
|
||||||
|
DominanceFrontier *DF = P->getAnalysisIfAvailable<DominanceFrontier>();
|
||||||
|
LoopInfo *LI = P->getAnalysisIfAvailable<LoopInfo>();
|
||||||
|
ProfileInfo *PI = P->getAnalysisIfAvailable<ProfileInfo>();
|
||||||
|
|
||||||
|
// If we have nothing to update, just return.
|
||||||
|
if (DT == 0 && DF == 0 && LI == 0 && PI == 0)
|
||||||
|
return NewBB;
|
||||||
|
|
||||||
// Now update analysis information. Since the only predecessor of NewBB is
|
// Now update analysis information. Since the only predecessor of NewBB is
|
||||||
// the TIBB, TIBB clearly dominates NewBB. TIBB usually doesn't dominate
|
// the TIBB, TIBB clearly dominates NewBB. TIBB usually doesn't dominate
|
||||||
// anything, as there are other successors of DestBB. However, if all other
|
// anything, as there are other successors of DestBB. However, if all other
|
||||||
@ -252,7 +285,7 @@ BasicBlock *llvm::SplitCriticalEdge(TerminatorInst *TI, unsigned SuccNum,
|
|||||||
bool NewBBDominatesDestBB = true;
|
bool NewBBDominatesDestBB = true;
|
||||||
|
|
||||||
// Should we update DominatorTree information?
|
// Should we update DominatorTree information?
|
||||||
if (DominatorTree *DT = P->getAnalysisIfAvailable<DominatorTree>()) {
|
if (DT) {
|
||||||
DomTreeNode *TINode = DT->getNode(TIBB);
|
DomTreeNode *TINode = DT->getNode(TIBB);
|
||||||
|
|
||||||
// The new block is not the immediate dominator for any other nodes, but
|
// The new block is not the immediate dominator for any other nodes, but
|
||||||
@ -283,7 +316,7 @@ BasicBlock *llvm::SplitCriticalEdge(TerminatorInst *TI, unsigned SuccNum,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Should we update DominanceFrontier information?
|
// Should we update DominanceFrontier information?
|
||||||
if (DominanceFrontier *DF = P->getAnalysisIfAvailable<DominanceFrontier>()) {
|
if (DF) {
|
||||||
// If NewBBDominatesDestBB hasn't been computed yet, do so with DF.
|
// If NewBBDominatesDestBB hasn't been computed yet, do so with DF.
|
||||||
if (!OtherPreds.empty()) {
|
if (!OtherPreds.empty()) {
|
||||||
// FIXME: IMPLEMENT THIS!
|
// FIXME: IMPLEMENT THIS!
|
||||||
@ -317,7 +350,7 @@ BasicBlock *llvm::SplitCriticalEdge(TerminatorInst *TI, unsigned SuccNum,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Update LoopInfo if it is around.
|
// Update LoopInfo if it is around.
|
||||||
if (LoopInfo *LI = P->getAnalysisIfAvailable<LoopInfo>()) {
|
if (LI) {
|
||||||
if (Loop *TIL = LI->getLoopFor(TIBB)) {
|
if (Loop *TIL = LI->getLoopFor(TIBB)) {
|
||||||
// If one or the other blocks were not in a loop, the new block is not
|
// If one or the other blocks were not in a loop, the new block is not
|
||||||
// either, and thus LI doesn't need to be updated.
|
// either, and thus LI doesn't need to be updated.
|
||||||
@ -398,7 +431,7 @@ BasicBlock *llvm::SplitCriticalEdge(TerminatorInst *TI, unsigned SuccNum,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Update ProfileInfo if it is around.
|
// Update ProfileInfo if it is around.
|
||||||
if (ProfileInfo *PI = P->getAnalysisIfAvailable<ProfileInfo>())
|
if (PI)
|
||||||
PI->splitEdge(TIBB, DestBB, NewBB, MergeIdenticalEdges);
|
PI->splitEdge(TIBB, DestBB, NewBB, MergeIdenticalEdges);
|
||||||
|
|
||||||
return NewBB;
|
return NewBB;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user