forked from OSchip/llvm-project
[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
This commit is contained in:
parent
498795829b
commit
8a4013ed38
|
@ -246,6 +246,20 @@ Optional<InlineResult> getAttributeBasedInliningDecision(
|
|||
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
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue