@@ -138,6 +138,14 @@ class CostAnnotationWriter : public AssemblyAnnotationWriter {
138
138
formatted_raw_ostream &OS);
139
139
};
140
140
141
+ // / Carry out call site analysis, in order to evaluate inlinability.
142
+ // / NOTE: the type is currently used as implementation detail of functions such
143
+ // / as llvm::getInlineCost. Note the function_ref constructor parameters - the
144
+ // / expectation is that they come from the outer scope, from the wrapper
145
+ // / functions. If we want to support constructing CallAnalyzer objects where
146
+ // / lambdas are provided inline at construction, or where the object needs to
147
+ // / otherwise survive past the scope of the provided functions, we need to
148
+ // / revisit the argument types.
141
149
class CallAnalyzer : public InstVisitor <CallAnalyzer, bool > {
142
150
typedef InstVisitor<CallAnalyzer, bool > Base;
143
151
friend class InstVisitor <CallAnalyzer, bool >;
@@ -148,10 +156,10 @@ class CallAnalyzer : public InstVisitor<CallAnalyzer, bool> {
148
156
const TargetTransformInfo &TTI;
149
157
150
158
// / Getter for the cache of @llvm.assume intrinsics.
151
- std::function <AssumptionCache &(Function &)> & GetAssumptionCache;
159
+ function_ref <AssumptionCache &(Function &)> GetAssumptionCache;
152
160
153
161
// / Getter for BlockFrequencyInfo
154
- Optional< function_ref<BlockFrequencyInfo &(Function &)>> & GetBFI;
162
+ function_ref<BlockFrequencyInfo &(Function &)> GetBFI;
155
163
156
164
// / Profile summary information.
157
165
ProfileSummaryInfo *PSI;
@@ -382,11 +390,12 @@ class CallAnalyzer : public InstVisitor<CallAnalyzer, bool> {
382
390
bool visitUnreachableInst (UnreachableInst &I);
383
391
384
392
public:
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)
393
+ CallAnalyzer (
394
+ Function &Callee, CallBase &Call, const TargetTransformInfo &TTI,
395
+ function_ref<AssumptionCache &(Function &)> GetAssumptionCache,
396
+ function_ref<BlockFrequencyInfo &(Function &)> GetBFI = nullptr ,
397
+ ProfileSummaryInfo *PSI = nullptr ,
398
+ OptimizationRemarkEmitter *ORE = nullptr )
390
399
: TTI(TTI), GetAssumptionCache(GetAssumptionCache), GetBFI(GetBFI),
391
400
PSI (PSI), F(Callee), DL(F.getParent()->getDataLayout()), ORE(ORE),
392
401
CandidateCall(Call), EnableLoadElimination(true ) {}
@@ -504,8 +513,8 @@ class InlineCostCallAnalyzer final : public CallAnalyzer {
504
513
InlineConstants::IndirectCallThreshold;
505
514
// / FIXME: if InlineCostCallAnalyzer is derived from, this may need
506
515
// / to instantiate the derived class.
507
- InlineCostCallAnalyzer CA (TTI, GetAssumptionCache, GetBFI, PSI, ORE, *F ,
508
- Call, IndirectCallParams , false );
516
+ InlineCostCallAnalyzer CA (*F, Call, IndirectCallParams, TTI ,
517
+ GetAssumptionCache, GetBFI, PSI, ORE , false );
509
518
if (CA.analyze ().isSuccess ()) {
510
519
// We were able to inline the indirect call! Subtract the cost from the
511
520
// threshold to get the bonus we want to apply, but don't go below zero.
@@ -693,13 +702,14 @@ class InlineCostCallAnalyzer final : public CallAnalyzer {
693
702
694
703
public:
695
704
InlineCostCallAnalyzer (
705
+ Function &Callee, CallBase &Call, const InlineParams &Params,
696
706
const TargetTransformInfo &TTI,
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 ,
707
+ function_ref <AssumptionCache &(Function &)> GetAssumptionCache,
708
+ function_ref<BlockFrequencyInfo &(Function &)> GetBFI = nullptr ,
709
+ ProfileSummaryInfo *PSI = nullptr ,
710
+ OptimizationRemarkEmitter *ORE = nullptr , bool BoostIndirect = true ,
701
711
bool IgnoreThreshold = false )
702
- : CallAnalyzer(TTI, GetAssumptionCache, GetBFI, PSI, ORE, Callee, Call ),
712
+ : CallAnalyzer(Callee, Call, TTI, GetAssumptionCache, GetBFI, PSI, ORE),
703
713
ComputeFullInlineCost (OptComputeFullInlineCost ||
704
714
Params.ComputeFullInlineCost || ORE),
705
715
Params(Params), Threshold(Params.DefaultThreshold),
@@ -1298,7 +1308,7 @@ void InlineCostCallAnalyzer::updateThreshold(CallBase &Call, Function &Callee) {
1298
1308
// Callsite hotness and coldness can be determined if sample profile is
1299
1309
// used (which adds hotness metadata to calls) or if caller's
1300
1310
// BlockFrequencyInfo is available.
1301
- BlockFrequencyInfo *CallerBFI = GetBFI ? &((* GetBFI) (*Caller)) : nullptr ;
1311
+ BlockFrequencyInfo *CallerBFI = GetBFI ? &(GetBFI (*Caller)) : nullptr ;
1302
1312
auto HotCallSiteThreshold = getHotCallSiteThreshold (Call, CallerBFI);
1303
1313
if (!Caller->hasOptSize () && HotCallSiteThreshold) {
1304
1314
LLVM_DEBUG (dbgs () << " Hot callsite.\n " );
@@ -1765,7 +1775,7 @@ bool CallAnalyzer::visitSwitchInst(SwitchInst &SI) {
1765
1775
// does not (yet) fire.
1766
1776
1767
1777
unsigned JumpTableSize = 0 ;
1768
- BlockFrequencyInfo *BFI = GetBFI ? &((* GetBFI) (F)) : nullptr ;
1778
+ BlockFrequencyInfo *BFI = GetBFI ? &(GetBFI (F)) : nullptr ;
1769
1779
unsigned NumCaseCluster =
1770
1780
TTI.getEstimatedNumberOfCaseClusters (SI, JumpTableSize, PSI, BFI);
1771
1781
@@ -2219,18 +2229,18 @@ int llvm::getCallsiteCost(CallBase &Call, const DataLayout &DL) {
2219
2229
2220
2230
InlineCost llvm::getInlineCost (
2221
2231
CallBase &Call, const InlineParams &Params, TargetTransformInfo &CalleeTTI,
2222
- std::function<AssumptionCache &(Function &)> &GetAssumptionCache,
2223
- Optional<function_ref<BlockFrequencyInfo &(Function &)>> GetBFI,
2232
+ function_ref<AssumptionCache &(Function &)> GetAssumptionCache,
2224
2233
function_ref<const TargetLibraryInfo &(Function &)> GetTLI,
2234
+ function_ref<BlockFrequencyInfo &(Function &)> GetBFI,
2225
2235
ProfileSummaryInfo *PSI, OptimizationRemarkEmitter *ORE) {
2226
2236
return getInlineCost (Call, Call.getCalledFunction (), Params, CalleeTTI,
2227
- GetAssumptionCache, GetBFI, GetTLI , PSI, ORE);
2237
+ GetAssumptionCache, GetTLI, GetBFI , PSI, ORE);
2228
2238
}
2229
2239
2230
2240
Optional<int > llvm::getInliningCostEstimate (
2231
2241
CallBase &Call, TargetTransformInfo &CalleeTTI,
2232
- std::function <AssumptionCache &(Function &)> & GetAssumptionCache,
2233
- Optional< function_ref<BlockFrequencyInfo &(Function &)> > GetBFI,
2242
+ function_ref <AssumptionCache &(Function &)> GetAssumptionCache,
2243
+ function_ref<BlockFrequencyInfo &(Function &)> GetBFI,
2234
2244
ProfileSummaryInfo *PSI, OptimizationRemarkEmitter *ORE) {
2235
2245
const InlineParams Params = {/* DefaultThreshold*/ 0 ,
2236
2246
/* HintThreshold*/ {},
@@ -2242,8 +2252,8 @@ Optional<int> llvm::getInliningCostEstimate(
2242
2252
/* ColdCallSiteThreshold*/ {},
2243
2253
/* ComputeFullInlineCost*/ true };
2244
2254
2245
- InlineCostCallAnalyzer CA (CalleeTTI, GetAssumptionCache, GetBFI, PSI, ORE ,
2246
- *Call. getCalledFunction (), Call, Params , true ,
2255
+ InlineCostCallAnalyzer CA (*Call. getCalledFunction (), Call, Params, CalleeTTI ,
2256
+ GetAssumptionCache, GetBFI, PSI, ORE , true ,
2247
2257
/* IgnoreThreshold*/ true );
2248
2258
auto R = CA.analyze ();
2249
2259
if (!R.isSuccess ())
@@ -2315,9 +2325,9 @@ Optional<InlineResult> llvm::getAttributeBasedInliningDecision(
2315
2325
InlineCost llvm::getInlineCost (
2316
2326
CallBase &Call, Function *Callee, const InlineParams &Params,
2317
2327
TargetTransformInfo &CalleeTTI,
2318
- std::function<AssumptionCache &(Function &)> &GetAssumptionCache,
2319
- Optional<function_ref<BlockFrequencyInfo &(Function &)>> GetBFI,
2328
+ function_ref<AssumptionCache &(Function &)> GetAssumptionCache,
2320
2329
function_ref<const TargetLibraryInfo &(Function &)> GetTLI,
2330
+ function_ref<BlockFrequencyInfo &(Function &)> GetBFI,
2321
2331
ProfileSummaryInfo *PSI, OptimizationRemarkEmitter *ORE) {
2322
2332
2323
2333
auto UserDecision =
@@ -2333,8 +2343,8 @@ InlineCost llvm::getInlineCost(
2333
2343
<< " ... (caller:" << Call.getCaller ()->getName ()
2334
2344
<< " )\n " );
2335
2345
2336
- InlineCostCallAnalyzer CA (CalleeTTI, GetAssumptionCache, GetBFI, PSI, ORE ,
2337
- *Callee, Call, Params );
2346
+ InlineCostCallAnalyzer CA (*Callee, Call, Params, CalleeTTI ,
2347
+ GetAssumptionCache, GetBFI, PSI, ORE );
2338
2348
InlineResult ShouldInline = CA.analyze ();
2339
2349
2340
2350
LLVM_DEBUG (CA.dump ());
0 commit comments