Skip to content

Commit 5ba960e

Browse files
committed
Merge from 'master' to 'sycl-web' (#1)
2 parents 4f72088 + 08e2386 commit 5ba960e

File tree

12 files changed

+122
-124
lines changed

12 files changed

+122
-124
lines changed

llvm-spirv/lib/SPIRV/SPIRVLowerSPIRBlocks.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -342,11 +342,10 @@ class SPIRVLowerSPIRBlocks : public ModulePass {
342342
<< '\n');
343343
auto CG = &getAnalysis<CallGraphWrapperPass>().getCallGraph();
344344
auto ACT = &getAnalysis<AssumptionCacheTracker>();
345-
std::function<AssumptionCache &(Function &)> GetAssumptionCache =
346-
[&](Function &F) -> AssumptionCache & {
345+
auto GetAssumptionCache = [&ACT](Function &F) -> AssumptionCache & {
347346
return ACT->getAssumptionCache(F);
348347
};
349-
InlineFunctionInfo IFI(CG, &GetAssumptionCache);
348+
InlineFunctionInfo IFI(CG, GetAssumptionCache);
350349
InlineFunction(*cast<CallBase>(CI), IFI);
351350
Inlined = true;
352351
}

llvm/include/llvm/Analysis/InlineCost.h

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -216,12 +216,14 @@ int getCallsiteCost(CallBase &Call, const DataLayout &DL);
216216
///
217217
/// Also note that calling this function *dynamically* computes the cost of
218218
/// inlining the callsite. It is an expensive, heavyweight call.
219-
InlineCost getInlineCost(
220-
CallBase &Call, const InlineParams &Params, TargetTransformInfo &CalleeTTI,
221-
std::function<AssumptionCache &(Function &)> &GetAssumptionCache,
222-
Optional<function_ref<BlockFrequencyInfo &(Function &)>> GetBFI,
223-
function_ref<const TargetLibraryInfo &(Function &)> GetTLI,
224-
ProfileSummaryInfo *PSI, OptimizationRemarkEmitter *ORE = nullptr);
219+
InlineCost
220+
getInlineCost(CallBase &Call, const InlineParams &Params,
221+
TargetTransformInfo &CalleeTTI,
222+
function_ref<AssumptionCache &(Function &)> GetAssumptionCache,
223+
function_ref<const TargetLibraryInfo &(Function &)> GetTLI,
224+
function_ref<BlockFrequencyInfo &(Function &)> GetBFI = nullptr,
225+
ProfileSummaryInfo *PSI = nullptr,
226+
OptimizationRemarkEmitter *ORE = nullptr);
225227

226228
/// Get an InlineCost with the callee explicitly specified.
227229
/// This allows you to calculate the cost of inlining a function via a
@@ -231,10 +233,11 @@ InlineCost getInlineCost(
231233
InlineCost
232234
getInlineCost(CallBase &Call, Function *Callee, const InlineParams &Params,
233235
TargetTransformInfo &CalleeTTI,
234-
std::function<AssumptionCache &(Function &)> &GetAssumptionCache,
235-
Optional<function_ref<BlockFrequencyInfo &(Function &)>> GetBFI,
236+
function_ref<AssumptionCache &(Function &)> GetAssumptionCache,
236237
function_ref<const TargetLibraryInfo &(Function &)> GetTLI,
237-
ProfileSummaryInfo *PSI, OptimizationRemarkEmitter *ORE);
238+
function_ref<BlockFrequencyInfo &(Function &)> GetBFI = nullptr,
239+
ProfileSummaryInfo *PSI = nullptr,
240+
OptimizationRemarkEmitter *ORE = nullptr);
238241

239242
/// Returns InlineResult::success() if the call site should be always inlined
240243
/// because of user directives, and the inlining is viable. Returns
@@ -256,9 +259,10 @@ Optional<InlineResult> getAttributeBasedInliningDecision(
256259
/// - an integer, representing the cost.
257260
Optional<int> getInliningCostEstimate(
258261
CallBase &Call, TargetTransformInfo &CalleeTTI,
259-
std::function<AssumptionCache &(Function &)> &GetAssumptionCache,
260-
Optional<function_ref<BlockFrequencyInfo &(Function &)>> GetBFI,
261-
ProfileSummaryInfo *PSI, OptimizationRemarkEmitter *ORE);
262+
function_ref<AssumptionCache &(Function &)> GetAssumptionCache,
263+
function_ref<BlockFrequencyInfo &(Function &)> GetBFI = nullptr,
264+
ProfileSummaryInfo *PSI = nullptr,
265+
OptimizationRemarkEmitter *ORE = nullptr);
262266

263267
/// Minimal filter to detect invalid constructs for inlining.
264268
InlineResult isInlineViable(Function &Callee);

llvm/include/llvm/Transforms/Utils/Cloning.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -171,19 +171,19 @@ void CloneAndPruneFunctionInto(Function *NewFunc, const Function *OldFunc,
171171
/// the auxiliary results produced by it.
172172
class InlineFunctionInfo {
173173
public:
174-
explicit InlineFunctionInfo(CallGraph *cg = nullptr,
175-
std::function<AssumptionCache &(Function &)>
176-
*GetAssumptionCache = nullptr,
177-
ProfileSummaryInfo *PSI = nullptr,
178-
BlockFrequencyInfo *CallerBFI = nullptr,
179-
BlockFrequencyInfo *CalleeBFI = nullptr)
174+
explicit InlineFunctionInfo(
175+
CallGraph *cg = nullptr,
176+
function_ref<AssumptionCache &(Function &)> GetAssumptionCache = nullptr,
177+
ProfileSummaryInfo *PSI = nullptr,
178+
BlockFrequencyInfo *CallerBFI = nullptr,
179+
BlockFrequencyInfo *CalleeBFI = nullptr)
180180
: CG(cg), GetAssumptionCache(GetAssumptionCache), PSI(PSI),
181181
CallerBFI(CallerBFI), CalleeBFI(CalleeBFI) {}
182182

183183
/// If non-null, InlineFunction will update the callgraph to reflect the
184184
/// changes it makes.
185185
CallGraph *CG;
186-
std::function<AssumptionCache &(Function &)> *GetAssumptionCache;
186+
function_ref<AssumptionCache &(Function &)> GetAssumptionCache;
187187
ProfileSummaryInfo *PSI;
188188
BlockFrequencyInfo *CallerBFI, *CalleeBFI;
189189

llvm/lib/Analysis/InlineAdvisor.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,7 @@ DefaultInlineAdvisor::getAdvice(CallBase &CB, FunctionAnalysisManager &FAM) {
9999
*CB.getParent()->getParent()->getParent());
100100

101101
auto &ORE = FAM.getResult<OptimizationRemarkEmitterAnalysis>(Caller);
102-
// FIXME: make GetAssumptionCache's decl similar to the other 2 below. May
103-
// need changing the type of getInlineCost parameters? Also see similar case
104-
// in Inliner.cpp
105-
std::function<AssumptionCache &(Function &)> GetAssumptionCache =
106-
[&](Function &F) -> AssumptionCache & {
102+
auto GetAssumptionCache = [&](Function &F) -> AssumptionCache & {
107103
return FAM.getResult<AssumptionAnalysis>(F);
108104
};
109105
auto GetBFI = [&](Function &F) -> BlockFrequencyInfo & {
@@ -119,8 +115,8 @@ DefaultInlineAdvisor::getAdvice(CallBase &CB, FunctionAnalysisManager &FAM) {
119115
bool RemarksEnabled =
120116
Callee.getContext().getDiagHandlerPtr()->isMissedOptRemarkEnabled(
121117
DEBUG_TYPE);
122-
return getInlineCost(CB, Params, CalleeTTI, GetAssumptionCache, {GetBFI},
123-
GetTLI, PSI, RemarksEnabled ? &ORE : nullptr);
118+
return getInlineCost(CB, Params, CalleeTTI, GetAssumptionCache, GetTLI,
119+
GetBFI, PSI, RemarksEnabled ? &ORE : nullptr);
124120
};
125121
auto OIC = llvm::shouldInline(CB, GetInlineCost, ORE);
126122
return std::make_unique<DefaultInlineAdvice>(this, CB, OIC, ORE);

llvm/lib/Analysis/InlineCost.cpp

Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,14 @@ class CostAnnotationWriter : public AssemblyAnnotationWriter {
138138
formatted_raw_ostream &OS);
139139
};
140140

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.
141149
class CallAnalyzer : public InstVisitor<CallAnalyzer, bool> {
142150
typedef InstVisitor<CallAnalyzer, bool> Base;
143151
friend class InstVisitor<CallAnalyzer, bool>;
@@ -148,10 +156,10 @@ class CallAnalyzer : public InstVisitor<CallAnalyzer, bool> {
148156
const TargetTransformInfo &TTI;
149157

150158
/// Getter for the cache of @llvm.assume intrinsics.
151-
std::function<AssumptionCache &(Function &)> &GetAssumptionCache;
159+
function_ref<AssumptionCache &(Function &)> GetAssumptionCache;
152160

153161
/// Getter for BlockFrequencyInfo
154-
Optional<function_ref<BlockFrequencyInfo &(Function &)>> &GetBFI;
162+
function_ref<BlockFrequencyInfo &(Function &)> GetBFI;
155163

156164
/// Profile summary information.
157165
ProfileSummaryInfo *PSI;
@@ -382,11 +390,12 @@ class CallAnalyzer : public InstVisitor<CallAnalyzer, bool> {
382390
bool visitUnreachableInst(UnreachableInst &I);
383391

384392
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)
390399
: TTI(TTI), GetAssumptionCache(GetAssumptionCache), GetBFI(GetBFI),
391400
PSI(PSI), F(Callee), DL(F.getParent()->getDataLayout()), ORE(ORE),
392401
CandidateCall(Call), EnableLoadElimination(true) {}
@@ -504,8 +513,8 @@ class InlineCostCallAnalyzer final : public CallAnalyzer {
504513
InlineConstants::IndirectCallThreshold;
505514
/// FIXME: if InlineCostCallAnalyzer is derived from, this may need
506515
/// 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);
509518
if (CA.analyze().isSuccess()) {
510519
// We were able to inline the indirect call! Subtract the cost from the
511520
// threshold to get the bonus we want to apply, but don't go below zero.
@@ -693,13 +702,14 @@ class InlineCostCallAnalyzer final : public CallAnalyzer {
693702

694703
public:
695704
InlineCostCallAnalyzer(
705+
Function &Callee, CallBase &Call, const InlineParams &Params,
696706
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,
701711
bool IgnoreThreshold = false)
702-
: CallAnalyzer(TTI, GetAssumptionCache, GetBFI, PSI, ORE, Callee, Call),
712+
: CallAnalyzer(Callee, Call, TTI, GetAssumptionCache, GetBFI, PSI, ORE),
703713
ComputeFullInlineCost(OptComputeFullInlineCost ||
704714
Params.ComputeFullInlineCost || ORE),
705715
Params(Params), Threshold(Params.DefaultThreshold),
@@ -1298,7 +1308,7 @@ void InlineCostCallAnalyzer::updateThreshold(CallBase &Call, Function &Callee) {
12981308
// Callsite hotness and coldness can be determined if sample profile is
12991309
// used (which adds hotness metadata to calls) or if caller's
13001310
// BlockFrequencyInfo is available.
1301-
BlockFrequencyInfo *CallerBFI = GetBFI ? &((*GetBFI)(*Caller)) : nullptr;
1311+
BlockFrequencyInfo *CallerBFI = GetBFI ? &(GetBFI(*Caller)) : nullptr;
13021312
auto HotCallSiteThreshold = getHotCallSiteThreshold(Call, CallerBFI);
13031313
if (!Caller->hasOptSize() && HotCallSiteThreshold) {
13041314
LLVM_DEBUG(dbgs() << "Hot callsite.\n");
@@ -1765,7 +1775,7 @@ bool CallAnalyzer::visitSwitchInst(SwitchInst &SI) {
17651775
// does not (yet) fire.
17661776

17671777
unsigned JumpTableSize = 0;
1768-
BlockFrequencyInfo *BFI = GetBFI ? &((*GetBFI)(F)) : nullptr;
1778+
BlockFrequencyInfo *BFI = GetBFI ? &(GetBFI(F)) : nullptr;
17691779
unsigned NumCaseCluster =
17701780
TTI.getEstimatedNumberOfCaseClusters(SI, JumpTableSize, PSI, BFI);
17711781

@@ -2219,18 +2229,18 @@ int llvm::getCallsiteCost(CallBase &Call, const DataLayout &DL) {
22192229

22202230
InlineCost llvm::getInlineCost(
22212231
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,
22242233
function_ref<const TargetLibraryInfo &(Function &)> GetTLI,
2234+
function_ref<BlockFrequencyInfo &(Function &)> GetBFI,
22252235
ProfileSummaryInfo *PSI, OptimizationRemarkEmitter *ORE) {
22262236
return getInlineCost(Call, Call.getCalledFunction(), Params, CalleeTTI,
2227-
GetAssumptionCache, GetBFI, GetTLI, PSI, ORE);
2237+
GetAssumptionCache, GetTLI, GetBFI, PSI, ORE);
22282238
}
22292239

22302240
Optional<int> llvm::getInliningCostEstimate(
22312241
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,
22342244
ProfileSummaryInfo *PSI, OptimizationRemarkEmitter *ORE) {
22352245
const InlineParams Params = {/* DefaultThreshold*/ 0,
22362246
/*HintThreshold*/ {},
@@ -2242,8 +2252,8 @@ Optional<int> llvm::getInliningCostEstimate(
22422252
/*ColdCallSiteThreshold*/ {},
22432253
/* ComputeFullInlineCost*/ true};
22442254

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,
22472257
/*IgnoreThreshold*/ true);
22482258
auto R = CA.analyze();
22492259
if (!R.isSuccess())
@@ -2315,9 +2325,9 @@ Optional<InlineResult> llvm::getAttributeBasedInliningDecision(
23152325
InlineCost llvm::getInlineCost(
23162326
CallBase &Call, Function *Callee, const InlineParams &Params,
23172327
TargetTransformInfo &CalleeTTI,
2318-
std::function<AssumptionCache &(Function &)> &GetAssumptionCache,
2319-
Optional<function_ref<BlockFrequencyInfo &(Function &)>> GetBFI,
2328+
function_ref<AssumptionCache &(Function &)> GetAssumptionCache,
23202329
function_ref<const TargetLibraryInfo &(Function &)> GetTLI,
2330+
function_ref<BlockFrequencyInfo &(Function &)> GetBFI,
23212331
ProfileSummaryInfo *PSI, OptimizationRemarkEmitter *ORE) {
23222332

23232333
auto UserDecision =
@@ -2333,8 +2343,8 @@ InlineCost llvm::getInlineCost(
23332343
<< "... (caller:" << Call.getCaller()->getName()
23342344
<< ")\n");
23352345

2336-
InlineCostCallAnalyzer CA(CalleeTTI, GetAssumptionCache, GetBFI, PSI, ORE,
2337-
*Callee, Call, Params);
2346+
InlineCostCallAnalyzer CA(*Callee, Call, Params, CalleeTTI,
2347+
GetAssumptionCache, GetBFI, PSI, ORE);
23382348
InlineResult ShouldInline = CA.analyze();
23392349

23402350
LLVM_DEBUG(CA.dump());

llvm/lib/Target/AMDGPU/AMDGPUInline.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -208,14 +208,13 @@ InlineCost AMDGPUInliner::getInlineCost(CallBase &CB) {
208208
}
209209

210210
OptimizationRemarkEmitter ORE(Caller);
211-
std::function<AssumptionCache &(Function &)> GetAssumptionCache =
212-
[this](Function &F) -> AssumptionCache & {
211+
auto GetAssumptionCache = [this](Function &F) -> AssumptionCache & {
213212
return ACT->getAssumptionCache(F);
214213
};
215214

216-
auto IC =
217-
llvm::getInlineCost(CB, Callee, LocalParams, TTI, GetAssumptionCache,
218-
None, GetTLI, PSI, RemarksEnabled ? &ORE : nullptr);
215+
auto IC = llvm::getInlineCost(CB, Callee, LocalParams, TTI,
216+
GetAssumptionCache, GetTLI, nullptr, PSI,
217+
RemarksEnabled ? &ORE : nullptr);
219218

220219
if (IC && !IC.isAlways() && !Callee->hasFnAttribute(Attribute::InlineHint)) {
221220
// Single BB does not increase total BB amount, thus subtract 1

llvm/lib/Transforms/IPO/AlwaysInliner.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,10 @@ PreservedAnalyses AlwaysInlinerPass::run(Module &M,
3636
// Add inline assumptions during code generation.
3737
FunctionAnalysisManager &FAM =
3838
MAM.getResult<FunctionAnalysisManagerModuleProxy>(M).getManager();
39-
std::function<AssumptionCache &(Function &)> GetAssumptionCache =
40-
[&](Function &F) -> AssumptionCache & {
39+
auto GetAssumptionCache = [&](Function &F) -> AssumptionCache & {
4140
return FAM.getResult<AssumptionAnalysis>(F);
4241
};
43-
InlineFunctionInfo IFI(/*cg=*/nullptr, &GetAssumptionCache);
42+
InlineFunctionInfo IFI(/*cg=*/nullptr, GetAssumptionCache);
4443

4544
SmallSetVector<CallBase *, 16> Calls;
4645
bool Changed = false;

llvm/lib/Transforms/IPO/InlineSimple.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ class SimpleInliner : public LegacyInlinerBase {
6868
[&](Function &F) -> AssumptionCache & {
6969
return ACT->getAssumptionCache(F);
7070
};
71-
return llvm::getInlineCost(CB, Params, TTI, GetAssumptionCache,
72-
/*GetBFI=*/None, GetTLI, PSI,
71+
return llvm::getInlineCost(CB, Params, TTI, GetAssumptionCache, GetTLI,
72+
/*GetBFI=*/nullptr, PSI,
7373
RemarksEnabled ? &ORE : nullptr);
7474
}
7575

llvm/lib/Transforms/IPO/Inliner.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ inlineCallsImpl(CallGraphSCC &SCC, CallGraph &CG,
395395
std::swap(CallSites[I--], CallSites[--FirstCallInSCC]);
396396

397397
InlinedArrayAllocasTy InlinedArrayAllocas;
398-
InlineFunctionInfo InlineInfo(&CG, &GetAssumptionCache, PSI);
398+
InlineFunctionInfo InlineInfo(&CG, GetAssumptionCache, PSI);
399399

400400
// Now that we have all of the call sites, loop over them and inline them if
401401
// it looks profitable to do so.
@@ -804,8 +804,7 @@ PreservedAnalyses InlinerPass::run(LazyCallGraph::SCC &InitialC,
804804

805805
LLVM_DEBUG(dbgs() << "Inlining calls in: " << F.getName() << "\n");
806806

807-
std::function<AssumptionCache &(Function &)> GetAssumptionCache =
808-
[&](Function &F) -> AssumptionCache & {
807+
auto GetAssumptionCache = [&](Function &F) -> AssumptionCache & {
809808
return FAM.getResult<AssumptionAnalysis>(F);
810809
};
811810

@@ -849,7 +848,7 @@ PreservedAnalyses InlinerPass::run(LazyCallGraph::SCC &InitialC,
849848
// Setup the data structure used to plumb customization into the
850849
// `InlineFunction` routine.
851850
InlineFunctionInfo IFI(
852-
/*cg=*/nullptr, &GetAssumptionCache, PSI,
851+
/*cg=*/nullptr, GetAssumptionCache, PSI,
853852
&FAM.getResult<BlockFrequencyAnalysis>(*(CB->getCaller())),
854853
&FAM.getResult<BlockFrequencyAnalysis>(Callee));
855854

0 commit comments

Comments
 (0)