@@ -427,6 +427,9 @@ class InlineCostCallAnalyzer final : public CallAnalyzer {
427427 // / Attempt to evaluate indirect calls to boost its inline cost.
428428 const bool BoostIndirectCalls;
429429
430+ // / Ignore the threshold when finalizing analysis.
431+ const bool IgnoreThreshold;
432+
430433 // / Inlining cost measured in abstract units, accounts for all the
431434 // / instructions expected to be executed for a given function invocation.
432435 // / Instructions that are statically proven to be dead based on call-site
@@ -629,14 +632,14 @@ class InlineCostCallAnalyzer final : public CallAnalyzer {
629632 else if (NumVectorInstructions <= NumInstructions / 2 )
630633 Threshold -= VectorBonus / 2 ;
631634
632- if (Cost < std::max (1 , Threshold))
635+ if (IgnoreThreshold || Cost < std::max (1 , Threshold))
633636 return InlineResult::success ();
634637 return InlineResult::failure (" Cost over threshold." );
635638 }
636639 bool shouldStop () override {
637640 // Bail out the moment we cross the threshold. This means we'll under-count
638641 // the cost, but only when undercounting doesn't matter.
639- return Cost >= Threshold && !ComputeFullInlineCost;
642+ return !IgnoreThreshold && Cost >= Threshold && !ComputeFullInlineCost;
640643 }
641644
642645 void onLoadEliminationOpportunity () override {
@@ -694,12 +697,13 @@ class InlineCostCallAnalyzer final : public CallAnalyzer {
694697 std::function<AssumptionCache &(Function &)> &GetAssumptionCache,
695698 Optional<function_ref<BlockFrequencyInfo &(Function &)>> &GetBFI,
696699 ProfileSummaryInfo *PSI, OptimizationRemarkEmitter *ORE, Function &Callee,
697- CallBase &Call, const InlineParams &Params, bool BoostIndirect = true )
700+ CallBase &Call, const InlineParams &Params, bool BoostIndirect = true ,
701+ bool IgnoreThreshold = false )
698702 : CallAnalyzer(TTI, GetAssumptionCache, GetBFI, PSI, ORE, Callee, Call),
699703 ComputeFullInlineCost (OptComputeFullInlineCost ||
700704 Params.ComputeFullInlineCost || ORE),
701705 Params(Params), Threshold(Params.DefaultThreshold),
702- BoostIndirectCalls(BoostIndirect) {}
706+ BoostIndirectCalls(BoostIndirect), IgnoreThreshold(IgnoreThreshold) {}
703707
704708 // / Annotation Writer for cost annotation
705709 CostAnnotationWriter Writer;
@@ -2215,6 +2219,30 @@ InlineCost llvm::getInlineCost(
22152219 GetAssumptionCache, GetBFI, GetTLI, PSI, ORE);
22162220}
22172221
2222+ Optional<int > getInliningCostEstimate (
2223+ CallBase &Call, TargetTransformInfo &CalleeTTI,
2224+ std::function<AssumptionCache &(Function &)> &GetAssumptionCache,
2225+ Optional<function_ref<BlockFrequencyInfo &(Function &)>> GetBFI,
2226+ ProfileSummaryInfo *PSI, OptimizationRemarkEmitter *ORE) {
2227+ const InlineParams Params = {/* DefaultThreshold*/ 0 ,
2228+ /* HintThreshold*/ {},
2229+ /* ColdThreshold*/ {},
2230+ /* OptSizeThreshold*/ {},
2231+ /* OptMinSizeThreshold*/ {},
2232+ /* HotCallSiteThreshold*/ {},
2233+ /* LocallyHotCallSiteThreshold*/ {},
2234+ /* ColdCallSiteThreshold*/ {},
2235+ /* ComputeFullInlineCost*/ true };
2236+
2237+ InlineCostCallAnalyzer CA (CalleeTTI, GetAssumptionCache, GetBFI, PSI, ORE,
2238+ *Call.getCalledFunction (), Call, Params, true ,
2239+ /* IgnoreThreshold*/ true );
2240+ auto R = CA.analyze ();
2241+ if (!R.isSuccess ())
2242+ return None;
2243+ return CA.getCost ();
2244+ }
2245+
22182246Optional<InlineResult> llvm::getAttributeBasedInliningDecision (
22192247 CallBase &Call, Function *Callee, TargetTransformInfo &CalleeTTI,
22202248 function_ref<const TargetLibraryInfo &(Function &)> GetTLI) {
0 commit comments