[llvm] 454de99 - Revert "[llvm][NFC] Cleanup uses of std::function in Inlining-related APIs"

Mircea Trofin via llvm-commits llvm-commits at lists.llvm.org
Fri May 15 11:18:16 PDT 2020


sorry - added a comment in phabricator

On Fri, May 15, 2020 at 11:07 AM David Blaikie <dblaikie at gmail.com> wrote:

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


More information about the llvm-commits mailing list