[llvm-commits] [llvm] r98401 - in /llvm/trunk: include/llvm/Analysis/InlineCost.h lib/Analysis/InlineCost.cpp
Jakob Stoklund Olesen
stoklund at 2pi.dk
Fri Mar 12 16:37:35 PST 2010
On Mar 12, 2010, at 4:10 PM, Devang Patel wrote:
> Author: dpatel
> Date: Fri Mar 12 18:10:20 2010
> New Revision: 98401
>
> URL: http://llvm.org/viewvc/llvm-project?rev=98401&view=rev
> Log:
> Do not overestimate code size reduction in presense of debug info.
> Use CodeMetrics.analyzeBasicBlock() to estimate BB size.
>
> 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=98401&r1=98400&r2=98401&view=diff
> ==============================================================================
> --- llvm/trunk/include/llvm/Analysis/InlineCost.h (original)
> +++ llvm/trunk/include/llvm/Analysis/InlineCost.h Fri Mar 12 18:10:20 2010
> @@ -18,6 +18,7 @@
> #include <climits>
> #include <map>
> #include <vector>
> +#include "llvm/ADT/DenseMap.h"
>
> namespace llvm {
>
> @@ -42,6 +43,9 @@
> /// is used to estimate the code size cost of inlining it.
> unsigned NumInsts, NumBlocks;
>
> + /// NumBBInsts - Keeps track of basic block code size estimates.
> + DenseMap<const BasicBlock *, unsigned> NumBBInsts;
> +
> /// NumCalls - Keep track of the number of calls to 'big' functions.
> unsigned NumCalls;
>
> @@ -148,7 +152,7 @@
> /// CountCodeReductionForConstant - Figure out an approximation for how
> /// many instructions will be constant folded if the specified value is
> /// constant.
> - unsigned CountCodeReductionForConstant(Value *V);
> + unsigned CountCodeReductionForConstant(Value *V, CodeMetrics &M);
The extra argument is not necessary since FunctionInfo already has a Metrics member.
>
> /// CountCodeReductionForAlloca - Figure out an approximation of how much
> /// smaller the function will be if it is inlined into a context where an
>
> Modified: llvm/trunk/lib/Analysis/InlineCost.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/InlineCost.cpp?rev=98401&r1=98400&r2=98401&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Analysis/InlineCost.cpp (original)
> +++ llvm/trunk/lib/Analysis/InlineCost.cpp Fri Mar 12 18:10:20 2010
> @@ -22,7 +22,7 @@
> // 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 @@
> 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 @@
>
> // And any other instructions that use it which become constants
> // themselves.
> - Reduction += CountCodeReductionForConstant(&Inst);
> + Reduction += CountCodeReductionForConstant(&Inst, Metrics);
> }
> }
>
> @@ -142,7 +142,7 @@
> /// 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 @@
> }
>
> ++NumInsts;
> + ++NumInstsInThisBB;
I think you should also include 'NumInsts += InlineConstants::CallPenalty + CS.arg_size();' for consistency.
/jakob
More information about the llvm-commits
mailing list