<div dir="ltr">sorry - added a comment in phabricator </div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, May 15, 2020 at 11:07 AM David Blaikie <<a href="mailto:dblaikie@gmail.com">dblaikie@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Why was this reverted? (Good to include that sort of info - links to failing buildbots, potentially quotes of any particular errors/stack traces/etc in the commit message - so folks can help fix it, or don't make introduce the same problem again in the future)</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, May 14, 2020 at 10:33 PM Mircea Trofin via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><br>
Author: Mircea Trofin<br>
Date: 2020-05-14T22:32:44-07:00<br>
New Revision: 454de99a6fec705e76ed7743bf538f7a77296f59<br>
<br>
URL: <a href="https://github.com/llvm/llvm-project/commit/454de99a6fec705e76ed7743bf538f7a77296f59" rel="noreferrer" target="_blank">https://github.com/llvm/llvm-project/commit/454de99a6fec705e76ed7743bf538f7a77296f59</a><br>
DIFF: <a href="https://github.com/llvm/llvm-project/commit/454de99a6fec705e76ed7743bf538f7a77296f59.diff" rel="noreferrer" target="_blank">https://github.com/llvm/llvm-project/commit/454de99a6fec705e76ed7743bf538f7a77296f59.diff</a><br>
<br>
LOG: Revert "[llvm][NFC] Cleanup uses of std::function in Inlining-related APIs"<br>
<br>
This reverts commit 767db5be67cab5aa04d81227725765cad9620611.<br>
<br>
Added: <br>
<br>
<br>
Modified: <br>
llvm/include/llvm/Analysis/InlineCost.h<br>
llvm/include/llvm/Transforms/Utils/Cloning.h<br>
llvm/lib/Analysis/InlineAdvisor.cpp<br>
llvm/lib/Analysis/InlineCost.cpp<br>
llvm/lib/Target/AMDGPU/AMDGPUInline.cpp<br>
llvm/lib/Transforms/IPO/AlwaysInliner.cpp<br>
llvm/lib/Transforms/IPO/InlineSimple.cpp<br>
llvm/lib/Transforms/IPO/Inliner.cpp<br>
llvm/lib/Transforms/IPO/PartialInlining.cpp<br>
llvm/lib/Transforms/IPO/SampleProfile.cpp<br>
llvm/lib/Transforms/Utils/InlineFunction.cpp<br>
<br>
Removed: <br>
<br>
<br>
<br>
################################################################################<br>
diff --git a/llvm/include/llvm/Analysis/InlineCost.h b/llvm/include/llvm/Analysis/InlineCost.h<br>
index 0d67f9f32859..0b37a99a5657 100644<br>
--- a/llvm/include/llvm/Analysis/InlineCost.h<br>
+++ b/llvm/include/llvm/Analysis/InlineCost.h<br>
@@ -216,14 +216,12 @@ int getCallsiteCost(CallBase &Call, const DataLayout &DL);<br>
///<br>
/// Also note that calling this function *dynamically* computes the cost of<br>
/// inlining the callsite. It is an expensive, heavyweight call.<br>
-InlineCost<br>
-getInlineCost(CallBase &Call, const InlineParams &Params,<br>
- TargetTransformInfo &CalleeTTI,<br>
- function_ref<AssumptionCache &(Function &)> GetAssumptionCache,<br>
- function_ref<const TargetLibraryInfo &(Function &)> GetTLI,<br>
- function_ref<BlockFrequencyInfo &(Function &)> GetBFI = nullptr,<br>
- ProfileSummaryInfo *PSI = nullptr,<br>
- OptimizationRemarkEmitter *ORE = nullptr);<br>
+InlineCost getInlineCost(<br>
+ CallBase &Call, const InlineParams &Params, TargetTransformInfo &CalleeTTI,<br>
+ std::function<AssumptionCache &(Function &)> &GetAssumptionCache,<br>
+ Optional<function_ref<BlockFrequencyInfo &(Function &)>> GetBFI,<br>
+ function_ref<const TargetLibraryInfo &(Function &)> GetTLI,<br>
+ ProfileSummaryInfo *PSI, OptimizationRemarkEmitter *ORE = nullptr);<br>
<br>
/// Get an InlineCost with the callee explicitly specified.<br>
/// This allows you to calculate the cost of inlining a function via a<br>
@@ -233,11 +231,10 @@ getInlineCost(CallBase &Call, const InlineParams &Params,<br>
InlineCost<br>
getInlineCost(CallBase &Call, Function *Callee, const InlineParams &Params,<br>
TargetTransformInfo &CalleeTTI,<br>
- function_ref<AssumptionCache &(Function &)> GetAssumptionCache,<br>
+ std::function<AssumptionCache &(Function &)> &GetAssumptionCache,<br>
+ Optional<function_ref<BlockFrequencyInfo &(Function &)>> GetBFI,<br>
function_ref<const TargetLibraryInfo &(Function &)> GetTLI,<br>
- function_ref<BlockFrequencyInfo &(Function &)> GetBFI = nullptr,<br>
- ProfileSummaryInfo *PSI = nullptr,<br>
- OptimizationRemarkEmitter *ORE = nullptr);<br>
+ ProfileSummaryInfo *PSI, OptimizationRemarkEmitter *ORE);<br>
<br>
/// Returns InlineResult::success() if the call site should be always inlined<br>
/// because of user directives, and the inlining is viable. Returns<br>
@@ -259,10 +256,9 @@ Optional<InlineResult> getAttributeBasedInliningDecision(<br>
/// - an integer, representing the cost.<br>
Optional<int> getInliningCostEstimate(<br>
CallBase &Call, TargetTransformInfo &CalleeTTI,<br>
- function_ref<AssumptionCache &(Function &)> GetAssumptionCache,<br>
- function_ref<BlockFrequencyInfo &(Function &)> GetBFI = nullptr,<br>
- ProfileSummaryInfo *PSI = nullptr,<br>
- OptimizationRemarkEmitter *ORE = nullptr);<br>
+ std::function<AssumptionCache &(Function &)> &GetAssumptionCache,<br>
+ Optional<function_ref<BlockFrequencyInfo &(Function &)>> GetBFI,<br>
+ ProfileSummaryInfo *PSI, OptimizationRemarkEmitter *ORE);<br>
<br>
/// Minimal filter to detect invalid constructs for inlining.<br>
InlineResult isInlineViable(Function &Callee);<br>
<br>
diff --git a/llvm/include/llvm/Transforms/Utils/Cloning.h b/llvm/include/llvm/Transforms/Utils/Cloning.h<br>
index 4fce03461deb..6e2ac3265f63 100644<br>
--- a/llvm/include/llvm/Transforms/Utils/Cloning.h<br>
+++ b/llvm/include/llvm/Transforms/Utils/Cloning.h<br>
@@ -171,19 +171,19 @@ void CloneAndPruneFunctionInto(Function *NewFunc, const Function *OldFunc,<br>
/// the auxiliary results produced by it.<br>
class InlineFunctionInfo {<br>
public:<br>
- explicit InlineFunctionInfo(<br>
- CallGraph *cg = nullptr,<br>
- function_ref<AssumptionCache &(Function &)> GetAssumptionCache = nullptr,<br>
- ProfileSummaryInfo *PSI = nullptr,<br>
- BlockFrequencyInfo *CallerBFI = nullptr,<br>
- BlockFrequencyInfo *CalleeBFI = nullptr)<br>
+ explicit InlineFunctionInfo(CallGraph *cg = nullptr,<br>
+ std::function<AssumptionCache &(Function &)><br>
+ *GetAssumptionCache = nullptr,<br>
+ ProfileSummaryInfo *PSI = nullptr,<br>
+ BlockFrequencyInfo *CallerBFI = nullptr,<br>
+ BlockFrequencyInfo *CalleeBFI = nullptr)<br>
: CG(cg), GetAssumptionCache(GetAssumptionCache), PSI(PSI),<br>
CallerBFI(CallerBFI), CalleeBFI(CalleeBFI) {}<br>
<br>
/// If non-null, InlineFunction will update the callgraph to reflect the<br>
/// changes it makes.<br>
CallGraph *CG;<br>
- function_ref<AssumptionCache &(Function &)> GetAssumptionCache;<br>
+ std::function<AssumptionCache &(Function &)> *GetAssumptionCache;<br>
ProfileSummaryInfo *PSI;<br>
BlockFrequencyInfo *CallerBFI, *CalleeBFI;<br>
<br>
<br>
diff --git a/llvm/lib/Analysis/InlineAdvisor.cpp b/llvm/lib/Analysis/InlineAdvisor.cpp<br>
index dcaf9d0fea74..16ab7598ee42 100644<br>
--- a/llvm/lib/Analysis/InlineAdvisor.cpp<br>
+++ b/llvm/lib/Analysis/InlineAdvisor.cpp<br>
@@ -99,7 +99,11 @@ DefaultInlineAdvisor::getAdvice(CallBase &CB, FunctionAnalysisManager &FAM) {<br>
*CB.getParent()->getParent()->getParent());<br>
<br>
auto &ORE = FAM.getResult<OptimizationRemarkEmitterAnalysis>(Caller);<br>
- auto GetAssumptionCache = [&](Function &F) -> AssumptionCache & {<br>
+ // FIXME: make GetAssumptionCache's decl similar to the other 2 below. May<br>
+ // need changing the type of getInlineCost parameters? Also see similar case<br>
+ // in Inliner.cpp<br>
+ std::function<AssumptionCache &(Function &)> GetAssumptionCache =<br>
+ [&](Function &F) -> AssumptionCache & {<br>
return FAM.getResult<AssumptionAnalysis>(F);<br>
};<br>
auto GetBFI = [&](Function &F) -> BlockFrequencyInfo & {<br>
@@ -115,8 +119,8 @@ DefaultInlineAdvisor::getAdvice(CallBase &CB, FunctionAnalysisManager &FAM) {<br>
bool RemarksEnabled =<br>
Callee.getContext().getDiagHandlerPtr()->isMissedOptRemarkEnabled(<br>
DEBUG_TYPE);<br>
- return getInlineCost(CB, Params, CalleeTTI, GetAssumptionCache, GetTLI,<br>
- GetBFI, PSI, RemarksEnabled ? &ORE : nullptr);<br>
+ return getInlineCost(CB, Params, CalleeTTI, GetAssumptionCache, {GetBFI},<br>
+ GetTLI, PSI, RemarksEnabled ? &ORE : nullptr);<br>
};<br>
auto OIC = llvm::shouldInline(CB, GetInlineCost, ORE);<br>
return std::make_unique<DefaultInlineAdvice>(this, CB, OIC, ORE);<br>
<br>
diff --git a/llvm/lib/Analysis/InlineCost.cpp b/llvm/lib/Analysis/InlineCost.cpp<br>
index 1f1050db819b..ce9f030bf379 100644<br>
--- a/llvm/lib/Analysis/InlineCost.cpp<br>
+++ b/llvm/lib/Analysis/InlineCost.cpp<br>
@@ -148,10 +148,10 @@ class CallAnalyzer : public InstVisitor<CallAnalyzer, bool> {<br>
const TargetTransformInfo &TTI;<br>
<br>
/// Getter for the cache of @llvm.assume intrinsics.<br>
- function_ref<AssumptionCache &(Function &)> GetAssumptionCache;<br>
+ std::function<AssumptionCache &(Function &)> &GetAssumptionCache;<br>
<br>
/// Getter for BlockFrequencyInfo<br>
- function_ref<BlockFrequencyInfo &(Function &)> GetBFI;<br>
+ Optional<function_ref<BlockFrequencyInfo &(Function &)>> &GetBFI;<br>
<br>
/// Profile summary information.<br>
ProfileSummaryInfo *PSI;<br>
@@ -382,12 +382,11 @@ class CallAnalyzer : public InstVisitor<CallAnalyzer, bool> {<br>
bool visitUnreachableInst(UnreachableInst &I);<br>
<br>
public:<br>
- CallAnalyzer(<br>
- Function &Callee, CallBase &Call, const TargetTransformInfo &TTI,<br>
- const std::function<AssumptionCache &(Function &)> &GetAssumptionCache,<br>
- function_ref<BlockFrequencyInfo &(Function &)> GetBFI = nullptr,<br>
- ProfileSummaryInfo *PSI = nullptr,<br>
- OptimizationRemarkEmitter *ORE = nullptr)<br>
+ CallAnalyzer(const TargetTransformInfo &TTI,<br>
+ std::function<AssumptionCache &(Function &)> &GetAssumptionCache,<br>
+ Optional<function_ref<BlockFrequencyInfo &(Function &)>> &GetBFI,<br>
+ ProfileSummaryInfo *PSI, OptimizationRemarkEmitter *ORE,<br>
+ Function &Callee, CallBase &Call)<br>
: TTI(TTI), GetAssumptionCache(GetAssumptionCache), GetBFI(GetBFI),<br>
PSI(PSI), F(Callee), DL(F.getParent()->getDataLayout()), ORE(ORE),<br>
CandidateCall(Call), EnableLoadElimination(true) {}<br>
@@ -505,8 +504,8 @@ class InlineCostCallAnalyzer final : public CallAnalyzer {<br>
InlineConstants::IndirectCallThreshold;<br>
/// FIXME: if InlineCostCallAnalyzer is derived from, this may need<br>
/// to instantiate the derived class.<br>
- InlineCostCallAnalyzer CA(*F, Call, IndirectCallParams, TTI,<br>
- GetAssumptionCache, GetBFI, PSI, ORE, false);<br>
+ InlineCostCallAnalyzer CA(TTI, GetAssumptionCache, GetBFI, PSI, ORE, *F,<br>
+ Call, IndirectCallParams, false);<br>
if (CA.analyze().isSuccess()) {<br>
// We were able to inline the indirect call! Subtract the cost from the<br>
// threshold to get the bonus we want to apply, but don't go below zero.<br>
@@ -694,14 +693,13 @@ class InlineCostCallAnalyzer final : public CallAnalyzer {<br>
<br>
public:<br>
InlineCostCallAnalyzer(<br>
- Function &Callee, CallBase &Call, const InlineParams &Params,<br>
const TargetTransformInfo &TTI,<br>
- function_ref<AssumptionCache &(Function &)> GetAssumptionCache,<br>
- function_ref<BlockFrequencyInfo &(Function &)> GetBFI = nullptr,<br>
- ProfileSummaryInfo *PSI = nullptr,<br>
- OptimizationRemarkEmitter *ORE = nullptr, bool BoostIndirect = true,<br>
+ std::function<AssumptionCache &(Function &)> &GetAssumptionCache,<br>
+ Optional<function_ref<BlockFrequencyInfo &(Function &)>> &GetBFI,<br>
+ ProfileSummaryInfo *PSI, OptimizationRemarkEmitter *ORE, Function &Callee,<br>
+ CallBase &Call, const InlineParams &Params, bool BoostIndirect = true,<br>
bool IgnoreThreshold = false)<br>
- : CallAnalyzer(Callee, Call, TTI, GetAssumptionCache, GetBFI, PSI, ORE),<br>
+ : CallAnalyzer(TTI, GetAssumptionCache, GetBFI, PSI, ORE, Callee, Call),<br>
ComputeFullInlineCost(OptComputeFullInlineCost ||<br>
Params.ComputeFullInlineCost || ORE),<br>
Params(Params), Threshold(Params.DefaultThreshold),<br>
@@ -1300,7 +1298,7 @@ void InlineCostCallAnalyzer::updateThreshold(CallBase &Call, Function &Callee) {<br>
// Callsite hotness and coldness can be determined if sample profile is<br>
// used (which adds hotness metadata to calls) or if caller's<br>
// BlockFrequencyInfo is available.<br>
- BlockFrequencyInfo *CallerBFI = GetBFI ? &(GetBFI(*Caller)) : nullptr;<br>
+ BlockFrequencyInfo *CallerBFI = GetBFI ? &((*GetBFI)(*Caller)) : nullptr;<br>
auto HotCallSiteThreshold = getHotCallSiteThreshold(Call, CallerBFI);<br>
if (!Caller->hasOptSize() && HotCallSiteThreshold) {<br>
LLVM_DEBUG(dbgs() << "Hot callsite.\n");<br>
@@ -1767,7 +1765,7 @@ bool CallAnalyzer::visitSwitchInst(SwitchInst &SI) {<br>
// does not (yet) fire.<br>
<br>
unsigned JumpTableSize = 0;<br>
- BlockFrequencyInfo *BFI = GetBFI ? &(GetBFI(F)) : nullptr;<br>
+ BlockFrequencyInfo *BFI = GetBFI ? &((*GetBFI)(F)) : nullptr;<br>
unsigned NumCaseCluster =<br>
TTI.getEstimatedNumberOfCaseClusters(SI, JumpTableSize, PSI, BFI);<br>
<br>
@@ -2221,18 +2219,18 @@ int llvm::getCallsiteCost(CallBase &Call, const DataLayout &DL) {<br>
<br>
InlineCost llvm::getInlineCost(<br>
CallBase &Call, const InlineParams &Params, TargetTransformInfo &CalleeTTI,<br>
- function_ref<AssumptionCache &(Function &)> GetAssumptionCache,<br>
+ std::function<AssumptionCache &(Function &)> &GetAssumptionCache,<br>
+ Optional<function_ref<BlockFrequencyInfo &(Function &)>> GetBFI,<br>
function_ref<const TargetLibraryInfo &(Function &)> GetTLI,<br>
- function_ref<BlockFrequencyInfo &(Function &)> GetBFI,<br>
ProfileSummaryInfo *PSI, OptimizationRemarkEmitter *ORE) {<br>
return getInlineCost(Call, Call.getCalledFunction(), Params, CalleeTTI,<br>
- GetAssumptionCache, GetTLI, GetBFI, PSI, ORE);<br>
+ GetAssumptionCache, GetBFI, GetTLI, PSI, ORE);<br>
}<br>
<br>
Optional<int> llvm::getInliningCostEstimate(<br>
CallBase &Call, TargetTransformInfo &CalleeTTI,<br>
- function_ref<AssumptionCache &(Function &)> GetAssumptionCache,<br>
- function_ref<BlockFrequencyInfo &(Function &)> GetBFI,<br>
+ std::function<AssumptionCache &(Function &)> &GetAssumptionCache,<br>
+ Optional<function_ref<BlockFrequencyInfo &(Function &)>> GetBFI,<br>
ProfileSummaryInfo *PSI, OptimizationRemarkEmitter *ORE) {<br>
const InlineParams Params = {/* DefaultThreshold*/ 0,<br>
/*HintThreshold*/ {},<br>
@@ -2244,8 +2242,8 @@ Optional<int> llvm::getInliningCostEstimate(<br>
/*ColdCallSiteThreshold*/ {},<br>
/* ComputeFullInlineCost*/ true};<br>
<br>
- InlineCostCallAnalyzer CA(*Call.getCalledFunction(), Call, Params, CalleeTTI,<br>
- GetAssumptionCache, GetBFI, PSI, ORE, true,<br>
+ InlineCostCallAnalyzer CA(CalleeTTI, GetAssumptionCache, GetBFI, PSI, ORE,<br>
+ *Call.getCalledFunction(), Call, Params, true,<br>
/*IgnoreThreshold*/ true);<br>
auto R = CA.analyze();<br>
if (!R.isSuccess())<br>
@@ -2317,9 +2315,9 @@ Optional<InlineResult> llvm::getAttributeBasedInliningDecision(<br>
InlineCost llvm::getInlineCost(<br>
CallBase &Call, Function *Callee, const InlineParams &Params,<br>
TargetTransformInfo &CalleeTTI,<br>
- function_ref<AssumptionCache &(Function &)> GetAssumptionCache,<br>
+ std::function<AssumptionCache &(Function &)> &GetAssumptionCache,<br>
+ Optional<function_ref<BlockFrequencyInfo &(Function &)>> GetBFI,<br>
function_ref<const TargetLibraryInfo &(Function &)> GetTLI,<br>
- function_ref<BlockFrequencyInfo &(Function &)> GetBFI,<br>
ProfileSummaryInfo *PSI, OptimizationRemarkEmitter *ORE) {<br>
<br>
auto UserDecision =<br>
@@ -2335,8 +2333,8 @@ InlineCost llvm::getInlineCost(<br>
<< "... (caller:" << Call.getCaller()->getName()<br>
<< ")\n");<br>
<br>
- InlineCostCallAnalyzer CA(*Callee, Call, Params, CalleeTTI,<br>
- GetAssumptionCache, GetBFI, PSI, ORE);<br>
+ InlineCostCallAnalyzer CA(CalleeTTI, GetAssumptionCache, GetBFI, PSI, ORE,<br>
+ *Callee, Call, Params);<br>
InlineResult ShouldInline = CA.analyze();<br>
<br>
LLVM_DEBUG(CA.dump());<br>
<br>
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUInline.cpp b/llvm/lib/Target/AMDGPU/AMDGPUInline.cpp<br>
index 3b5d91133a2f..f980780c5129 100644<br>
--- a/llvm/lib/Target/AMDGPU/AMDGPUInline.cpp<br>
+++ b/llvm/lib/Target/AMDGPU/AMDGPUInline.cpp<br>
@@ -208,13 +208,14 @@ InlineCost AMDGPUInliner::getInlineCost(CallBase &CB) {<br>
}<br>
<br>
OptimizationRemarkEmitter ORE(Caller);<br>
- auto GetAssumptionCache = [this](Function &F) -> AssumptionCache & {<br>
+ std::function<AssumptionCache &(Function &)> GetAssumptionCache =<br>
+ [this](Function &F) -> AssumptionCache & {<br>
return ACT->getAssumptionCache(F);<br>
};<br>
<br>
- auto IC = llvm::getInlineCost(CB, Callee, LocalParams, TTI,<br>
- GetAssumptionCache, GetTLI, nullptr, PSI,<br>
- RemarksEnabled ? &ORE : nullptr);<br>
+ auto IC =<br>
+ llvm::getInlineCost(CB, Callee, LocalParams, TTI, GetAssumptionCache,<br>
+ None, GetTLI, PSI, RemarksEnabled ? &ORE : nullptr);<br>
<br>
if (IC && !IC.isAlways() && !Callee->hasFnAttribute(Attribute::InlineHint)) {<br>
// Single BB does not increase total BB amount, thus subtract 1<br>
<br>
diff --git a/llvm/lib/Transforms/IPO/AlwaysInliner.cpp b/llvm/lib/Transforms/IPO/AlwaysInliner.cpp<br>
index 53f9512f86f3..6987ed6b0cf1 100644<br>
--- a/llvm/lib/Transforms/IPO/AlwaysInliner.cpp<br>
+++ b/llvm/lib/Transforms/IPO/AlwaysInliner.cpp<br>
@@ -36,10 +36,11 @@ PreservedAnalyses AlwaysInlinerPass::run(Module &M,<br>
// Add inline assumptions during code generation.<br>
FunctionAnalysisManager &FAM =<br>
MAM.getResult<FunctionAnalysisManagerModuleProxy>(M).getManager();<br>
- auto GetAssumptionCache = [&](Function &F) -> AssumptionCache & {<br>
+ std::function<AssumptionCache &(Function &)> GetAssumptionCache =<br>
+ [&](Function &F) -> AssumptionCache & {<br>
return FAM.getResult<AssumptionAnalysis>(F);<br>
};<br>
- InlineFunctionInfo IFI(/*cg=*/nullptr, GetAssumptionCache);<br>
+ InlineFunctionInfo IFI(/*cg=*/nullptr, &GetAssumptionCache);<br>
<br>
SmallSetVector<CallBase *, 16> Calls;<br>
bool Changed = false;<br>
<br>
diff --git a/llvm/lib/Transforms/IPO/InlineSimple.cpp b/llvm/lib/Transforms/IPO/InlineSimple.cpp<br>
index 76f1d0c54d08..9eaf9b865094 100644<br>
--- a/llvm/lib/Transforms/IPO/InlineSimple.cpp<br>
+++ b/llvm/lib/Transforms/IPO/InlineSimple.cpp<br>
@@ -68,8 +68,8 @@ class SimpleInliner : public LegacyInlinerBase {<br>
[&](Function &F) -> AssumptionCache & {<br>
return ACT->getAssumptionCache(F);<br>
};<br>
- return llvm::getInlineCost(CB, Params, TTI, GetAssumptionCache, GetTLI,<br>
- /*GetBFI=*/nullptr, PSI,<br>
+ return llvm::getInlineCost(CB, Params, TTI, GetAssumptionCache,<br>
+ /*GetBFI=*/None, GetTLI, PSI,<br>
RemarksEnabled ? &ORE : nullptr);<br>
}<br>
<br>
<br>
diff --git a/llvm/lib/Transforms/IPO/Inliner.cpp b/llvm/lib/Transforms/IPO/Inliner.cpp<br>
index 35a16cb1c7b6..4e94d44c1b40 100644<br>
--- a/llvm/lib/Transforms/IPO/Inliner.cpp<br>
+++ b/llvm/lib/Transforms/IPO/Inliner.cpp<br>
@@ -395,7 +395,7 @@ inlineCallsImpl(CallGraphSCC &SCC, CallGraph &CG,<br>
std::swap(CallSites[I--], CallSites[--FirstCallInSCC]);<br>
<br>
InlinedArrayAllocasTy InlinedArrayAllocas;<br>
- InlineFunctionInfo InlineInfo(&CG, GetAssumptionCache, PSI);<br>
+ InlineFunctionInfo InlineInfo(&CG, &GetAssumptionCache, PSI);<br>
<br>
// Now that we have all of the call sites, loop over them and inline them if<br>
// it looks profitable to do so.<br>
@@ -804,7 +804,8 @@ PreservedAnalyses InlinerPass::run(LazyCallGraph::SCC &InitialC,<br>
<br>
LLVM_DEBUG(dbgs() << "Inlining calls in: " << F.getName() << "\n");<br>
<br>
- auto GetAssumptionCache = [&](Function &F) -> AssumptionCache & {<br>
+ std::function<AssumptionCache &(Function &)> GetAssumptionCache =<br>
+ [&](Function &F) -> AssumptionCache & {<br>
return FAM.getResult<AssumptionAnalysis>(F);<br>
};<br>
<br>
@@ -848,7 +849,7 @@ PreservedAnalyses InlinerPass::run(LazyCallGraph::SCC &InitialC,<br>
// Setup the data structure used to plumb customization into the<br>
// `InlineFunction` routine.<br>
InlineFunctionInfo IFI(<br>
- /*cg=*/nullptr, GetAssumptionCache, PSI,<br>
+ /*cg=*/nullptr, &GetAssumptionCache, PSI,<br>
&FAM.getResult<BlockFrequencyAnalysis>(*(CB->getCaller())),<br>
&FAM.getResult<BlockFrequencyAnalysis>(Callee));<br>
<br>
<br>
diff --git a/llvm/lib/Transforms/IPO/PartialInlining.cpp b/llvm/lib/Transforms/IPO/PartialInlining.cpp<br>
index 5d863f1330a4..19224204dcc5 100644<br>
--- a/llvm/lib/Transforms/IPO/PartialInlining.cpp<br>
+++ b/llvm/lib/Transforms/IPO/PartialInlining.cpp<br>
@@ -198,12 +198,12 @@ struct FunctionOutliningMultiRegionInfo {<br>
struct PartialInlinerImpl {<br>
<br>
PartialInlinerImpl(<br>
- function_ref<AssumptionCache &(Function &)> GetAC,<br>
+ std::function<AssumptionCache &(Function &)> *GetAC,<br>
function_ref<AssumptionCache *(Function &)> LookupAC,<br>
- function_ref<TargetTransformInfo &(Function &)> GTTI,<br>
- function_ref<const TargetLibraryInfo &(Function &)> GTLI,<br>
- ProfileSummaryInfo &ProfSI,<br>
- function_ref<BlockFrequencyInfo &(Function &)> GBFI = nullptr)<br>
+ std::function<TargetTransformInfo &(Function &)> *GTTI,<br>
+ Optional<function_ref<BlockFrequencyInfo &(Function &)>> GBFI,<br>
+ std::function<const TargetLibraryInfo &(Function &)> *GTLI,<br>
+ ProfileSummaryInfo *ProfSI)<br>
: GetAssumptionCache(GetAC), LookupAssumptionCache(LookupAC),<br>
GetTTI(GTTI), GetBFI(GBFI), GetTLI(GTLI), PSI(ProfSI) {}<br>
<br>
@@ -270,12 +270,12 @@ struct PartialInlinerImpl {<br>
<br>
private:<br>
int NumPartialInlining = 0;<br>
- function_ref<AssumptionCache &(Function &)> GetAssumptionCache;<br>
+ std::function<AssumptionCache &(Function &)> *GetAssumptionCache;<br>
function_ref<AssumptionCache *(Function &)> LookupAssumptionCache;<br>
- function_ref<TargetTransformInfo &(Function &)> GetTTI;<br>
- function_ref<BlockFrequencyInfo &(Function &)> GetBFI;<br>
- function_ref<const TargetLibraryInfo &(Function &)> GetTLI;<br>
- ProfileSummaryInfo &PSI;<br>
+ std::function<TargetTransformInfo &(Function &)> *GetTTI;<br>
+ Optional<function_ref<BlockFrequencyInfo &(Function &)>> GetBFI;<br>
+ std::function<const TargetLibraryInfo &(Function &)> *GetTLI;<br>
+ ProfileSummaryInfo *PSI;<br>
<br>
// Return the frequency of the OutlininingBB relative to F's entry point.<br>
// The result is no larger than 1 and is represented using BP.<br>
@@ -362,10 +362,11 @@ struct PartialInlinerLegacyPass : public ModulePass {<br>
AssumptionCacheTracker *ACT = &getAnalysis<AssumptionCacheTracker>();<br>
TargetTransformInfoWrapperPass *TTIWP =<br>
&getAnalysis<TargetTransformInfoWrapperPass>();<br>
- ProfileSummaryInfo &PSI =<br>
- getAnalysis<ProfileSummaryInfoWrapperPass>().getPSI();<br>
+ ProfileSummaryInfo *PSI =<br>
+ &getAnalysis<ProfileSummaryInfoWrapperPass>().getPSI();<br>
<br>
- auto GetAssumptionCache = [&ACT](Function &F) -> AssumptionCache & {<br>
+ std::function<AssumptionCache &(Function &)> GetAssumptionCache =<br>
+ [&ACT](Function &F) -> AssumptionCache & {<br>
return ACT->getAssumptionCache(F);<br>
};<br>
<br>
@@ -373,16 +374,18 @@ struct PartialInlinerLegacyPass : public ModulePass {<br>
return ACT->lookupAssumptionCache(F);<br>
};<br>
<br>
- auto GetTTI = [&TTIWP](Function &F) -> TargetTransformInfo & {<br>
+ std::function<TargetTransformInfo &(Function &)> GetTTI =<br>
+ [&TTIWP](Function &F) -> TargetTransformInfo & {<br>
return TTIWP->getTTI(F);<br>
};<br>
<br>
- auto GetTLI = [this](Function &F) -> TargetLibraryInfo & {<br>
+ std::function<const TargetLibraryInfo &(Function &)> GetTLI =<br>
+ [this](Function &F) -> TargetLibraryInfo & {<br>
return this->getAnalysis<TargetLibraryInfoWrapperPass>().getTLI(F);<br>
};<br>
<br>
- return PartialInlinerImpl(GetAssumptionCache, LookupAssumptionCache, GetTTI,<br>
- GetTLI, PSI)<br>
+ return PartialInlinerImpl(&GetAssumptionCache, LookupAssumptionCache,<br>
+ &GetTTI, NoneType::None, &GetTLI, PSI)<br>
.run(M);<br>
}<br>
};<br>
@@ -403,10 +406,10 @@ PartialInlinerImpl::computeOutliningColdRegionsInfo(Function *F,<br>
ScopedBFI.reset(new BlockFrequencyInfo(*F, BPI, LI));<br>
BFI = ScopedBFI.get();<br>
} else<br>
- BFI = &(GetBFI(*F));<br>
+ BFI = &(*GetBFI)(*F);<br>
<br>
// Return if we don't have profiling information.<br>
- if (!PSI.hasInstrumentationProfile())<br>
+ if (!PSI->hasInstrumentationProfile())<br>
return std::unique_ptr<FunctionOutliningMultiRegionInfo>();<br>
<br>
std::unique_ptr<FunctionOutliningMultiRegionInfo> OutliningInfo =<br>
@@ -479,7 +482,7 @@ PartialInlinerImpl::computeOutliningColdRegionsInfo(Function *F,<br>
// Only consider regions with predecessor blocks that are considered<br>
// not-cold (default: part of the top 99.99% of all block counters)<br>
// AND greater than our minimum block execution count (default: 100).<br>
- if (PSI.isColdBlock(thisBB, BFI) ||<br>
+ if (PSI->isColdBlock(thisBB, BFI) ||<br>
BBProfileCount(thisBB) < MinBlockCounterExecution)<br>
continue;<br>
for (auto SI = succ_begin(thisBB); SI != succ_end(thisBB); ++SI) {<br>
@@ -770,13 +773,13 @@ bool PartialInlinerImpl::shouldPartialInline(<br>
return isInlineViable(*Callee).isSuccess();<br>
<br>
Function *Caller = CB.getCaller();<br>
- auto &CalleeTTI = GetTTI(*Callee);<br>
+ auto &CalleeTTI = (*GetTTI)(*Callee);<br>
bool RemarksEnabled =<br>
Callee->getContext().getDiagHandlerPtr()->isMissedOptRemarkEnabled(<br>
DEBUG_TYPE);<br>
InlineCost IC =<br>
- getInlineCost(CB, getInlineParams(), CalleeTTI, GetAssumptionCache,<br>
- GetTLI, GetBFI, &PSI, RemarksEnabled ? &ORE : nullptr);<br>
+ getInlineCost(CB, getInlineParams(), CalleeTTI, *GetAssumptionCache,<br>
+ GetBFI, *GetTLI, PSI, RemarksEnabled ? &ORE : nullptr);<br>
<br>
if (IC.isAlways()) {<br>
ORE.emit([&]() {<br>
@@ -938,7 +941,7 @@ void PartialInlinerImpl::computeCallsiteToProfCountMap(<br>
CurrentCallerBFI = TempBFI.get();<br>
} else {<br>
// New pass manager:<br>
- CurrentCallerBFI = &(GetBFI(*Caller));<br>
+ CurrentCallerBFI = &(*GetBFI)(*Caller);<br>
}<br>
};<br>
<br>
@@ -1262,7 +1265,7 @@ std::pair<bool, Function *> PartialInlinerImpl::unswitchFunction(Function *F) {<br>
if (F->hasFnAttribute(Attribute::NoInline))<br>
return {false, nullptr};<br>
<br>
- if (PSI.isFunctionEntryCold(F))<br>
+ if (PSI->isFunctionEntryCold(F))<br>
return {false, nullptr};<br>
<br>
if (F->users().empty())<br>
@@ -1272,7 +1275,7 @@ std::pair<bool, Function *> PartialInlinerImpl::unswitchFunction(Function *F) {<br>
<br>
// Only try to outline cold regions if we have a profile summary, which<br>
// implies we have profiling information.<br>
- if (PSI.hasProfileSummary() && F->hasProfileData() &&<br>
+ if (PSI->hasProfileSummary() && F->hasProfileData() &&<br>
!DisableMultiRegionPartialInline) {<br>
std::unique_ptr<FunctionOutliningMultiRegionInfo> OMRI =<br>
computeOutliningColdRegionsInfo(F, ORE);<br>
@@ -1281,8 +1284,8 @@ std::pair<bool, Function *> PartialInlinerImpl::unswitchFunction(Function *F) {<br>
<br>
#ifndef NDEBUG<br>
if (TracePartialInlining) {<br>
- dbgs() << "HotCountThreshold = " << PSI.getHotCountThreshold() << "\n";<br>
- dbgs() << "ColdCountThreshold = " << PSI.getColdCountThreshold()<br>
+ dbgs() << "HotCountThreshold = " << PSI->getHotCountThreshold() << "\n";<br>
+ dbgs() << "ColdCountThreshold = " << PSI->getColdCountThreshold()<br>
<< "\n";<br>
}<br>
#endif<br>
@@ -1402,7 +1405,7 @@ bool PartialInlinerImpl::tryPartialInline(FunctionCloner &Cloner) {<br>
OR << ore::NV("Callee", Cloner.OrigFunc) << " partially inlined into "<br>
<< ore::NV("Caller", CB->getCaller());<br>
<br>
- InlineFunctionInfo IFI(nullptr, GetAssumptionCache, &PSI);<br>
+ InlineFunctionInfo IFI(nullptr, GetAssumptionCache, PSI);<br>
// We can only forward varargs when we outlined a single region, else we<br>
// bail on vararg functions.<br>
if (!InlineFunction(*CB, IFI, nullptr, true,<br>
@@ -1501,7 +1504,8 @@ PreservedAnalyses PartialInlinerPass::run(Module &M,<br>
ModuleAnalysisManager &AM) {<br>
auto &FAM = AM.getResult<FunctionAnalysisManagerModuleProxy>(M).getManager();<br>
<br>
- auto GetAssumptionCache = [&FAM](Function &F) -> AssumptionCache & {<br>
+ std::function<AssumptionCache &(Function &)> GetAssumptionCache =<br>
+ [&FAM](Function &F) -> AssumptionCache & {<br>
return FAM.getResult<AssumptionAnalysis>(F);<br>
};<br>
<br>
@@ -1509,22 +1513,25 @@ PreservedAnalyses PartialInlinerPass::run(Module &M,<br>
return FAM.getCachedResult<AssumptionAnalysis>(F);<br>
};<br>
<br>
- auto GetBFI = [&FAM](Function &F) -> BlockFrequencyInfo & {<br>
+ std::function<BlockFrequencyInfo &(Function &)> GetBFI =<br>
+ [&FAM](Function &F) -> BlockFrequencyInfo & {<br>
return FAM.getResult<BlockFrequencyAnalysis>(F);<br>
};<br>
<br>
- auto GetTTI = [&FAM](Function &F) -> TargetTransformInfo & {<br>
+ std::function<TargetTransformInfo &(Function &)> GetTTI =<br>
+ [&FAM](Function &F) -> TargetTransformInfo & {<br>
return FAM.getResult<TargetIRAnalysis>(F);<br>
};<br>
<br>
- auto GetTLI = [&FAM](Function &F) -> TargetLibraryInfo & {<br>
+ std::function<const TargetLibraryInfo &(Function &)> GetTLI =<br>
+ [&FAM](Function &F) -> TargetLibraryInfo & {<br>
return FAM.getResult<TargetLibraryAnalysis>(F);<br>
};<br>
<br>
- ProfileSummaryInfo &PSI = AM.getResult<ProfileSummaryAnalysis>(M);<br>
+ ProfileSummaryInfo *PSI = &AM.getResult<ProfileSummaryAnalysis>(M);<br>
<br>
- if (PartialInlinerImpl(GetAssumptionCache, LookupAssumptionCache, GetTTI,<br>
- GetTLI, PSI, GetBFI)<br>
+ if (PartialInlinerImpl(&GetAssumptionCache, LookupAssumptionCache, &GetTTI,<br>
+ {GetBFI}, &GetTLI, PSI)<br>
.run(M))<br>
return PreservedAnalyses::none();<br>
return PreservedAnalyses::all();<br>
<br>
diff --git a/llvm/lib/Transforms/IPO/SampleProfile.cpp b/llvm/lib/Transforms/IPO/SampleProfile.cpp<br>
index eb0747fde6d3..85c81f3e6b41 100644<br>
--- a/llvm/lib/Transforms/IPO/SampleProfile.cpp<br>
+++ b/llvm/lib/Transforms/IPO/SampleProfile.cpp<br>
@@ -906,14 +906,14 @@ bool SampleProfileLoader::inlineCallInstruction(CallBase &CB) {<br>
// when cost exceeds threshold without checking all IRs in the callee.<br>
// The acutal cost does not matter because we only checks isNever() to<br>
// see if it is legal to inline the callsite.<br>
- InlineCost Cost =<br>
- getInlineCost(CB, Params, GetTTI(*CalledFunction), GetAC, GetTLI);<br>
+ InlineCost Cost = getInlineCost(CB, Params, GetTTI(*CalledFunction), GetAC,<br>
+ None, GetTLI, nullptr, nullptr);<br>
if (Cost.isNever()) {<br>
ORE->emit(OptimizationRemarkAnalysis(CSINLINE_DEBUG, "InlineFail", DLoc, BB)<br>
<< "incompatible inlining");<br>
return false;<br>
}<br>
- InlineFunctionInfo IFI(nullptr, GetAC);<br>
+ InlineFunctionInfo IFI(nullptr, &GetAC);<br>
if (InlineFunction(CB, IFI).isSuccess()) {<br>
// The call to InlineFunction erases I, so we can't pass it here.<br>
ORE->emit(OptimizationRemark(CSINLINE_DEBUG, "InlineSuccess", DLoc, BB)<br>
@@ -933,7 +933,7 @@ bool SampleProfileLoader::shouldInlineColdCallee(CallBase &CallInst) {<br>
return false;<br>
<br>
InlineCost Cost = getInlineCost(CallInst, getInlineParams(), GetTTI(*Callee),<br>
- GetAC, GetTLI);<br>
+ GetAC, None, GetTLI, nullptr, nullptr);<br>
<br>
return Cost.getCost() <= SampleColdCallSiteThreshold;<br>
}<br>
<br>
diff --git a/llvm/lib/Transforms/Utils/InlineFunction.cpp b/llvm/lib/Transforms/Utils/InlineFunction.cpp<br>
index ad2dd393d6a5..bcba256fde16 100644<br>
--- a/llvm/lib/Transforms/Utils/InlineFunction.cpp<br>
+++ b/llvm/lib/Transforms/Utils/InlineFunction.cpp<br>
@@ -1234,7 +1234,7 @@ static void AddAlignmentAssumptions(CallBase &CB, InlineFunctionInfo &IFI) {<br>
if (!PreserveAlignmentAssumptions || !IFI.GetAssumptionCache)<br>
return;<br>
<br>
- AssumptionCache *AC = &IFI.GetAssumptionCache(*CB.getCaller());<br>
+ AssumptionCache *AC = &(*IFI.GetAssumptionCache)(*CB.getCaller());<br>
auto &DL = CB.getCaller()->getParent()->getDataLayout();<br>
<br>
// To avoid inserting redundant assumptions, we should check for assumptions<br>
@@ -1373,7 +1373,7 @@ static Value *HandleByValArgument(Value *Arg, Instruction *TheCall,<br>
return Arg;<br>
<br>
AssumptionCache *AC =<br>
- IFI.GetAssumptionCache ? &IFI.GetAssumptionCache(*Caller) : nullptr;<br>
+ IFI.GetAssumptionCache ? &(*IFI.GetAssumptionCache)(*Caller) : nullptr;<br>
<br>
// If the pointer is already known to be sufficiently aligned, or if we can<br>
// round it up to a larger alignment, then we don't need a temporary.<br>
@@ -1792,7 +1792,7 @@ llvm::InlineResult llvm::InlineFunction(CallBase &CB, InlineFunctionInfo &IFI,<br>
AddAlignmentAssumptions(CB, IFI);<br>
<br>
AssumptionCache *AC =<br>
- IFI.GetAssumptionCache ? &IFI.GetAssumptionCache(*Caller) : nullptr;<br>
+ IFI.GetAssumptionCache ? &(*IFI.GetAssumptionCache)(*Caller) : nullptr;<br>
<br>
/// Preserve all attributes on of the call and its parameters.<br>
salvageKnowledge(&CB, AC);<br>
@@ -1904,10 +1904,11 @@ llvm::InlineResult llvm::InlineFunction(CallBase &CB, InlineFunctionInfo &IFI,<br>
if (IFI.GetAssumptionCache)<br>
for (BasicBlock &NewBlock :<br>
make_range(FirstNewBlock->getIterator(), Caller->end()))<br>
- for (Instruction &I : NewBlock)<br>
+ for (Instruction &I : NewBlock) {<br>
if (auto *II = dyn_cast<IntrinsicInst>(&I))<br>
if (II->getIntrinsicID() == Intrinsic::assume)<br>
- IFI.GetAssumptionCache(*Caller).registerAssumption(II);<br>
+ (*IFI.GetAssumptionCache)(*Caller).registerAssumption(II);<br>
+ }<br>
}<br>
<br>
// If there are any alloca instructions in the block that used to be the entry<br>
@@ -2495,7 +2496,7 @@ llvm::InlineResult llvm::InlineFunction(CallBase &CB, InlineFunctionInfo &IFI,<br>
// block other optimizations.<br>
if (PHI) {<br>
AssumptionCache *AC =<br>
- IFI.GetAssumptionCache ? &IFI.GetAssumptionCache(*Caller) : nullptr;<br>
+ IFI.GetAssumptionCache ? &(*IFI.GetAssumptionCache)(*Caller) : nullptr;<br>
auto &DL = Caller->getParent()->getDataLayout();<br>
if (Value *V = SimplifyInstruction(PHI, {DL, nullptr, nullptr, AC})) {<br>
PHI->replaceAllUsesWith(V);<br>
<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
</blockquote></div>
</blockquote></div>