forked from OSchip/llvm-project
Teach the jump threading optimization to stop scanning the basic block when calculating the cost after passing the threshold.
llvm-svn: 169135
This commit is contained in:
parent
4c2094be3c
commit
2349531def
|
@ -216,19 +216,24 @@ bool JumpThreading::runOnFunction(Function &F) {
|
|||
}
|
||||
|
||||
/// getJumpThreadDuplicationCost - Return the cost of duplicating this block to
|
||||
/// thread across it.
|
||||
static unsigned getJumpThreadDuplicationCost(const BasicBlock *BB) {
|
||||
/// thread across it. Stop scanning the block when passing the threshold.
|
||||
static unsigned getJumpThreadDuplicationCost(const BasicBlock *BB,
|
||||
unsigned Threshold) {
|
||||
/// Ignore PHI nodes, these will be flattened when duplication happens.
|
||||
BasicBlock::const_iterator I = BB->getFirstNonPHI();
|
||||
|
||||
// FIXME: THREADING will delete values that are just used to compute the
|
||||
// branch, so they shouldn't count against the duplication cost.
|
||||
|
||||
|
||||
// Sum up the cost of each instruction until we get to the terminator. Don't
|
||||
// include the terminator because the copy won't include it.
|
||||
unsigned Size = 0;
|
||||
for (; !isa<TerminatorInst>(I); ++I) {
|
||||
|
||||
// Stop scanning the block if we've reached the threshold.
|
||||
if (Size > Threshold)
|
||||
return Size;
|
||||
|
||||
// Debugger intrinsics don't incur code size.
|
||||
if (isa<DbgInfoIntrinsic>(I)) continue;
|
||||
|
||||
|
@ -1337,7 +1342,7 @@ bool JumpThreading::ThreadEdge(BasicBlock *BB,
|
|||
return false;
|
||||
}
|
||||
|
||||
unsigned JumpThreadCost = getJumpThreadDuplicationCost(BB);
|
||||
unsigned JumpThreadCost = getJumpThreadDuplicationCost(BB, Threshold);
|
||||
if (JumpThreadCost > Threshold) {
|
||||
DEBUG(dbgs() << " Not threading BB '" << BB->getName()
|
||||
<< "' - Cost is too high: " << JumpThreadCost << "\n");
|
||||
|
@ -1481,7 +1486,7 @@ bool JumpThreading::DuplicateCondBranchOnPHIIntoPred(BasicBlock *BB,
|
|||
return false;
|
||||
}
|
||||
|
||||
unsigned DuplicationCost = getJumpThreadDuplicationCost(BB);
|
||||
unsigned DuplicationCost = getJumpThreadDuplicationCost(BB, Threshold);
|
||||
if (DuplicationCost > Threshold) {
|
||||
DEBUG(dbgs() << " Not duplicating BB '" << BB->getName()
|
||||
<< "' - Cost is too high: " << DuplicationCost << "\n");
|
||||
|
|
Loading…
Reference in New Issue