diff options
author | Mircea Trofin <mtrofin@google.com> | 2020-04-23 10:04:48 -0700 |
---|---|---|
committer | Mircea Trofin <mtrofin@google.com> | 2020-04-27 09:11:45 -0700 |
commit | 8a4013ed38c6eee730dd6781a7c3dfd2b39e7e80 (patch) | |
tree | bde41f1c2b92992fa14817fad654f067714c489c /llvm/lib/Analysis/InlineCost.cpp | |
parent | 498795829ba6c72824dfa6e44e5a9ebc737f7f66 (diff) | |
download | llvm-8a4013ed38c6eee730dd6781a7c3dfd2b39e7e80.zip llvm-8a4013ed38c6eee730dd6781a7c3dfd2b39e7e80.tar.gz llvm-8a4013ed38c6eee730dd6781a7c3dfd2b39e7e80.tar.bz2 |
[llvm][NFC] Add an explicit 'ComputeFullInlineCost' API
Summary:
Added getInliningCostEstimate, which is essentially what getInlineCost
computes if passed default inlining params, and non-null ORE or
InlineParams::ComputeFullInlineCost.
Reviewers: davidxl, eraman, jdoerfert
Subscribers: hiraditya, haicheng, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D78730
Diffstat (limited to 'llvm/lib/Analysis/InlineCost.cpp')
-rw-r--r-- | llvm/lib/Analysis/InlineCost.cpp | 36 |
1 files changed, 32 insertions, 4 deletions
diff --git a/llvm/lib/Analysis/InlineCost.cpp b/llvm/lib/Analysis/InlineCost.cpp index e247d8f..c7894a9 100644 --- a/llvm/lib/Analysis/InlineCost.cpp +++ b/llvm/lib/Analysis/InlineCost.cpp @@ -427,6 +427,9 @@ class InlineCostCallAnalyzer final : public CallAnalyzer { /// Attempt to evaluate indirect calls to boost its inline cost. const bool BoostIndirectCalls; + /// Ignore the threshold when finalizing analysis. + const bool IgnoreThreshold; + /// Inlining cost measured in abstract units, accounts for all the /// instructions expected to be executed for a given function invocation. /// Instructions that are statically proven to be dead based on call-site @@ -629,14 +632,14 @@ class InlineCostCallAnalyzer final : public CallAnalyzer { else if (NumVectorInstructions <= NumInstructions / 2) Threshold -= VectorBonus / 2; - if (Cost < std::max(1, Threshold)) + if (IgnoreThreshold || Cost < std::max(1, Threshold)) return InlineResult::success(); return InlineResult::failure("Cost over threshold."); } bool shouldStop() override { // Bail out the moment we cross the threshold. This means we'll under-count // the cost, but only when undercounting doesn't matter. - return Cost >= Threshold && !ComputeFullInlineCost; + return !IgnoreThreshold && Cost >= Threshold && !ComputeFullInlineCost; } void onLoadEliminationOpportunity() override { @@ -694,12 +697,13 @@ public: std::function<AssumptionCache &(Function &)> &GetAssumptionCache, Optional<function_ref<BlockFrequencyInfo &(Function &)>> &GetBFI, ProfileSummaryInfo *PSI, OptimizationRemarkEmitter *ORE, Function &Callee, - CallBase &Call, const InlineParams &Params, bool BoostIndirect = true) + CallBase &Call, const InlineParams &Params, bool BoostIndirect = true, + bool IgnoreThreshold = false) : CallAnalyzer(TTI, GetAssumptionCache, GetBFI, PSI, ORE, Callee, Call), ComputeFullInlineCost(OptComputeFullInlineCost || Params.ComputeFullInlineCost || ORE), Params(Params), Threshold(Params.DefaultThreshold), - BoostIndirectCalls(BoostIndirect) {} + BoostIndirectCalls(BoostIndirect), IgnoreThreshold(IgnoreThreshold) {} /// Annotation Writer for cost annotation CostAnnotationWriter Writer; @@ -2215,6 +2219,30 @@ InlineCost llvm::getInlineCost( GetAssumptionCache, GetBFI, GetTLI, PSI, ORE); } +Optional<int> getInliningCostEstimate( + CallBase &Call, TargetTransformInfo &CalleeTTI, + std::function<AssumptionCache &(Function &)> &GetAssumptionCache, + Optional<function_ref<BlockFrequencyInfo &(Function &)>> GetBFI, + ProfileSummaryInfo *PSI, OptimizationRemarkEmitter *ORE) { + const InlineParams Params = {/* DefaultThreshold*/ 0, + /*HintThreshold*/ {}, + /*ColdThreshold*/ {}, + /*OptSizeThreshold*/ {}, + /*OptMinSizeThreshold*/ {}, + /*HotCallSiteThreshold*/ {}, + /*LocallyHotCallSiteThreshold*/ {}, + /*ColdCallSiteThreshold*/ {}, + /* ComputeFullInlineCost*/ true}; + + InlineCostCallAnalyzer CA(CalleeTTI, GetAssumptionCache, GetBFI, PSI, ORE, + *Call.getCalledFunction(), Call, Params, true, + /*IgnoreThreshold*/ true); + auto R = CA.analyze(); + if (!R.isSuccess()) + return None; + return CA.getCost(); +} + Optional<InlineResult> llvm::getAttributeBasedInliningDecision( CallBase &Call, Function *Callee, TargetTransformInfo &CalleeTTI, function_ref<const TargetLibraryInfo &(Function &)> GetTLI) { |