[llvm-commits] [llvm] r95453 - in /llvm/trunk: include/llvm/Analysis/InlineCost.h lib/Analysis/InlineCost.cpp
Jakob Stoklund Olesen
stoklund at 2pi.dk
Fri Feb 5 15:21:18 PST 2010
Author: stoklund
Date: Fri Feb 5 17:21:18 2010
New Revision: 95453
URL: http://llvm.org/viewvc/llvm-project?rev=95453&view=rev
Log:
Update CodeMetrics to count 'big' function calls explicitly.
Modified:
llvm/trunk/include/llvm/Analysis/InlineCost.h
llvm/trunk/lib/Analysis/InlineCost.cpp
Modified: llvm/trunk/include/llvm/Analysis/InlineCost.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/InlineCost.h?rev=95453&r1=95452&r2=95453&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Analysis/InlineCost.h (original)
+++ llvm/trunk/include/llvm/Analysis/InlineCost.h Fri Feb 5 17:21:18 2010
@@ -34,7 +34,7 @@
/// NeverInline - True if this callee should never be inlined into a
/// caller.
bool NeverInline;
-
+
/// usesDynamicAlloca - True if this function calls alloca (in the C sense).
bool usesDynamicAlloca;
@@ -42,17 +42,20 @@
/// is used to estimate the code size cost of inlining it.
unsigned NumInsts, NumBlocks;
+ /// NumCalls - Keep track of the number of calls to 'big' functions.
+ unsigned NumCalls;
+
/// NumVectorInsts - Keep track of how many instructions produce vector
/// values. The inliner is being more aggressive with inlining vector
/// kernels.
unsigned NumVectorInsts;
-
+
/// NumRets - Keep track of how many Ret instructions the block contains.
unsigned NumRets;
CodeMetrics() : NeverInline(false), usesDynamicAlloca(false), NumInsts(0),
- NumBlocks(0), NumVectorInsts(0), NumRets(0) {}
-
+ NumBlocks(0), NumCalls(0), NumVectorInsts(0), NumRets(0) {}
+
/// analyzeBasicBlock - Add information about the specified basic block
/// to the current structure.
void analyzeBasicBlock(const BasicBlock *BB);
@@ -66,7 +69,7 @@
// Various magic constants used to adjust heuristics.
const int InstrCost = 5;
const int IndirectCallBonus = 500;
- const int CallPenalty = 5; // In instrs, so multiply by InstrCost.
+ const int CallPenalty = 25;
const int LastCallToStaticBonus = -15000;
const int ColdccPenalty = 2000;
const int NoreturnPenalty = 10000;
@@ -121,18 +124,18 @@
return getCost();
}
};
-
+
/// InlineCostAnalyzer - Cost analyzer used by inliner.
class InlineCostAnalyzer {
struct ArgInfo {
public:
unsigned ConstantWeight;
unsigned AllocaWeight;
-
+
ArgInfo(unsigned CWeight, unsigned AWeight)
: ConstantWeight(CWeight), AllocaWeight(AWeight) {}
};
-
+
struct FunctionInfo {
CodeMetrics Metrics;
@@ -141,12 +144,12 @@
/// would reduce the code size. If so, we add some value to the argument
/// entry here.
std::vector<ArgInfo> ArgumentWeights;
-
+
/// CountCodeReductionForConstant - Figure out an approximation for how
/// many instructions will be constant folded if the specified value is
/// constant.
unsigned CountCodeReductionForConstant(Value *V);
-
+
/// CountCodeReductionForAlloca - Figure out an approximation of how much
/// smaller the function will be if it is inlined into a context where an
/// argument becomes an alloca.
Modified: llvm/trunk/lib/Analysis/InlineCost.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/InlineCost.cpp?rev=95453&r1=95452&r2=95453&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/InlineCost.cpp (original)
+++ llvm/trunk/lib/Analysis/InlineCost.cpp Fri Feb 5 17:21:18 2010
@@ -163,10 +163,11 @@
(F->getName() == "setjmp" || F->getName() == "_setjmp"))
NeverInline = true;
- // Each argument to a call takes on average one instruction to set up.
- // Add an extra penalty because calls can take a long time to execute.
- if (!isa<IntrinsicInst>(II) && !callIsSmall(CS.getCalledFunction()))
- NumInsts += InlineConstants::CallPenalty + CS.arg_size();
+ if (!isa<IntrinsicInst>(II) && !callIsSmall(CS.getCalledFunction())) {
+ // Each argument to a call takes on average one instruction to set up.
+ NumInsts += CS.arg_size();
+ ++NumCalls;
+ }
}
if (const AllocaInst *AI = dyn_cast<AllocaInst>(II)) {
@@ -347,7 +348,10 @@
// Now that we have considered all of the factors that make the call site more
// likely to be inlined, look at factors that make us not want to inline it.
-
+
+ // Calls usually take a long time, so they make the inlining gain smaller.
+ InlineCost += CalleeFI.Metrics.NumCalls * InlineConstants::CallPenalty;
+
// Don't inline into something too big, which would make it bigger.
// "size" here is the number of basic blocks, not instructions.
//
More information about the llvm-commits
mailing list