@@ -148,10 +148,10 @@ class CallAnalyzer : public InstVisitor<CallAnalyzer, bool> {
148
148
const TargetTransformInfo &TTI;
149
149
150
150
// / Getter for the cache of @llvm.assume intrinsics.
151
- function_ref <AssumptionCache &(Function &)> GetAssumptionCache;
151
+ std::function <AssumptionCache &(Function &)> & GetAssumptionCache;
152
152
153
153
// / Getter for BlockFrequencyInfo
154
- function_ref<BlockFrequencyInfo &(Function &)> GetBFI;
154
+ Optional< function_ref<BlockFrequencyInfo &(Function &)>> & GetBFI;
155
155
156
156
// / Profile summary information.
157
157
ProfileSummaryInfo *PSI;
@@ -382,12 +382,11 @@ class CallAnalyzer : public InstVisitor<CallAnalyzer, bool> {
382
382
bool visitUnreachableInst (UnreachableInst &I);
383
383
384
384
public:
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)
391
390
: TTI(TTI), GetAssumptionCache(GetAssumptionCache), GetBFI(GetBFI),
392
391
PSI (PSI), F(Callee), DL(F.getParent()->getDataLayout()), ORE(ORE),
393
392
CandidateCall(Call), EnableLoadElimination(true ) {}
@@ -505,8 +504,8 @@ class InlineCostCallAnalyzer final : public CallAnalyzer {
505
504
InlineConstants::IndirectCallThreshold;
506
505
// / FIXME: if InlineCostCallAnalyzer is derived from, this may need
507
506
// / 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 );
510
509
if (CA.analyze ().isSuccess ()) {
511
510
// We were able to inline the indirect call! Subtract the cost from the
512
511
// threshold to get the bonus we want to apply, but don't go below zero.
@@ -694,14 +693,13 @@ class InlineCostCallAnalyzer final : public CallAnalyzer {
694
693
695
694
public:
696
695
InlineCostCallAnalyzer (
697
- Function &Callee, CallBase &Call, const InlineParams &Params,
698
696
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 ,
703
701
bool IgnoreThreshold = false )
704
- : CallAnalyzer(Callee, Call, TTI, GetAssumptionCache, GetBFI, PSI, ORE),
702
+ : CallAnalyzer(TTI, GetAssumptionCache, GetBFI, PSI, ORE, Callee, Call ),
705
703
ComputeFullInlineCost (OptComputeFullInlineCost ||
706
704
Params.ComputeFullInlineCost || ORE),
707
705
Params(Params), Threshold(Params.DefaultThreshold),
@@ -1300,7 +1298,7 @@ void InlineCostCallAnalyzer::updateThreshold(CallBase &Call, Function &Callee) {
1300
1298
// Callsite hotness and coldness can be determined if sample profile is
1301
1299
// used (which adds hotness metadata to calls) or if caller's
1302
1300
// BlockFrequencyInfo is available.
1303
- BlockFrequencyInfo *CallerBFI = GetBFI ? &(GetBFI (*Caller)) : nullptr ;
1301
+ BlockFrequencyInfo *CallerBFI = GetBFI ? &((* GetBFI) (*Caller)) : nullptr ;
1304
1302
auto HotCallSiteThreshold = getHotCallSiteThreshold (Call, CallerBFI);
1305
1303
if (!Caller->hasOptSize () && HotCallSiteThreshold) {
1306
1304
LLVM_DEBUG (dbgs () << " Hot callsite.\n " );
@@ -1767,7 +1765,7 @@ bool CallAnalyzer::visitSwitchInst(SwitchInst &SI) {
1767
1765
// does not (yet) fire.
1768
1766
1769
1767
unsigned JumpTableSize = 0 ;
1770
- BlockFrequencyInfo *BFI = GetBFI ? &(GetBFI (F)) : nullptr ;
1768
+ BlockFrequencyInfo *BFI = GetBFI ? &((* GetBFI) (F)) : nullptr ;
1771
1769
unsigned NumCaseCluster =
1772
1770
TTI.getEstimatedNumberOfCaseClusters (SI, JumpTableSize, PSI, BFI);
1773
1771
@@ -2221,18 +2219,18 @@ int llvm::getCallsiteCost(CallBase &Call, const DataLayout &DL) {
2221
2219
2222
2220
InlineCost llvm::getInlineCost (
2223
2221
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,
2225
2224
function_ref<const TargetLibraryInfo &(Function &)> GetTLI,
2226
- function_ref<BlockFrequencyInfo &(Function &)> GetBFI,
2227
2225
ProfileSummaryInfo *PSI, OptimizationRemarkEmitter *ORE) {
2228
2226
return getInlineCost (Call, Call.getCalledFunction (), Params, CalleeTTI,
2229
- GetAssumptionCache, GetTLI, GetBFI , PSI, ORE);
2227
+ GetAssumptionCache, GetBFI, GetTLI , PSI, ORE);
2230
2228
}
2231
2229
2232
2230
Optional<int > llvm::getInliningCostEstimate (
2233
2231
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,
2236
2234
ProfileSummaryInfo *PSI, OptimizationRemarkEmitter *ORE) {
2237
2235
const InlineParams Params = {/* DefaultThreshold*/ 0 ,
2238
2236
/* HintThreshold*/ {},
@@ -2244,8 +2242,8 @@ Optional<int> llvm::getInliningCostEstimate(
2244
2242
/* ColdCallSiteThreshold*/ {},
2245
2243
/* ComputeFullInlineCost*/ true };
2246
2244
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 ,
2249
2247
/* IgnoreThreshold*/ true );
2250
2248
auto R = CA.analyze ();
2251
2249
if (!R.isSuccess ())
@@ -2317,9 +2315,9 @@ Optional<InlineResult> llvm::getAttributeBasedInliningDecision(
2317
2315
InlineCost llvm::getInlineCost (
2318
2316
CallBase &Call, Function *Callee, const InlineParams &Params,
2319
2317
TargetTransformInfo &CalleeTTI,
2320
- function_ref<AssumptionCache &(Function &)> GetAssumptionCache,
2318
+ std::function<AssumptionCache &(Function &)> &GetAssumptionCache,
2319
+ Optional<function_ref<BlockFrequencyInfo &(Function &)>> GetBFI,
2321
2320
function_ref<const TargetLibraryInfo &(Function &)> GetTLI,
2322
- function_ref<BlockFrequencyInfo &(Function &)> GetBFI,
2323
2321
ProfileSummaryInfo *PSI, OptimizationRemarkEmitter *ORE) {
2324
2322
2325
2323
auto UserDecision =
@@ -2335,8 +2333,8 @@ InlineCost llvm::getInlineCost(
2335
2333
<< " ... (caller:" << Call.getCaller ()->getName ()
2336
2334
<< " )\n " );
2337
2335
2338
- InlineCostCallAnalyzer CA (*Callee, Call, Params, CalleeTTI ,
2339
- GetAssumptionCache, GetBFI, PSI, ORE );
2336
+ InlineCostCallAnalyzer CA (CalleeTTI, GetAssumptionCache, GetBFI, PSI, ORE ,
2337
+ *Callee, Call, Params );
2340
2338
InlineResult ShouldInline = CA.analyze ();
2341
2339
2342
2340
LLVM_DEBUG (CA.dump ());
0 commit comments