diff options
author | Jakob Stoklund Olesen <stoklund@2pi.dk> | 2010-02-06 01:16:28 +0000 |
---|---|---|
committer | Jakob Stoklund Olesen <stoklund@2pi.dk> | 2010-02-06 01:16:28 +0000 |
commit | 570a4a5d9ca31f276a67502d1e0533d59d331fea (patch) | |
tree | 306ece29a43dcc79fe17a0665e6534ce137e4582 /lib/Transforms | |
parent | 8d535859e583183591503aa63cd4559271803920 (diff) | |
download | external_llvm-570a4a5d9ca31f276a67502d1e0533d59d331fea.zip external_llvm-570a4a5d9ca31f276a67502d1e0533d59d331fea.tar.gz external_llvm-570a4a5d9ca31f276a67502d1e0533d59d331fea.tar.bz2 |
Reintroduce the InlineHint function attribute.
This time it's for real! I am going to hook this up in the frontends as well.
The inliner has some experimental heuristics for dealing with the inline hint.
When given a -respect-inlinehint option, functions marked with the inline
keyword are given a threshold just above the default for -O3.
We need some experiments to determine if that is the right thing to do.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@95466 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms')
-rw-r--r-- | lib/Transforms/IPO/Inliner.cpp | 31 |
1 files changed, 24 insertions, 7 deletions
diff --git a/lib/Transforms/IPO/Inliner.cpp b/lib/Transforms/IPO/Inliner.cpp index 55cc536..97e2f06 100644 --- a/lib/Transforms/IPO/Inliner.cpp +++ b/lib/Transforms/IPO/Inliner.cpp @@ -41,6 +41,16 @@ static cl::opt<int> InlineLimit("inline-threshold", cl::Hidden, cl::init(225), cl::ZeroOrMore, cl::desc("Control the amount of inlining to perform (default = 225)")); +static cl::opt<bool> +RespectHint("respect-inlinehint", cl::Hidden, + cl::desc("Respect the inlinehint attribute")); + +// Threshold to use when inlinehint is given. +const int HintThreshold = 300; + +// Threshold to use when optsize is specified (and there is no -inline-limit). +const int OptSizeThreshold = 75; + Inliner::Inliner(void *ID) : CallGraphSCCPass(ID), InlineThreshold(InlineLimit) {} @@ -172,13 +182,21 @@ static bool InlineCallIfPossible(CallSite CS, CallGraph &CG, return true; } -unsigned Inliner::getInlineThreshold(Function* Caller) const { +unsigned Inliner::getInlineThreshold(CallSite CS) const { + // Listen to inlinehint when -respect-inlinehint is given. + Function *Callee = CS.getCalledFunction(); + if (RespectHint && Callee && !Callee->isDeclaration() && + Callee->hasFnAttr(Attribute::InlineHint)) + return HintThreshold; + + // Listen to optsize when -inline-limit is not given. + Function *Caller = CS.getCaller(); if (Caller && !Caller->isDeclaration() && Caller->hasFnAttr(Attribute::OptimizeForSize) && InlineLimit.getNumOccurrences() == 0) - return 75; - else - return InlineThreshold; + return OptSizeThreshold; + + return InlineThreshold; } /// shouldInline - Return true if the inliner should attempt to inline @@ -200,7 +218,7 @@ bool Inliner::shouldInline(CallSite CS) { int Cost = IC.getValue(); Function *Caller = CS.getCaller(); - int CurrentThreshold = getInlineThreshold(Caller); + int CurrentThreshold = getInlineThreshold(CS); float FudgeFactor = getInlineFudgeFactor(CS); if (Cost >= (int)(CurrentThreshold * FudgeFactor)) { DEBUG(dbgs() << " NOT Inlining: cost=" << Cost @@ -236,8 +254,7 @@ bool Inliner::shouldInline(CallSite CS) { outerCallsFound = true; int Cost2 = IC2.getValue(); - Function *Caller2 = CS2.getCaller(); - int CurrentThreshold2 = getInlineThreshold(Caller2); + int CurrentThreshold2 = getInlineThreshold(CS2); float FudgeFactor2 = getInlineFudgeFactor(CS2); if (Cost2 >= (int)(CurrentThreshold2 * FudgeFactor2)) |