aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Analysis/InlineCost.cpp
diff options
context:
space:
mode:
authorDevang Patel <dpatel@apple.com>2010-03-13 00:10:20 +0000
committerDevang Patel <dpatel@apple.com>2010-03-13 00:10:20 +0000
commitcbd056074cfcd79265ee1e04e83f347355e9ad61 (patch)
tree3e6ab746b8a85d9dd6a41413a997002be1025561 /lib/Analysis/InlineCost.cpp
parente4193b20fd30e59c389814835ed2f6b3bc3b225c (diff)
downloadexternal_llvm-cbd056074cfcd79265ee1e04e83f347355e9ad61.zip
external_llvm-cbd056074cfcd79265ee1e04e83f347355e9ad61.tar.gz
external_llvm-cbd056074cfcd79265ee1e04e83f347355e9ad61.tar.bz2
Do not overestimate code size reduction in presense of debug info.
Use CodeMetrics.analyzeBasicBlock() to estimate BB size. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@98401 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/InlineCost.cpp')
-rw-r--r--lib/Analysis/InlineCost.cpp17
1 files changed, 11 insertions, 6 deletions
diff --git a/lib/Analysis/InlineCost.cpp b/lib/Analysis/InlineCost.cpp
index 0f1f93b..280f5f5 100644
--- a/lib/Analysis/InlineCost.cpp
+++ b/lib/Analysis/InlineCost.cpp
@@ -22,7 +22,7 @@ using namespace llvm;
// instructions will be constant folded if the specified value is constant.
//
unsigned InlineCostAnalyzer::FunctionInfo::
- CountCodeReductionForConstant(Value *V) {
+CountCodeReductionForConstant(Value *V, CodeMetrics &Metrics) {
unsigned Reduction = 0;
for (Value::use_iterator UI = V->use_begin(), E = V->use_end(); UI != E; ++UI)
if (isa<BranchInst>(*UI) || isa<SwitchInst>(*UI)) {
@@ -31,7 +31,7 @@ unsigned InlineCostAnalyzer::FunctionInfo::
const unsigned NumSucc = TI.getNumSuccessors();
unsigned Instrs = 0;
for (unsigned I = 0; I != NumSucc; ++I)
- Instrs += TI.getSuccessor(I)->size();
+ Instrs += Metrics.NumBBInsts[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 if (CallInst *CI = dyn_cast<CallInst>(*UI)) {
@@ -71,7 +71,7 @@ unsigned InlineCostAnalyzer::FunctionInfo::
// And any other instructions that use it which become constants
// themselves.
- Reduction += CountCodeReductionForConstant(&Inst);
+ Reduction += CountCodeReductionForConstant(&Inst, Metrics);
}
}
@@ -142,7 +142,7 @@ static bool callIsSmall(const Function *F) {
/// from the specified block.
void CodeMetrics::analyzeBasicBlock(const BasicBlock *BB) {
++NumBlocks;
-
+ unsigned NumInstsInThisBB = 0;
for (BasicBlock::const_iterator II = BB->begin(), E = BB->end();
II != E; ++II) {
if (isa<PHINode>(II)) continue; // PHI nodes don't count.
@@ -196,6 +196,7 @@ void CodeMetrics::analyzeBasicBlock(const BasicBlock *BB) {
}
++NumInsts;
+ ++NumInstsInThisBB;
}
if (isa<ReturnInst>(BB->getTerminator()))
@@ -208,6 +209,9 @@ void CodeMetrics::analyzeBasicBlock(const BasicBlock *BB) {
// function which is extremely undefined behavior.
if (isa<IndirectBrInst>(BB->getTerminator()))
NeverInline = true;
+
+ // Remember NumInsts for this BB.
+ NumBBInsts[BB] = NumInstsInThisBB;
}
/// analyzeFunction - Fill in the current structure with information gleaned
@@ -238,8 +242,9 @@ void InlineCostAnalyzer::FunctionInfo::analyzeFunction(Function *F) {
// code can be eliminated if one of the arguments is a constant.
ArgumentWeights.reserve(F->arg_size());
for (Function::arg_iterator I = F->arg_begin(), E = F->arg_end(); I != E; ++I)
- ArgumentWeights.push_back(ArgInfo(CountCodeReductionForConstant(I),
- CountCodeReductionForAlloca(I)));
+ ArgumentWeights.
+ push_back(ArgInfo(CountCodeReductionForConstant(I, Metrics),
+ CountCodeReductionForAlloca(I)));
}
// getInlineCost - The heuristic used to determine if we should inline the