[PATCH] D78730: [llvm][NFC] Add an explicit 'ComputeFullInlineCost' API
Mircea Trofin via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 24 14:07:08 PDT 2020
mtrofin updated this revision to Diff 259991.
mtrofin added a comment.
simplified
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D78730/new/
https://reviews.llvm.org/D78730
Files:
llvm/include/llvm/Analysis/InlineCost.h
llvm/lib/Analysis/InlineCost.cpp
Index: llvm/lib/Analysis/InlineCost.cpp
===================================================================
--- llvm/lib/Analysis/InlineCost.cpp
+++ llvm/lib/Analysis/InlineCost.cpp
@@ -427,6 +427,9 @@
/// 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,7 +632,7 @@
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.");
}
@@ -694,12 +697,13 @@
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 @@
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) {
Index: llvm/include/llvm/Analysis/InlineCost.h
===================================================================
--- llvm/include/llvm/Analysis/InlineCost.h
+++ llvm/include/llvm/Analysis/InlineCost.h
@@ -246,6 +246,20 @@
CallBase &Call, Function *Callee, TargetTransformInfo &CalleeTTI,
function_ref<const TargetLibraryInfo &(Function &)> GetTLI);
+/// Get the cost estimate ignoring thresholds. This is similar to getInlineCost
+/// when passed InlineParams::ComputeFullInlineCost, or a non-null ORE. It
+/// uses default InlineParams otherwise.
+/// Contrary to getInlineCost, which makes a threshold-based final evaluation of
+/// should/shouldn't inline, captured in InlineResult, getInliningCostEstimate
+/// returns:
+/// - None, if the inlining cannot happen (is illegal)
+/// - an integer, representing the cost.
+Optional<int> getInliningCostEstimate(
+ CallBase &Call, TargetTransformInfo &CalleeTTI,
+ std::function<AssumptionCache &(Function &)> &GetAssumptionCache,
+ Optional<function_ref<BlockFrequencyInfo &(Function &)>> GetBFI,
+ ProfileSummaryInfo *PSI, OptimizationRemarkEmitter *ORE);
+
/// Minimal filter to detect invalid constructs for inlining.
InlineResult isInlineViable(Function &Callee);
} // namespace llvm
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D78730.259991.patch
Type: text/x-patch
Size: 4569 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200424/d5dedcc6/attachment.bin>
More information about the llvm-commits
mailing list