mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-04-17 07:00:05 +00:00
Refactor the inline cost bonus calculation for constants to use
a worklist rather than a recursive call. No functionality changed. llvm-svn: 152706
This commit is contained in:
parent
542f88bf4f
commit
dbefb1f9d8
@ -165,18 +165,24 @@ void CodeMetrics::analyzeBasicBlock(const BasicBlock *BB,
|
|||||||
unsigned InlineCostAnalyzer::FunctionInfo::countCodeReductionForConstant(
|
unsigned InlineCostAnalyzer::FunctionInfo::countCodeReductionForConstant(
|
||||||
const CodeMetrics &Metrics, Value *V) {
|
const CodeMetrics &Metrics, Value *V) {
|
||||||
unsigned Reduction = 0;
|
unsigned Reduction = 0;
|
||||||
for (Value::use_iterator UI = V->use_begin(), E = V->use_end(); UI != E;++UI){
|
SmallVector<Value *, 4> Worklist;
|
||||||
User *U = *UI;
|
Worklist.push_back(V);
|
||||||
if (isa<BranchInst>(U) || isa<SwitchInst>(U)) {
|
do {
|
||||||
// We will be able to eliminate all but one of the successors.
|
Value *V = Worklist.pop_back_val();
|
||||||
const TerminatorInst &TI = cast<TerminatorInst>(*U);
|
for (Value::use_iterator UI = V->use_begin(), E = V->use_end(); UI != E;++UI){
|
||||||
const unsigned NumSucc = TI.getNumSuccessors();
|
User *U = *UI;
|
||||||
unsigned Instrs = 0;
|
if (isa<BranchInst>(U) || isa<SwitchInst>(U)) {
|
||||||
for (unsigned I = 0; I != NumSucc; ++I)
|
// We will be able to eliminate all but one of the successors.
|
||||||
Instrs += Metrics.NumBBInsts.lookup(TI.getSuccessor(I));
|
const TerminatorInst &TI = cast<TerminatorInst>(*U);
|
||||||
// We don't know which blocks will be eliminated, so use the average size.
|
const unsigned NumSucc = TI.getNumSuccessors();
|
||||||
Reduction += InlineConstants::InstrCost*Instrs*(NumSucc-1)/NumSucc;
|
unsigned Instrs = 0;
|
||||||
} else {
|
for (unsigned I = 0; I != NumSucc; ++I)
|
||||||
|
Instrs += Metrics.NumBBInsts.lookup(TI.getSuccessor(I));
|
||||||
|
// We don't know which blocks will be eliminated, so use the average size.
|
||||||
|
Reduction += InlineConstants::InstrCost*Instrs*(NumSucc-1)/NumSucc;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// Figure out if this instruction will be removed due to simple constant
|
// Figure out if this instruction will be removed due to simple constant
|
||||||
// propagation.
|
// propagation.
|
||||||
Instruction &Inst = cast<Instruction>(*U);
|
Instruction &Inst = cast<Instruction>(*U);
|
||||||
@ -198,17 +204,17 @@ unsigned InlineCostAnalyzer::FunctionInfo::countCodeReductionForConstant(
|
|||||||
AllOperandsConstant = false;
|
AllOperandsConstant = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
if (!AllOperandsConstant)
|
||||||
|
continue;
|
||||||
|
|
||||||
if (AllOperandsConstant) {
|
// We will get to remove this instruction...
|
||||||
// We will get to remove this instruction...
|
Reduction += InlineConstants::InstrCost;
|
||||||
Reduction += InlineConstants::InstrCost;
|
|
||||||
|
|
||||||
// And any other instructions that use it which become constants
|
// And any other instructions that use it which become constants
|
||||||
// themselves.
|
// themselves.
|
||||||
Reduction += countCodeReductionForConstant(Metrics, &Inst);
|
Worklist.push_back(&Inst);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
} while (!Worklist.empty());
|
||||||
return Reduction;
|
return Reduction;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user