@@ -148,10 +148,10 @@ class CallAnalyzer : public InstVisitor<CallAnalyzer, bool> {
148148 const TargetTransformInfo &TTI;
149149
150150 // / Getter for the cache of @llvm.assume intrinsics.
151- function_ref <AssumptionCache &(Function &)> GetAssumptionCache;
151+ std::function <AssumptionCache &(Function &)> & GetAssumptionCache;
152152
153153 // / Getter for BlockFrequencyInfo
154- function_ref<BlockFrequencyInfo &(Function &)> GetBFI;
154+ Optional< function_ref<BlockFrequencyInfo &(Function &)>> & GetBFI;
155155
156156 // / Profile summary information.
157157 ProfileSummaryInfo *PSI;
@@ -382,12 +382,11 @@ class CallAnalyzer : public InstVisitor<CallAnalyzer, bool> {
382382 bool visitUnreachableInst (UnreachableInst &I);
383383
384384public:
385- CallAnalyzer (
386- Function &Callee, CallBase &Call, const TargetTransformInfo &TTI,
387- const std::function<AssumptionCache &(Function &)> &GetAssumptionCache,
388- function_ref<BlockFrequencyInfo &(Function &)> GetBFI = nullptr ,
389- ProfileSummaryInfo *PSI = nullptr ,
390- OptimizationRemarkEmitter *ORE = nullptr )
385+ CallAnalyzer (const TargetTransformInfo &TTI,
386+ std::function<AssumptionCache &(Function &)> &GetAssumptionCache,
387+ Optional<function_ref<BlockFrequencyInfo &(Function &)>> &GetBFI,
388+ ProfileSummaryInfo *PSI, OptimizationRemarkEmitter *ORE,
389+ Function &Callee, CallBase &Call)
391390 : TTI(TTI), GetAssumptionCache(GetAssumptionCache), GetBFI(GetBFI),
392391 PSI (PSI), F(Callee), DL(F.getParent()->getDataLayout()), ORE(ORE),
393392 CandidateCall(Call), EnableLoadElimination(true ) {}
@@ -505,8 +504,8 @@ class InlineCostCallAnalyzer final : public CallAnalyzer {
505504 InlineConstants::IndirectCallThreshold;
506505 // / FIXME: if InlineCostCallAnalyzer is derived from, this may need
507506 // / to instantiate the derived class.
508- InlineCostCallAnalyzer CA (*F, Call, IndirectCallParams, TTI ,
509- GetAssumptionCache, GetBFI, PSI, ORE , false );
507+ InlineCostCallAnalyzer CA (TTI, GetAssumptionCache, GetBFI, PSI, ORE, *F ,
508+ Call, IndirectCallParams , false );
510509 if (CA.analyze ().isSuccess ()) {
511510 // We were able to inline the indirect call! Subtract the cost from the
512511 // threshold to get the bonus we want to apply, but don't go below zero.
@@ -694,14 +693,13 @@ class InlineCostCallAnalyzer final : public CallAnalyzer {
694693
695694public:
696695 InlineCostCallAnalyzer (
697- Function &Callee, CallBase &Call, const InlineParams &Params,
698696 const TargetTransformInfo &TTI,
699- function_ref <AssumptionCache &(Function &)> GetAssumptionCache,
700- function_ref<BlockFrequencyInfo &(Function &)> GetBFI = nullptr ,
701- ProfileSummaryInfo *PSI = nullptr ,
702- OptimizationRemarkEmitter *ORE = nullptr , bool BoostIndirect = true ,
697+ std::function <AssumptionCache &(Function &)> & GetAssumptionCache,
698+ Optional< function_ref<BlockFrequencyInfo &(Function &)>> & GetBFI,
699+ ProfileSummaryInfo *PSI, OptimizationRemarkEmitter *ORE, Function &Callee ,
700+ CallBase &Call, const InlineParams &Params , bool BoostIndirect = true ,
703701 bool IgnoreThreshold = false )
704- : CallAnalyzer(Callee, Call, TTI, GetAssumptionCache, GetBFI, PSI, ORE),
702+ : CallAnalyzer(TTI, GetAssumptionCache, GetBFI, PSI, ORE, Callee, Call ),
705703 ComputeFullInlineCost (OptComputeFullInlineCost ||
706704 Params.ComputeFullInlineCost || ORE),
707705 Params(Params), Threshold(Params.DefaultThreshold),
@@ -1300,7 +1298,7 @@ void InlineCostCallAnalyzer::updateThreshold(CallBase &Call, Function &Callee) {
13001298 // Callsite hotness and coldness can be determined if sample profile is
13011299 // used (which adds hotness metadata to calls) or if caller's
13021300 // BlockFrequencyInfo is available.
1303- BlockFrequencyInfo *CallerBFI = GetBFI ? &(GetBFI (*Caller)) : nullptr ;
1301+ BlockFrequencyInfo *CallerBFI = GetBFI ? &((* GetBFI) (*Caller)) : nullptr ;
13041302 auto HotCallSiteThreshold = getHotCallSiteThreshold (Call, CallerBFI);
13051303 if (!Caller->hasOptSize () && HotCallSiteThreshold) {
13061304 LLVM_DEBUG (dbgs () << " Hot callsite.\n " );
@@ -1767,7 +1765,7 @@ bool CallAnalyzer::visitSwitchInst(SwitchInst &SI) {
17671765 // does not (yet) fire.
17681766
17691767 unsigned JumpTableSize = 0 ;
1770- BlockFrequencyInfo *BFI = GetBFI ? &(GetBFI (F)) : nullptr ;
1768+ BlockFrequencyInfo *BFI = GetBFI ? &((* GetBFI) (F)) : nullptr ;
17711769 unsigned NumCaseCluster =
17721770 TTI.getEstimatedNumberOfCaseClusters (SI, JumpTableSize, PSI, BFI);
17731771
@@ -2221,18 +2219,18 @@ int llvm::getCallsiteCost(CallBase &Call, const DataLayout &DL) {
22212219
22222220InlineCost llvm::getInlineCost (
22232221 CallBase &Call, const InlineParams &Params, TargetTransformInfo &CalleeTTI,
2224- function_ref<AssumptionCache &(Function &)> GetAssumptionCache,
2222+ std::function<AssumptionCache &(Function &)> &GetAssumptionCache,
2223+ Optional<function_ref<BlockFrequencyInfo &(Function &)>> GetBFI,
22252224 function_ref<const TargetLibraryInfo &(Function &)> GetTLI,
2226- function_ref<BlockFrequencyInfo &(Function &)> GetBFI,
22272225 ProfileSummaryInfo *PSI, OptimizationRemarkEmitter *ORE) {
22282226 return getInlineCost (Call, Call.getCalledFunction (), Params, CalleeTTI,
2229- GetAssumptionCache, GetTLI, GetBFI , PSI, ORE);
2227+ GetAssumptionCache, GetBFI, GetTLI , PSI, ORE);
22302228}
22312229
22322230Optional<int > llvm::getInliningCostEstimate (
22332231 CallBase &Call, TargetTransformInfo &CalleeTTI,
2234- function_ref <AssumptionCache &(Function &)> GetAssumptionCache,
2235- function_ref<BlockFrequencyInfo &(Function &)> GetBFI,
2232+ std::function <AssumptionCache &(Function &)> & GetAssumptionCache,
2233+ Optional< function_ref<BlockFrequencyInfo &(Function &)> > GetBFI,
22362234 ProfileSummaryInfo *PSI, OptimizationRemarkEmitter *ORE) {
22372235 const InlineParams Params = {/* DefaultThreshold*/ 0 ,
22382236 /* HintThreshold*/ {},
@@ -2244,8 +2242,8 @@ Optional<int> llvm::getInliningCostEstimate(
22442242 /* ColdCallSiteThreshold*/ {},
22452243 /* ComputeFullInlineCost*/ true };
22462244
2247- InlineCostCallAnalyzer CA (*Call. getCalledFunction (), Call, Params, CalleeTTI ,
2248- GetAssumptionCache, GetBFI, PSI, ORE , true ,
2245+ InlineCostCallAnalyzer CA (CalleeTTI, GetAssumptionCache, GetBFI, PSI, ORE ,
2246+ *Call. getCalledFunction (), Call, Params , true ,
22492247 /* IgnoreThreshold*/ true );
22502248 auto R = CA.analyze ();
22512249 if (!R.isSuccess ())
@@ -2317,9 +2315,9 @@ Optional<InlineResult> llvm::getAttributeBasedInliningDecision(
23172315InlineCost llvm::getInlineCost (
23182316 CallBase &Call, Function *Callee, const InlineParams &Params,
23192317 TargetTransformInfo &CalleeTTI,
2320- function_ref<AssumptionCache &(Function &)> GetAssumptionCache,
2318+ std::function<AssumptionCache &(Function &)> &GetAssumptionCache,
2319+ Optional<function_ref<BlockFrequencyInfo &(Function &)>> GetBFI,
23212320 function_ref<const TargetLibraryInfo &(Function &)> GetTLI,
2322- function_ref<BlockFrequencyInfo &(Function &)> GetBFI,
23232321 ProfileSummaryInfo *PSI, OptimizationRemarkEmitter *ORE) {
23242322
23252323 auto UserDecision =
@@ -2335,8 +2333,8 @@ InlineCost llvm::getInlineCost(
23352333 << " ... (caller:" << Call.getCaller ()->getName ()
23362334 << " )\n " );
23372335
2338- InlineCostCallAnalyzer CA (*Callee, Call, Params, CalleeTTI ,
2339- GetAssumptionCache, GetBFI, PSI, ORE );
2336+ InlineCostCallAnalyzer CA (CalleeTTI, GetAssumptionCache, GetBFI, PSI, ORE ,
2337+ *Callee, Call, Params );
23402338 InlineResult ShouldInline = CA.analyze ();
23412339
23422340 LLVM_DEBUG (CA.dump ());
0 commit comments