summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Analysis/InlineCost.cpp
diff options
context:
space:
mode:
authorChandler Carruth <chandlerc@gmail.com>2012-03-14 07:32:53 +0000
committerChandler Carruth <chandlerc@gmail.com>2012-03-14 07:32:53 +0000
commita3089559934324cced7d01c3f6582f18dd7daf70 (patch)
tree1d4b8968ccc573bc2a1fd4f778fdb723bb1dee9a /llvm/lib/Analysis/InlineCost.cpp
parentd7c0aae45b3ec71e6b080ca34f16e7fdc66794b4 (diff)
downloadbcm5719-llvm-a3089559934324cced7d01c3f6582f18dd7daf70.tar.gz
bcm5719-llvm-a3089559934324cced7d01c3f6582f18dd7daf70.zip
Refactor the inline cost bonus calculation for constants to use
a worklist rather than a recursive call. No functionality changed. llvm-svn: 152706
Diffstat (limited to 'llvm/lib/Analysis/InlineCost.cpp')
-rw-r--r--llvm/lib/Analysis/InlineCost.cpp46
1 files changed, 26 insertions, 20 deletions
diff --git a/llvm/lib/Analysis/InlineCost.cpp b/llvm/lib/Analysis/InlineCost.cpp
index 68d3d4676c2..f8d49a22a7f 100644
--- a/llvm/lib/Analysis/InlineCost.cpp
+++ b/llvm/lib/Analysis/InlineCost.cpp
@@ -165,18 +165,24 @@ void CodeMetrics::analyzeBasicBlock(const BasicBlock *BB,
unsigned InlineCostAnalyzer::FunctionInfo::countCodeReductionForConstant(
const CodeMetrics &Metrics, Value *V) {
unsigned Reduction = 0;
- for (Value::use_iterator UI = V->use_begin(), E = V->use_end(); UI != E;++UI){
- User *U = *UI;
- if (isa<BranchInst>(U) || isa<SwitchInst>(U)) {
- // We will be able to eliminate all but one of the successors.
- const TerminatorInst &TI = cast<TerminatorInst>(*U);
- const unsigned NumSucc = TI.getNumSuccessors();
- unsigned Instrs = 0;
- 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;
- } else {
+ SmallVector<Value *, 4> Worklist;
+ Worklist.push_back(V);
+ do {
+ Value *V = Worklist.pop_back_val();
+ for (Value::use_iterator UI = V->use_begin(), E = V->use_end(); UI != E;++UI){
+ User *U = *UI;
+ if (isa<BranchInst>(U) || isa<SwitchInst>(U)) {
+ // We will be able to eliminate all but one of the successors.
+ const TerminatorInst &TI = cast<TerminatorInst>(*U);
+ const unsigned NumSucc = TI.getNumSuccessors();
+ unsigned Instrs = 0;
+ 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
// propagation.
Instruction &Inst = cast<Instruction>(*U);
@@ -198,17 +204,17 @@ unsigned InlineCostAnalyzer::FunctionInfo::countCodeReductionForConstant(
AllOperandsConstant = false;
break;
}
+ if (!AllOperandsConstant)
+ continue;
- if (AllOperandsConstant) {
- // We will get to remove this instruction...
- Reduction += InlineConstants::InstrCost;
+ // We will get to remove this instruction...
+ Reduction += InlineConstants::InstrCost;
- // And any other instructions that use it which become constants
- // themselves.
- Reduction += countCodeReductionForConstant(Metrics, &Inst);
- }
+ // And any other instructions that use it which become constants
+ // themselves.
+ Worklist.push_back(&Inst);
}
- }
+ } while (!Worklist.empty());
return Reduction;
}
OpenPOWER on IntegriCloud