diff options
| author | Easwaran Raman <eraman@google.com> | 2016-01-14 23:16:29 +0000 |
|---|---|---|
| committer | Easwaran Raman <eraman@google.com> | 2016-01-14 23:16:29 +0000 |
| commit | f4bb2f0dc322e15dddda95eafbb2eb0485f03e69 (patch) | |
| tree | a28e6ac212c09266ad6b4d7d25c99b00f3f6b1d3 /llvm/lib/Transforms | |
| parent | 14714c4181d8cb142ed684c9abfba835b9167410 (diff) | |
| download | bcm5719-llvm-f4bb2f0dc322e15dddda95eafbb2eb0485f03e69.tar.gz bcm5719-llvm-f4bb2f0dc322e15dddda95eafbb2eb0485f03e69.zip | |
Refactor threshold computation for inline cost analysis
Differential Revision: http://reviews.llvm.org/D15401
llvm-svn: 257832
Diffstat (limited to 'llvm/lib/Transforms')
| -rw-r--r-- | llvm/lib/Transforms/IPO/InlineAlways.cpp | 6 | ||||
| -rw-r--r-- | llvm/lib/Transforms/IPO/InlineSimple.cpp | 26 | ||||
| -rw-r--r-- | llvm/lib/Transforms/IPO/Inliner.cpp | 90 |
3 files changed, 15 insertions, 107 deletions
diff --git a/llvm/lib/Transforms/IPO/InlineAlways.cpp b/llvm/lib/Transforms/IPO/InlineAlways.cpp index 1704bfea0b8..e7623a96300 100644 --- a/llvm/lib/Transforms/IPO/InlineAlways.cpp +++ b/llvm/lib/Transforms/IPO/InlineAlways.cpp @@ -37,13 +37,11 @@ namespace { class AlwaysInliner : public Inliner { public: - // Use extremely low threshold. - AlwaysInliner() : Inliner(ID, -2000000000, /*InsertLifetime*/ true) { + AlwaysInliner() : Inliner(ID, /*InsertLifetime*/ true) { initializeAlwaysInlinerPass(*PassRegistry::getPassRegistry()); } - AlwaysInliner(bool InsertLifetime) - : Inliner(ID, -2000000000, InsertLifetime) { + AlwaysInliner(bool InsertLifetime) : Inliner(ID, InsertLifetime) { initializeAlwaysInlinerPass(*PassRegistry::getPassRegistry()); } diff --git a/llvm/lib/Transforms/IPO/InlineSimple.cpp b/llvm/lib/Transforms/IPO/InlineSimple.cpp index 45609f891ed..a87c0d396db 100644 --- a/llvm/lib/Transforms/IPO/InlineSimple.cpp +++ b/llvm/lib/Transforms/IPO/InlineSimple.cpp @@ -38,14 +38,19 @@ namespace { /// inliner pass and the always inliner pass. The two passes use different cost /// analyses to determine when to inline. class SimpleInliner : public Inliner { + // This field is populated based on one of the following: + // optimization or size optimization levels, + // --inline-threshold flag, + // user specified value. + int DefaultThreshold; public: - SimpleInliner() : Inliner(ID) { + SimpleInliner() + : Inliner(ID), DefaultThreshold(llvm::getDefaultInlineThreshold()) { initializeSimpleInlinerPass(*PassRegistry::getPassRegistry()); } - SimpleInliner(int Threshold) - : Inliner(ID, Threshold, /*InsertLifetime*/ true) { + SimpleInliner(int Threshold) : Inliner(ID), DefaultThreshold(Threshold) { initializeSimpleInlinerPass(*PassRegistry::getPassRegistry()); } @@ -54,7 +59,7 @@ public: InlineCost getInlineCost(CallSite CS) override { Function *Callee = CS.getCalledFunction(); TargetTransformInfo &TTI = TTIWP->getTTI(*Callee); - return llvm::getInlineCost(CS, getInlineThreshold(CS), TTI, ACT); + return llvm::getInlineCost(CS, DefaultThreshold, TTI, ACT); } bool runOnSCC(CallGraphSCC &SCC) override; @@ -64,17 +69,6 @@ private: TargetTransformInfoWrapperPass *TTIWP; }; -static int computeThresholdFromOptLevels(unsigned OptLevel, - unsigned SizeOptLevel) { - if (OptLevel > 2) - return 275; - if (SizeOptLevel == 1) // -Os - return 75; - if (SizeOptLevel == 2) // -Oz - return 25; - return 225; -} - } // end anonymous namespace char SimpleInliner::ID = 0; @@ -96,7 +90,7 @@ Pass *llvm::createFunctionInliningPass(int Threshold) { Pass *llvm::createFunctionInliningPass(unsigned OptLevel, unsigned SizeOptLevel) { return new SimpleInliner( - computeThresholdFromOptLevels(OptLevel, SizeOptLevel)); + llvm::computeThresholdFromOptLevels(OptLevel, SizeOptLevel)); } bool SimpleInliner::runOnSCC(CallGraphSCC &SCC) { diff --git a/llvm/lib/Transforms/IPO/Inliner.cpp b/llvm/lib/Transforms/IPO/Inliner.cpp index bbe5f8761d5..bdef4733906 100644 --- a/llvm/lib/Transforms/IPO/Inliner.cpp +++ b/llvm/lib/Transforms/IPO/Inliner.cpp @@ -47,33 +47,10 @@ STATISTIC(NumMergedAllocas, "Number of allocas merged together"); // if those would be more profitable and blocked inline steps. STATISTIC(NumCallerCallersAnalyzed, "Number of caller-callers analyzed"); -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<int> -HintThreshold("inlinehint-threshold", cl::Hidden, cl::init(325), - cl::desc("Threshold for inlining functions with inline hint")); - -// We instroduce this threshold to help performance of instrumentation based -// PGO before we actually hook up inliner with analysis passes such as BPI and -// BFI. -static cl::opt<int> -ColdThreshold("inlinecold-threshold", cl::Hidden, cl::init(225), - cl::desc("Threshold for inlining functions with cold attribute")); - -// Threshold to use when optsize is specified (and there is no -inline-limit). -const int OptSizeThreshold = 75; - -Inliner::Inliner(char &ID) - : CallGraphSCCPass(ID), InlineThreshold(InlineLimit), InsertLifetime(true) { -} +Inliner::Inliner(char &ID) : CallGraphSCCPass(ID), InsertLifetime(true) {} -Inliner::Inliner(char &ID, int Threshold, bool InsertLifetime) - : CallGraphSCCPass(ID), - InlineThreshold(InlineLimit.getNumOccurrences() > 0 ? InlineLimit - : Threshold), - InsertLifetime(InsertLifetime) {} +Inliner::Inliner(char &ID, bool InsertLifetime) + : CallGraphSCCPass(ID), InsertLifetime(InsertLifetime) {} /// For this class, we declare that we require and preserve the call graph. /// If the derived class implements this method, it should @@ -243,67 +220,6 @@ static bool InlineCallIfPossible(Pass &P, CallSite CS, InlineFunctionInfo &IFI, return true; } -unsigned Inliner::getInlineThreshold(CallSite CS) const { - int Threshold = InlineThreshold; // -inline-threshold or else selected by - // overall opt level - - // If -inline-threshold is not given, listen to the optsize attribute when it - // would decrease the threshold. - Function *Caller = CS.getCaller(); - bool OptSize = Caller && !Caller->isDeclaration() && - // FIXME: Use Function::optForSize(). - Caller->hasFnAttribute(Attribute::OptimizeForSize); - if (!(InlineLimit.getNumOccurrences() > 0) && OptSize && - OptSizeThreshold < Threshold) - Threshold = OptSizeThreshold; - - Function *Callee = CS.getCalledFunction(); - if (!Callee || Callee->isDeclaration()) - return Threshold; - - // If profile information is available, use that to adjust threshold of hot - // and cold functions. - // FIXME: The heuristic used below for determining hotness and coldness are - // based on preliminary SPEC tuning and may not be optimal. Replace this with - // a well-tuned heuristic based on *callsite* hotness and not callee hotness. - uint64_t FunctionCount = 0, MaxFunctionCount = 0; - bool HasPGOCounts = false; - if (Callee->getEntryCount() && - Callee->getParent()->getMaximumFunctionCount()) { - HasPGOCounts = true; - FunctionCount = Callee->getEntryCount().getValue(); - MaxFunctionCount = - Callee->getParent()->getMaximumFunctionCount().getValue(); - } - - // Listen to the inlinehint attribute or profile based hotness information - // when it would increase the threshold and the caller does not need to - // minimize its size. - bool InlineHint = - Callee->hasFnAttribute(Attribute::InlineHint) || - (HasPGOCounts && - FunctionCount >= (uint64_t)(0.3 * (double)MaxFunctionCount)); - if (InlineHint && HintThreshold > Threshold && - !Caller->hasFnAttribute(Attribute::MinSize)) - Threshold = HintThreshold; - - // Listen to the cold attribute or profile based coldness information - // when it would decrease the threshold. - bool ColdCallee = - Callee->hasFnAttribute(Attribute::Cold) || - (HasPGOCounts && - FunctionCount <= (uint64_t)(0.01 * (double)MaxFunctionCount)); - // Command line argument for InlineLimit will override the default - // ColdThreshold. If we have -inline-threshold but no -inlinecold-threshold, - // do not use the default cold threshold even if it is smaller. - if ((InlineLimit.getNumOccurrences() == 0 || - ColdThreshold.getNumOccurrences() > 0) && ColdCallee && - ColdThreshold < Threshold) - Threshold = ColdThreshold; - - return Threshold; -} - static void emitAnalysis(CallSite CS, const Twine &Msg) { Function *Caller = CS.getCaller(); LLVMContext &Ctx = Caller->getContext(); |

