diff --git a/llvm/include/llvm/Analysis/InlineCost.h b/llvm/include/llvm/Analysis/InlineCost.h --- a/llvm/include/llvm/Analysis/InlineCost.h +++ b/llvm/include/llvm/Analysis/InlineCost.h @@ -216,12 +216,14 @@ /// /// 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, - std::function &GetAssumptionCache, - Optional> GetBFI, - function_ref GetTLI, - ProfileSummaryInfo *PSI, OptimizationRemarkEmitter *ORE = nullptr); +InlineCost +getInlineCost(CallBase &Call, const InlineParams &Params, + TargetTransformInfo &CalleeTTI, + function_ref GetAssumptionCache, + function_ref GetTLI, + function_ref GetBFI = nullptr, + ProfileSummaryInfo *PSI = nullptr, + OptimizationRemarkEmitter *ORE = nullptr); /// Get an InlineCost with the callee explicitly specified. /// This allows you to calculate the cost of inlining a function via a @@ -231,10 +233,11 @@ InlineCost getInlineCost(CallBase &Call, Function *Callee, const InlineParams &Params, TargetTransformInfo &CalleeTTI, - std::function &GetAssumptionCache, - Optional> GetBFI, + function_ref GetAssumptionCache, function_ref GetTLI, - ProfileSummaryInfo *PSI, OptimizationRemarkEmitter *ORE); + function_ref GetBFI = nullptr, + ProfileSummaryInfo *PSI = nullptr, + OptimizationRemarkEmitter *ORE = nullptr); /// Returns InlineResult::success() if the call site should be always inlined /// because of user directives, and the inlining is viable. Returns @@ -256,9 +259,10 @@ /// - an integer, representing the cost. Optional getInliningCostEstimate( CallBase &Call, TargetTransformInfo &CalleeTTI, - std::function &GetAssumptionCache, - Optional> GetBFI, - ProfileSummaryInfo *PSI, OptimizationRemarkEmitter *ORE); + function_ref GetAssumptionCache, + function_ref GetBFI = nullptr, + ProfileSummaryInfo *PSI = nullptr, + OptimizationRemarkEmitter *ORE = nullptr); /// 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 --- a/llvm/include/llvm/Transforms/Utils/Cloning.h +++ b/llvm/include/llvm/Transforms/Utils/Cloning.h @@ -171,19 +171,19 @@ /// the auxiliary results produced by it. class InlineFunctionInfo { public: - explicit InlineFunctionInfo(CallGraph *cg = nullptr, - std::function - *GetAssumptionCache = nullptr, - ProfileSummaryInfo *PSI = nullptr, - BlockFrequencyInfo *CallerBFI = nullptr, - BlockFrequencyInfo *CalleeBFI = nullptr) + explicit InlineFunctionInfo( + CallGraph *cg = nullptr, + function_ref 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; - std::function *GetAssumptionCache; + function_ref GetAssumptionCache; ProfileSummaryInfo *PSI; BlockFrequencyInfo *CallerBFI, *CalleeBFI; diff --git a/llvm/lib/Analysis/InlineAdvisor.cpp b/llvm/lib/Analysis/InlineAdvisor.cpp --- a/llvm/lib/Analysis/InlineAdvisor.cpp +++ b/llvm/lib/Analysis/InlineAdvisor.cpp @@ -99,11 +99,7 @@ *CB.getParent()->getParent()->getParent()); auto &ORE = FAM.getResult(Caller); - // 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 GetAssumptionCache = - [&](Function &F) -> AssumptionCache & { + auto GetAssumptionCache = [&](Function &F) -> AssumptionCache & { return FAM.getResult(F); }; auto GetBFI = [&](Function &F) -> BlockFrequencyInfo & { @@ -119,8 +115,8 @@ bool RemarksEnabled = Callee.getContext().getDiagHandlerPtr()->isMissedOptRemarkEnabled( DEBUG_TYPE); - return getInlineCost(CB, Params, CalleeTTI, GetAssumptionCache, {GetBFI}, - GetTLI, PSI, RemarksEnabled ? &ORE : nullptr); + return getInlineCost(CB, Params, CalleeTTI, GetAssumptionCache, GetTLI, + GetBFI, PSI, RemarksEnabled ? &ORE : nullptr); }; auto OIC = llvm::shouldInline(CB, GetInlineCost, ORE); return std::make_unique(this, CB, OIC, ORE); diff --git a/llvm/lib/Analysis/InlineCost.cpp b/llvm/lib/Analysis/InlineCost.cpp --- a/llvm/lib/Analysis/InlineCost.cpp +++ b/llvm/lib/Analysis/InlineCost.cpp @@ -148,10 +148,10 @@ const TargetTransformInfo &TTI; /// Getter for the cache of @llvm.assume intrinsics. - std::function &GetAssumptionCache; + function_ref GetAssumptionCache; /// Getter for BlockFrequencyInfo - Optional> &GetBFI; + function_ref GetBFI; /// Profile summary information. ProfileSummaryInfo *PSI; @@ -382,11 +382,12 @@ bool visitUnreachableInst(UnreachableInst &I); public: - CallAnalyzer(const TargetTransformInfo &TTI, - std::function &GetAssumptionCache, - Optional> &GetBFI, - ProfileSummaryInfo *PSI, OptimizationRemarkEmitter *ORE, - Function &Callee, CallBase &Call) + CallAnalyzer( + Function &Callee, CallBase &Call, const TargetTransformInfo &TTI, + const std::function &GetAssumptionCache, + function_ref GetBFI = nullptr, + ProfileSummaryInfo *PSI = nullptr, + OptimizationRemarkEmitter *ORE = nullptr) : TTI(TTI), GetAssumptionCache(GetAssumptionCache), GetBFI(GetBFI), PSI(PSI), F(Callee), DL(F.getParent()->getDataLayout()), ORE(ORE), CandidateCall(Call), EnableLoadElimination(true) {} @@ -504,8 +505,8 @@ InlineConstants::IndirectCallThreshold; /// FIXME: if InlineCostCallAnalyzer is derived from, this may need /// to instantiate the derived class. - InlineCostCallAnalyzer CA(TTI, GetAssumptionCache, GetBFI, PSI, ORE, *F, - Call, IndirectCallParams, false); + InlineCostCallAnalyzer CA(*F, Call, IndirectCallParams, TTI, + GetAssumptionCache, GetBFI, PSI, ORE, 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. @@ -693,13 +694,14 @@ public: InlineCostCallAnalyzer( + Function &Callee, CallBase &Call, const InlineParams &Params, const TargetTransformInfo &TTI, - std::function &GetAssumptionCache, - Optional> &GetBFI, - ProfileSummaryInfo *PSI, OptimizationRemarkEmitter *ORE, Function &Callee, - CallBase &Call, const InlineParams &Params, bool BoostIndirect = true, + function_ref GetAssumptionCache, + function_ref GetBFI = nullptr, + ProfileSummaryInfo *PSI = nullptr, + OptimizationRemarkEmitter *ORE = nullptr, bool BoostIndirect = true, bool IgnoreThreshold = false) - : CallAnalyzer(TTI, GetAssumptionCache, GetBFI, PSI, ORE, Callee, Call), + : CallAnalyzer(Callee, Call, TTI, GetAssumptionCache, GetBFI, PSI, ORE), ComputeFullInlineCost(OptComputeFullInlineCost || Params.ComputeFullInlineCost || ORE), Params(Params), Threshold(Params.DefaultThreshold), @@ -1298,7 +1300,7 @@ // 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"); @@ -1765,7 +1767,7 @@ // 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); @@ -2219,18 +2221,18 @@ InlineCost llvm::getInlineCost( CallBase &Call, const InlineParams &Params, TargetTransformInfo &CalleeTTI, - std::function &GetAssumptionCache, - Optional> GetBFI, + function_ref GetAssumptionCache, function_ref GetTLI, + function_ref GetBFI, ProfileSummaryInfo *PSI, OptimizationRemarkEmitter *ORE) { return getInlineCost(Call, Call.getCalledFunction(), Params, CalleeTTI, - GetAssumptionCache, GetBFI, GetTLI, PSI, ORE); + GetAssumptionCache, GetTLI, GetBFI, PSI, ORE); } Optional llvm::getInliningCostEstimate( CallBase &Call, TargetTransformInfo &CalleeTTI, - std::function &GetAssumptionCache, - Optional> GetBFI, + function_ref GetAssumptionCache, + function_ref GetBFI, ProfileSummaryInfo *PSI, OptimizationRemarkEmitter *ORE) { const InlineParams Params = {/* DefaultThreshold*/ 0, /*HintThreshold*/ {}, @@ -2242,8 +2244,8 @@ /*ColdCallSiteThreshold*/ {}, /* ComputeFullInlineCost*/ true}; - InlineCostCallAnalyzer CA(CalleeTTI, GetAssumptionCache, GetBFI, PSI, ORE, - *Call.getCalledFunction(), Call, Params, true, + InlineCostCallAnalyzer CA(*Call.getCalledFunction(), Call, Params, CalleeTTI, + GetAssumptionCache, GetBFI, PSI, ORE, true, /*IgnoreThreshold*/ true); auto R = CA.analyze(); if (!R.isSuccess()) @@ -2315,9 +2317,9 @@ InlineCost llvm::getInlineCost( CallBase &Call, Function *Callee, const InlineParams &Params, TargetTransformInfo &CalleeTTI, - std::function &GetAssumptionCache, - Optional> GetBFI, + function_ref GetAssumptionCache, function_ref GetTLI, + function_ref GetBFI, ProfileSummaryInfo *PSI, OptimizationRemarkEmitter *ORE) { auto UserDecision = @@ -2333,8 +2335,8 @@ << "... (caller:" << Call.getCaller()->getName() << ")\n"); - InlineCostCallAnalyzer CA(CalleeTTI, GetAssumptionCache, GetBFI, PSI, ORE, - *Callee, Call, Params); + InlineCostCallAnalyzer CA(*Callee, Call, Params, CalleeTTI, + GetAssumptionCache, GetBFI, PSI, ORE); InlineResult ShouldInline = CA.analyze(); LLVM_DEBUG(CA.dump()); diff --git a/llvm/lib/Target/AMDGPU/AMDGPUInline.cpp b/llvm/lib/Target/AMDGPU/AMDGPUInline.cpp --- a/llvm/lib/Target/AMDGPU/AMDGPUInline.cpp +++ b/llvm/lib/Target/AMDGPU/AMDGPUInline.cpp @@ -208,14 +208,13 @@ } OptimizationRemarkEmitter ORE(Caller); - std::function GetAssumptionCache = - [this](Function &F) -> AssumptionCache & { + auto GetAssumptionCache = [this](Function &F) -> AssumptionCache & { return ACT->getAssumptionCache(F); }; - auto IC = - llvm::getInlineCost(CB, Callee, LocalParams, TTI, GetAssumptionCache, - None, GetTLI, PSI, RemarksEnabled ? &ORE : nullptr); + auto IC = llvm::getInlineCost(CB, Callee, LocalParams, TTI, + GetAssumptionCache, GetTLI, nullptr, 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 --- a/llvm/lib/Transforms/IPO/AlwaysInliner.cpp +++ b/llvm/lib/Transforms/IPO/AlwaysInliner.cpp @@ -36,11 +36,10 @@ // Add inline assumptions during code generation. FunctionAnalysisManager &FAM = MAM.getResult(M).getManager(); - std::function GetAssumptionCache = - [&](Function &F) -> AssumptionCache & { + auto GetAssumptionCache = [&](Function &F) -> AssumptionCache & { return FAM.getResult(F); }; - InlineFunctionInfo IFI(/*cg=*/nullptr, &GetAssumptionCache); + InlineFunctionInfo IFI(/*cg=*/nullptr, GetAssumptionCache); SmallSetVector Calls; bool Changed = false; diff --git a/llvm/lib/Transforms/IPO/InlineSimple.cpp b/llvm/lib/Transforms/IPO/InlineSimple.cpp --- a/llvm/lib/Transforms/IPO/InlineSimple.cpp +++ b/llvm/lib/Transforms/IPO/InlineSimple.cpp @@ -68,8 +68,8 @@ [&](Function &F) -> AssumptionCache & { return ACT->getAssumptionCache(F); }; - return llvm::getInlineCost(CB, Params, TTI, GetAssumptionCache, - /*GetBFI=*/None, GetTLI, PSI, + return llvm::getInlineCost(CB, Params, TTI, GetAssumptionCache, GetTLI, + /*GetBFI=*/nullptr, PSI, RemarksEnabled ? &ORE : nullptr); } diff --git a/llvm/lib/Transforms/IPO/Inliner.cpp b/llvm/lib/Transforms/IPO/Inliner.cpp --- a/llvm/lib/Transforms/IPO/Inliner.cpp +++ b/llvm/lib/Transforms/IPO/Inliner.cpp @@ -395,7 +395,7 @@ 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,8 +804,7 @@ LLVM_DEBUG(dbgs() << "Inlining calls in: " << F.getName() << "\n"); - std::function GetAssumptionCache = - [&](Function &F) -> AssumptionCache & { + auto GetAssumptionCache = [&](Function &F) -> AssumptionCache & { return FAM.getResult(F); }; @@ -849,7 +848,7 @@ // Setup the data structure used to plumb customization into the // `InlineFunction` routine. InlineFunctionInfo IFI( - /*cg=*/nullptr, &GetAssumptionCache, PSI, + /*cg=*/nullptr, GetAssumptionCache, PSI, &FAM.getResult(*(CB->getCaller())), &FAM.getResult(Callee)); diff --git a/llvm/lib/Transforms/IPO/PartialInlining.cpp b/llvm/lib/Transforms/IPO/PartialInlining.cpp --- a/llvm/lib/Transforms/IPO/PartialInlining.cpp +++ b/llvm/lib/Transforms/IPO/PartialInlining.cpp @@ -198,12 +198,12 @@ struct PartialInlinerImpl { PartialInlinerImpl( - std::function *GetAC, + function_ref GetAC, function_ref LookupAC, - std::function *GTTI, - Optional> GBFI, - std::function *GTLI, - ProfileSummaryInfo *ProfSI) + function_ref GTTI, + function_ref GTLI, + ProfileSummaryInfo &ProfSI, + function_ref GBFI = nullptr) : GetAssumptionCache(GetAC), LookupAssumptionCache(LookupAC), GetTTI(GTTI), GetBFI(GBFI), GetTLI(GTLI), PSI(ProfSI) {} @@ -270,12 +270,12 @@ private: int NumPartialInlining = 0; - std::function *GetAssumptionCache; + function_ref GetAssumptionCache; function_ref LookupAssumptionCache; - std::function *GetTTI; - Optional> GetBFI; - std::function *GetTLI; - ProfileSummaryInfo *PSI; + function_ref GetTTI; + function_ref GetBFI; + function_ref 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,11 +362,10 @@ AssumptionCacheTracker *ACT = &getAnalysis(); TargetTransformInfoWrapperPass *TTIWP = &getAnalysis(); - ProfileSummaryInfo *PSI = - &getAnalysis().getPSI(); + ProfileSummaryInfo &PSI = + getAnalysis().getPSI(); - std::function GetAssumptionCache = - [&ACT](Function &F) -> AssumptionCache & { + auto GetAssumptionCache = [&ACT](Function &F) -> AssumptionCache & { return ACT->getAssumptionCache(F); }; @@ -374,18 +373,16 @@ return ACT->lookupAssumptionCache(F); }; - std::function GetTTI = - [&TTIWP](Function &F) -> TargetTransformInfo & { + auto GetTTI = [&TTIWP](Function &F) -> TargetTransformInfo & { return TTIWP->getTTI(F); }; - std::function GetTLI = - [this](Function &F) -> TargetLibraryInfo & { + auto GetTLI = [this](Function &F) -> TargetLibraryInfo & { return this->getAnalysis().getTLI(F); }; - return PartialInlinerImpl(&GetAssumptionCache, LookupAssumptionCache, - &GetTTI, NoneType::None, &GetTLI, PSI) + return PartialInlinerImpl(GetAssumptionCache, LookupAssumptionCache, GetTTI, + GetTLI, PSI) .run(M); } }; @@ -406,10 +403,10 @@ 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(); std::unique_ptr OutliningInfo = @@ -482,7 +479,7 @@ // 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) { @@ -773,13 +770,13 @@ 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, - GetBFI, *GetTLI, PSI, RemarksEnabled ? &ORE : nullptr); + getInlineCost(CB, getInlineParams(), CalleeTTI, GetAssumptionCache, + GetTLI, GetBFI, &PSI, RemarksEnabled ? &ORE : nullptr); if (IC.isAlways()) { ORE.emit([&]() { @@ -941,7 +938,7 @@ CurrentCallerBFI = TempBFI.get(); } else { // New pass manager: - CurrentCallerBFI = &(*GetBFI)(*Caller); + CurrentCallerBFI = &(GetBFI(*Caller)); } }; @@ -1265,7 +1262,7 @@ if (F->hasFnAttribute(Attribute::NoInline)) return {false, nullptr}; - if (PSI->isFunctionEntryCold(F)) + if (PSI.isFunctionEntryCold(F)) return {false, nullptr}; if (F->users().empty()) @@ -1275,7 +1272,7 @@ // 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 OMRI = computeOutliningColdRegionsInfo(F, ORE); @@ -1284,8 +1281,8 @@ #ifndef NDEBUG if (TracePartialInlining) { - dbgs() << "HotCountThreshold = " << PSI->getHotCountThreshold() << "\n"; - dbgs() << "ColdCountThreshold = " << PSI->getColdCountThreshold() + dbgs() << "HotCountThreshold = " << PSI.getHotCountThreshold() << "\n"; + dbgs() << "ColdCountThreshold = " << PSI.getColdCountThreshold() << "\n"; } #endif @@ -1405,7 +1402,7 @@ 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, @@ -1504,8 +1501,7 @@ ModuleAnalysisManager &AM) { auto &FAM = AM.getResult(M).getManager(); - std::function GetAssumptionCache = - [&FAM](Function &F) -> AssumptionCache & { + auto GetAssumptionCache = [&FAM](Function &F) -> AssumptionCache & { return FAM.getResult(F); }; @@ -1513,25 +1509,22 @@ return FAM.getCachedResult(F); }; - std::function GetBFI = - [&FAM](Function &F) -> BlockFrequencyInfo & { + auto GetBFI = [&FAM](Function &F) -> BlockFrequencyInfo & { return FAM.getResult(F); }; - std::function GetTTI = - [&FAM](Function &F) -> TargetTransformInfo & { + auto GetTTI = [&FAM](Function &F) -> TargetTransformInfo & { return FAM.getResult(F); }; - std::function GetTLI = - [&FAM](Function &F) -> TargetLibraryInfo & { + auto GetTLI = [&FAM](Function &F) -> TargetLibraryInfo & { return FAM.getResult(F); }; - ProfileSummaryInfo *PSI = &AM.getResult(M); + ProfileSummaryInfo &PSI = AM.getResult(M); - if (PartialInlinerImpl(&GetAssumptionCache, LookupAssumptionCache, &GetTTI, - {GetBFI}, &GetTLI, PSI) + if (PartialInlinerImpl(GetAssumptionCache, LookupAssumptionCache, GetTTI, + GetTLI, PSI, GetBFI) .run(M)) return PreservedAnalyses::none(); return PreservedAnalyses::all(); diff --git a/llvm/lib/Transforms/IPO/SampleProfile.cpp b/llvm/lib/Transforms/IPO/SampleProfile.cpp --- a/llvm/lib/Transforms/IPO/SampleProfile.cpp +++ b/llvm/lib/Transforms/IPO/SampleProfile.cpp @@ -906,14 +906,14 @@ // 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, - None, GetTLI, nullptr, nullptr); + InlineCost Cost = + getInlineCost(CB, Params, GetTTI(*CalledFunction), GetAC, GetTLI); 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 @@ return false; InlineCost Cost = getInlineCost(CallInst, getInlineParams(), GetTTI(*Callee), - GetAC, None, GetTLI, nullptr, nullptr); + GetAC, GetTLI); return Cost.getCost() <= SampleColdCallSiteThreshold; } diff --git a/llvm/lib/Transforms/Utils/InlineFunction.cpp b/llvm/lib/Transforms/Utils/InlineFunction.cpp --- a/llvm/lib/Transforms/Utils/InlineFunction.cpp +++ b/llvm/lib/Transforms/Utils/InlineFunction.cpp @@ -1234,7 +1234,7 @@ 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 @@ 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 @@ 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,11 +1904,10 @@ 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(&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 @@ -2496,7 +2495,7 @@ // 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);