Path: blob/main/contrib/llvm-project/llvm/lib/Analysis/InlineAdvisor.cpp
35233 views
//===- InlineAdvisor.cpp - analysis pass implementation -------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// This file implements InlineAdvisorAnalysis and DefaultInlineAdvisor, and9// related types.10//11//===----------------------------------------------------------------------===//1213#include "llvm/Analysis/InlineAdvisor.h"14#include "llvm/ADT/Statistic.h"15#include "llvm/ADT/StringExtras.h"16#include "llvm/Analysis/AssumptionCache.h"17#include "llvm/Analysis/InlineCost.h"18#include "llvm/Analysis/OptimizationRemarkEmitter.h"19#include "llvm/Analysis/ProfileSummaryInfo.h"20#include "llvm/Analysis/ReplayInlineAdvisor.h"21#include "llvm/Analysis/TargetLibraryInfo.h"22#include "llvm/Analysis/TargetTransformInfo.h"23#include "llvm/Analysis/Utils/ImportedFunctionsInliningStatistics.h"24#include "llvm/IR/DebugInfoMetadata.h"25#include "llvm/IR/Module.h"26#include "llvm/IR/PassManager.h"27#include "llvm/Support/CommandLine.h"28#include "llvm/Support/raw_ostream.h"2930using namespace llvm;31#define DEBUG_TYPE "inline"32#ifdef LLVM_HAVE_TF_AOT_INLINERSIZEMODEL33#define LLVM_HAVE_TF_AOT34#endif3536// This weirdly named statistic tracks the number of times that, when attempting37// to inline a function A into B, we analyze the callers of B in order to see38// if those would be more profitable and blocked inline steps.39STATISTIC(NumCallerCallersAnalyzed, "Number of caller-callers analyzed");4041/// Flag to add inline messages as callsite attributes 'inline-remark'.42static cl::opt<bool>43InlineRemarkAttribute("inline-remark-attribute", cl::init(false),44cl::Hidden,45cl::desc("Enable adding inline-remark attribute to"46" callsites processed by inliner but decided"47" to be not inlined"));4849static cl::opt<bool> EnableInlineDeferral("inline-deferral", cl::init(false),50cl::Hidden,51cl::desc("Enable deferred inlining"));5253// An integer used to limit the cost of inline deferral. The default negative54// number tells shouldBeDeferred to only take the secondary cost into account.55static cl::opt<int>56InlineDeferralScale("inline-deferral-scale",57cl::desc("Scale to limit the cost of inline deferral"),58cl::init(2), cl::Hidden);5960static cl::opt<bool>61AnnotateInlinePhase("annotate-inline-phase", cl::Hidden, cl::init(false),62cl::desc("If true, annotate inline advisor remarks "63"with LTO and pass information."));6465namespace llvm {66extern cl::opt<InlinerFunctionImportStatsOpts> InlinerFunctionImportStats;67} // namespace llvm6869namespace {70using namespace llvm::ore;71class MandatoryInlineAdvice : public InlineAdvice {72public:73MandatoryInlineAdvice(InlineAdvisor *Advisor, CallBase &CB,74OptimizationRemarkEmitter &ORE,75bool IsInliningMandatory)76: InlineAdvice(Advisor, CB, ORE, IsInliningMandatory) {}7778private:79void recordInliningWithCalleeDeletedImpl() override { recordInliningImpl(); }8081void recordInliningImpl() override {82if (IsInliningRecommended)83emitInlinedInto(ORE, DLoc, Block, *Callee, *Caller, IsInliningRecommended,84[&](OptimizationRemark &Remark) {85Remark << ": always inline attribute";86});87}8889void recordUnsuccessfulInliningImpl(const InlineResult &Result) override {90if (IsInliningRecommended)91ORE.emit([&]() {92return OptimizationRemarkMissed(Advisor->getAnnotatedInlinePassName(),93"NotInlined", DLoc, Block)94<< "'" << NV("Callee", Callee) << "' is not AlwaysInline into '"95<< NV("Caller", Caller)96<< "': " << NV("Reason", Result.getFailureReason());97});98}99100void recordUnattemptedInliningImpl() override {101assert(!IsInliningRecommended && "Expected to attempt inlining");102}103};104} // namespace105106void DefaultInlineAdvice::recordUnsuccessfulInliningImpl(107const InlineResult &Result) {108using namespace ore;109llvm::setInlineRemark(*OriginalCB, std::string(Result.getFailureReason()) +110"; " + inlineCostStr(*OIC));111ORE.emit([&]() {112return OptimizationRemarkMissed(Advisor->getAnnotatedInlinePassName(),113"NotInlined", DLoc, Block)114<< "'" << NV("Callee", Callee) << "' is not inlined into '"115<< NV("Caller", Caller)116<< "': " << NV("Reason", Result.getFailureReason());117});118}119120void DefaultInlineAdvice::recordInliningWithCalleeDeletedImpl() {121if (EmitRemarks)122emitInlinedIntoBasedOnCost(ORE, DLoc, Block, *Callee, *Caller, *OIC,123/* ForProfileContext= */ false,124Advisor->getAnnotatedInlinePassName());125}126127void DefaultInlineAdvice::recordInliningImpl() {128if (EmitRemarks)129emitInlinedIntoBasedOnCost(ORE, DLoc, Block, *Callee, *Caller, *OIC,130/* ForProfileContext= */ false,131Advisor->getAnnotatedInlinePassName());132}133134std::optional<llvm::InlineCost> static getDefaultInlineAdvice(135CallBase &CB, FunctionAnalysisManager &FAM, const InlineParams &Params) {136Function &Caller = *CB.getCaller();137ProfileSummaryInfo *PSI =138FAM.getResult<ModuleAnalysisManagerFunctionProxy>(Caller)139.getCachedResult<ProfileSummaryAnalysis>(140*CB.getParent()->getParent()->getParent());141142auto &ORE = FAM.getResult<OptimizationRemarkEmitterAnalysis>(Caller);143auto GetAssumptionCache = [&](Function &F) -> AssumptionCache & {144return FAM.getResult<AssumptionAnalysis>(F);145};146auto GetBFI = [&](Function &F) -> BlockFrequencyInfo & {147return FAM.getResult<BlockFrequencyAnalysis>(F);148};149auto GetTLI = [&](Function &F) -> const TargetLibraryInfo & {150return FAM.getResult<TargetLibraryAnalysis>(F);151};152153auto GetInlineCost = [&](CallBase &CB) {154Function &Callee = *CB.getCalledFunction();155auto &CalleeTTI = FAM.getResult<TargetIRAnalysis>(Callee);156bool RemarksEnabled =157Callee.getContext().getDiagHandlerPtr()->isMissedOptRemarkEnabled(158DEBUG_TYPE);159return getInlineCost(CB, Params, CalleeTTI, GetAssumptionCache, GetTLI,160GetBFI, PSI, RemarksEnabled ? &ORE : nullptr);161};162return llvm::shouldInline(163CB, GetInlineCost, ORE,164Params.EnableDeferral.value_or(EnableInlineDeferral));165}166167std::unique_ptr<InlineAdvice>168DefaultInlineAdvisor::getAdviceImpl(CallBase &CB) {169auto OIC = getDefaultInlineAdvice(CB, FAM, Params);170return std::make_unique<DefaultInlineAdvice>(171this, CB, OIC,172FAM.getResult<OptimizationRemarkEmitterAnalysis>(*CB.getCaller()));173}174175InlineAdvice::InlineAdvice(InlineAdvisor *Advisor, CallBase &CB,176OptimizationRemarkEmitter &ORE,177bool IsInliningRecommended)178: Advisor(Advisor), Caller(CB.getCaller()), Callee(CB.getCalledFunction()),179DLoc(CB.getDebugLoc()), Block(CB.getParent()), ORE(ORE),180IsInliningRecommended(IsInliningRecommended) {}181182void InlineAdvice::recordInlineStatsIfNeeded() {183if (Advisor->ImportedFunctionsStats)184Advisor->ImportedFunctionsStats->recordInline(*Caller, *Callee);185}186187void InlineAdvice::recordInlining() {188markRecorded();189recordInlineStatsIfNeeded();190recordInliningImpl();191}192193void InlineAdvice::recordInliningWithCalleeDeleted() {194markRecorded();195recordInlineStatsIfNeeded();196recordInliningWithCalleeDeletedImpl();197}198199AnalysisKey InlineAdvisorAnalysis::Key;200AnalysisKey PluginInlineAdvisorAnalysis::Key;201bool PluginInlineAdvisorAnalysis::HasBeenRegistered = false;202203bool InlineAdvisorAnalysis::Result::tryCreate(204InlineParams Params, InliningAdvisorMode Mode,205const ReplayInlinerSettings &ReplaySettings, InlineContext IC) {206auto &FAM = MAM.getResult<FunctionAnalysisManagerModuleProxy>(M).getManager();207if (PluginInlineAdvisorAnalysis::HasBeenRegistered) {208auto &DA = MAM.getResult<PluginInlineAdvisorAnalysis>(M);209Advisor.reset(DA.Factory(M, FAM, Params, IC));210return !!Advisor;211}212auto GetDefaultAdvice = [&FAM, Params](CallBase &CB) {213auto OIC = getDefaultInlineAdvice(CB, FAM, Params);214return OIC.has_value();215};216switch (Mode) {217case InliningAdvisorMode::Default:218LLVM_DEBUG(dbgs() << "Using default inliner heuristic.\n");219Advisor.reset(new DefaultInlineAdvisor(M, FAM, Params, IC));220// Restrict replay to default advisor, ML advisors are stateful so221// replay will need augmentations to interleave with them correctly.222if (!ReplaySettings.ReplayFile.empty()) {223Advisor = llvm::getReplayInlineAdvisor(M, FAM, M.getContext(),224std::move(Advisor), ReplaySettings,225/* EmitRemarks =*/true, IC);226}227break;228case InliningAdvisorMode::Development:229#ifdef LLVM_HAVE_TFLITE230LLVM_DEBUG(dbgs() << "Using development-mode inliner policy.\n");231Advisor = llvm::getDevelopmentModeAdvisor(M, MAM, GetDefaultAdvice);232#endif233break;234case InliningAdvisorMode::Release:235LLVM_DEBUG(dbgs() << "Using release-mode inliner policy.\n");236Advisor = llvm::getReleaseModeAdvisor(M, MAM, GetDefaultAdvice);237break;238}239240return !!Advisor;241}242243/// Return true if inlining of CB can block the caller from being244/// inlined which is proved to be more beneficial. \p IC is the245/// estimated inline cost associated with callsite \p CB.246/// \p TotalSecondaryCost will be set to the estimated cost of inlining the247/// caller if \p CB is suppressed for inlining.248static bool249shouldBeDeferred(Function *Caller, InlineCost IC, int &TotalSecondaryCost,250function_ref<InlineCost(CallBase &CB)> GetInlineCost) {251// For now we only handle local or inline functions.252if (!Caller->hasLocalLinkage() && !Caller->hasLinkOnceODRLinkage())253return false;254// If the cost of inlining CB is non-positive, it is not going to prevent the255// caller from being inlined into its callers and hence we don't need to256// defer.257if (IC.getCost() <= 0)258return false;259// Try to detect the case where the current inlining candidate caller (call260// it B) is a static or linkonce-ODR function and is an inlining candidate261// elsewhere, and the current candidate callee (call it C) is large enough262// that inlining it into B would make B too big to inline later. In these263// circumstances it may be best not to inline C into B, but to inline B into264// its callers.265//266// This only applies to static and linkonce-ODR functions because those are267// expected to be available for inlining in the translation units where they268// are used. Thus we will always have the opportunity to make local inlining269// decisions. Importantly the linkonce-ODR linkage covers inline functions270// and templates in C++.271//272// FIXME: All of this logic should be sunk into getInlineCost. It relies on273// the internal implementation of the inline cost metrics rather than274// treating them as truly abstract units etc.275TotalSecondaryCost = 0;276// The candidate cost to be imposed upon the current function.277int CandidateCost = IC.getCost() - 1;278// If the caller has local linkage and can be inlined to all its callers, we279// can apply a huge negative bonus to TotalSecondaryCost.280bool ApplyLastCallBonus = Caller->hasLocalLinkage() && !Caller->hasOneUse();281// This bool tracks what happens if we DO inline C into B.282bool InliningPreventsSomeOuterInline = false;283unsigned NumCallerUsers = 0;284for (User *U : Caller->users()) {285CallBase *CS2 = dyn_cast<CallBase>(U);286287// If this isn't a call to Caller (it could be some other sort288// of reference) skip it. Such references will prevent the caller289// from being removed.290if (!CS2 || CS2->getCalledFunction() != Caller) {291ApplyLastCallBonus = false;292continue;293}294295InlineCost IC2 = GetInlineCost(*CS2);296++NumCallerCallersAnalyzed;297if (!IC2) {298ApplyLastCallBonus = false;299continue;300}301if (IC2.isAlways())302continue;303304// See if inlining of the original callsite would erase the cost delta of305// this callsite. We subtract off the penalty for the call instruction,306// which we would be deleting.307if (IC2.getCostDelta() <= CandidateCost) {308InliningPreventsSomeOuterInline = true;309TotalSecondaryCost += IC2.getCost();310NumCallerUsers++;311}312}313314if (!InliningPreventsSomeOuterInline)315return false;316317// If all outer calls to Caller would get inlined, the cost for the last318// one is set very low by getInlineCost, in anticipation that Caller will319// be removed entirely. We did not account for this above unless there320// is only one caller of Caller.321if (ApplyLastCallBonus)322TotalSecondaryCost -= InlineConstants::LastCallToStaticBonus;323324// If InlineDeferralScale is negative, then ignore the cost of primary325// inlining -- IC.getCost() multiplied by the number of callers to Caller.326if (InlineDeferralScale < 0)327return TotalSecondaryCost < IC.getCost();328329int TotalCost = TotalSecondaryCost + IC.getCost() * NumCallerUsers;330int Allowance = IC.getCost() * InlineDeferralScale;331return TotalCost < Allowance;332}333334namespace llvm {335static raw_ostream &operator<<(raw_ostream &R, const ore::NV &Arg) {336return R << Arg.Val;337}338339template <class RemarkT>340RemarkT &operator<<(RemarkT &&R, const InlineCost &IC) {341using namespace ore;342if (IC.isAlways()) {343R << "(cost=always)";344} else if (IC.isNever()) {345R << "(cost=never)";346} else {347R << "(cost=" << ore::NV("Cost", IC.getCost())348<< ", threshold=" << ore::NV("Threshold", IC.getThreshold()) << ")";349}350if (const char *Reason = IC.getReason())351R << ": " << ore::NV("Reason", Reason);352return R;353}354} // namespace llvm355356std::string llvm::inlineCostStr(const InlineCost &IC) {357std::string Buffer;358raw_string_ostream Remark(Buffer);359Remark << IC;360return Remark.str();361}362363void llvm::setInlineRemark(CallBase &CB, StringRef Message) {364if (!InlineRemarkAttribute)365return;366367Attribute Attr = Attribute::get(CB.getContext(), "inline-remark", Message);368CB.addFnAttr(Attr);369}370371/// Return the cost only if the inliner should attempt to inline at the given372/// CallSite. If we return the cost, we will emit an optimisation remark later373/// using that cost, so we won't do so from this function. Return std::nullopt374/// if inlining should not be attempted.375std::optional<InlineCost>376llvm::shouldInline(CallBase &CB,377function_ref<InlineCost(CallBase &CB)> GetInlineCost,378OptimizationRemarkEmitter &ORE, bool EnableDeferral) {379using namespace ore;380381InlineCost IC = GetInlineCost(CB);382Instruction *Call = &CB;383Function *Callee = CB.getCalledFunction();384Function *Caller = CB.getCaller();385386if (IC.isAlways()) {387LLVM_DEBUG(dbgs() << " Inlining " << inlineCostStr(IC)388<< ", Call: " << CB << "\n");389return IC;390}391392if (!IC) {393LLVM_DEBUG(dbgs() << " NOT Inlining " << inlineCostStr(IC)394<< ", Call: " << CB << "\n");395if (IC.isNever()) {396ORE.emit([&]() {397return OptimizationRemarkMissed(DEBUG_TYPE, "NeverInline", Call)398<< "'" << NV("Callee", Callee) << "' not inlined into '"399<< NV("Caller", Caller)400<< "' because it should never be inlined " << IC;401});402} else {403ORE.emit([&]() {404return OptimizationRemarkMissed(DEBUG_TYPE, "TooCostly", Call)405<< "'" << NV("Callee", Callee) << "' not inlined into '"406<< NV("Caller", Caller) << "' because too costly to inline "407<< IC;408});409}410setInlineRemark(CB, inlineCostStr(IC));411return std::nullopt;412}413414int TotalSecondaryCost = 0;415if (EnableDeferral &&416shouldBeDeferred(Caller, IC, TotalSecondaryCost, GetInlineCost)) {417LLVM_DEBUG(dbgs() << " NOT Inlining: " << CB418<< " Cost = " << IC.getCost()419<< ", outer Cost = " << TotalSecondaryCost << '\n');420ORE.emit([&]() {421return OptimizationRemarkMissed(DEBUG_TYPE, "IncreaseCostInOtherContexts",422Call)423<< "Not inlining. Cost of inlining '" << NV("Callee", Callee)424<< "' increases the cost of inlining '" << NV("Caller", Caller)425<< "' in other contexts";426});427setInlineRemark(CB, "deferred");428return std::nullopt;429}430431LLVM_DEBUG(dbgs() << " Inlining " << inlineCostStr(IC) << ", Call: " << CB432<< '\n');433return IC;434}435436std::string llvm::formatCallSiteLocation(DebugLoc DLoc,437const CallSiteFormat &Format) {438std::string Buffer;439raw_string_ostream CallSiteLoc(Buffer);440bool First = true;441for (DILocation *DIL = DLoc.get(); DIL; DIL = DIL->getInlinedAt()) {442if (!First)443CallSiteLoc << " @ ";444// Note that negative line offset is actually possible, but we use445// unsigned int to match line offset representation in remarks so446// it's directly consumable by relay advisor.447uint32_t Offset =448DIL->getLine() - DIL->getScope()->getSubprogram()->getLine();449uint32_t Discriminator = DIL->getBaseDiscriminator();450StringRef Name = DIL->getScope()->getSubprogram()->getLinkageName();451if (Name.empty())452Name = DIL->getScope()->getSubprogram()->getName();453CallSiteLoc << Name.str() << ":" << llvm::utostr(Offset);454if (Format.outputColumn())455CallSiteLoc << ":" << llvm::utostr(DIL->getColumn());456if (Format.outputDiscriminator() && Discriminator)457CallSiteLoc << "." << llvm::utostr(Discriminator);458First = false;459}460461return CallSiteLoc.str();462}463464void llvm::addLocationToRemarks(OptimizationRemark &Remark, DebugLoc DLoc) {465if (!DLoc) {466return;467}468469bool First = true;470Remark << " at callsite ";471for (DILocation *DIL = DLoc.get(); DIL; DIL = DIL->getInlinedAt()) {472if (!First)473Remark << " @ ";474unsigned int Offset = DIL->getLine();475Offset -= DIL->getScope()->getSubprogram()->getLine();476unsigned int Discriminator = DIL->getBaseDiscriminator();477StringRef Name = DIL->getScope()->getSubprogram()->getLinkageName();478if (Name.empty())479Name = DIL->getScope()->getSubprogram()->getName();480Remark << Name << ":" << ore::NV("Line", Offset) << ":"481<< ore::NV("Column", DIL->getColumn());482if (Discriminator)483Remark << "." << ore::NV("Disc", Discriminator);484First = false;485}486487Remark << ";";488}489490void llvm::emitInlinedInto(491OptimizationRemarkEmitter &ORE, DebugLoc DLoc, const BasicBlock *Block,492const Function &Callee, const Function &Caller, bool AlwaysInline,493function_ref<void(OptimizationRemark &)> ExtraContext,494const char *PassName) {495ORE.emit([&]() {496StringRef RemarkName = AlwaysInline ? "AlwaysInline" : "Inlined";497OptimizationRemark Remark(PassName ? PassName : DEBUG_TYPE, RemarkName,498DLoc, Block);499Remark << "'" << ore::NV("Callee", &Callee) << "' inlined into '"500<< ore::NV("Caller", &Caller) << "'";501if (ExtraContext)502ExtraContext(Remark);503addLocationToRemarks(Remark, DLoc);504return Remark;505});506}507508void llvm::emitInlinedIntoBasedOnCost(509OptimizationRemarkEmitter &ORE, DebugLoc DLoc, const BasicBlock *Block,510const Function &Callee, const Function &Caller, const InlineCost &IC,511bool ForProfileContext, const char *PassName) {512llvm::emitInlinedInto(513ORE, DLoc, Block, Callee, Caller, IC.isAlways(),514[&](OptimizationRemark &Remark) {515if (ForProfileContext)516Remark << " to match profiling context";517Remark << " with " << IC;518},519PassName);520}521522InlineAdvisor::InlineAdvisor(Module &M, FunctionAnalysisManager &FAM,523std::optional<InlineContext> IC)524: M(M), FAM(FAM), IC(IC),525AnnotatedInlinePassName((IC && AnnotateInlinePhase)526? llvm::AnnotateInlinePassName(*IC)527: DEBUG_TYPE) {528if (InlinerFunctionImportStats != InlinerFunctionImportStatsOpts::No) {529ImportedFunctionsStats =530std::make_unique<ImportedFunctionsInliningStatistics>();531ImportedFunctionsStats->setModuleInfo(M);532}533}534535InlineAdvisor::~InlineAdvisor() {536if (ImportedFunctionsStats) {537assert(InlinerFunctionImportStats != InlinerFunctionImportStatsOpts::No);538ImportedFunctionsStats->dump(InlinerFunctionImportStats ==539InlinerFunctionImportStatsOpts::Verbose);540}541}542543std::unique_ptr<InlineAdvice> InlineAdvisor::getMandatoryAdvice(CallBase &CB,544bool Advice) {545return std::make_unique<MandatoryInlineAdvice>(this, CB, getCallerORE(CB),546Advice);547}548549static inline const char *getLTOPhase(ThinOrFullLTOPhase LTOPhase) {550switch (LTOPhase) {551case (ThinOrFullLTOPhase::None):552return "main";553case (ThinOrFullLTOPhase::ThinLTOPreLink):554case (ThinOrFullLTOPhase::FullLTOPreLink):555return "prelink";556case (ThinOrFullLTOPhase::ThinLTOPostLink):557case (ThinOrFullLTOPhase::FullLTOPostLink):558return "postlink";559}560llvm_unreachable("unreachable");561}562563static inline const char *getInlineAdvisorContext(InlinePass IP) {564switch (IP) {565case (InlinePass::AlwaysInliner):566return "always-inline";567case (InlinePass::CGSCCInliner):568return "cgscc-inline";569case (InlinePass::EarlyInliner):570return "early-inline";571case (InlinePass::MLInliner):572return "ml-inline";573case (InlinePass::ModuleInliner):574return "module-inline";575case (InlinePass::ReplayCGSCCInliner):576return "replay-cgscc-inline";577case (InlinePass::ReplaySampleProfileInliner):578return "replay-sample-profile-inline";579case (InlinePass::SampleProfileInliner):580return "sample-profile-inline";581}582583llvm_unreachable("unreachable");584}585586std::string llvm::AnnotateInlinePassName(InlineContext IC) {587return std::string(getLTOPhase(IC.LTOPhase)) + "-" +588std::string(getInlineAdvisorContext(IC.Pass));589}590591InlineAdvisor::MandatoryInliningKind592InlineAdvisor::getMandatoryKind(CallBase &CB, FunctionAnalysisManager &FAM,593OptimizationRemarkEmitter &ORE) {594auto &Callee = *CB.getCalledFunction();595596auto GetTLI = [&](Function &F) -> const TargetLibraryInfo & {597return FAM.getResult<TargetLibraryAnalysis>(F);598};599600auto &TIR = FAM.getResult<TargetIRAnalysis>(Callee);601602auto TrivialDecision =603llvm::getAttributeBasedInliningDecision(CB, &Callee, TIR, GetTLI);604605if (TrivialDecision) {606if (TrivialDecision->isSuccess())607return MandatoryInliningKind::Always;608else609return MandatoryInliningKind::Never;610}611return MandatoryInliningKind::NotMandatory;612}613614std::unique_ptr<InlineAdvice> InlineAdvisor::getAdvice(CallBase &CB,615bool MandatoryOnly) {616if (!MandatoryOnly)617return getAdviceImpl(CB);618bool Advice = CB.getCaller() != CB.getCalledFunction() &&619MandatoryInliningKind::Always ==620getMandatoryKind(CB, FAM, getCallerORE(CB));621return getMandatoryAdvice(CB, Advice);622}623624OptimizationRemarkEmitter &InlineAdvisor::getCallerORE(CallBase &CB) {625return FAM.getResult<OptimizationRemarkEmitterAnalysis>(*CB.getCaller());626}627628PreservedAnalyses629InlineAdvisorAnalysisPrinterPass::run(Module &M, ModuleAnalysisManager &MAM) {630const auto *IA = MAM.getCachedResult<InlineAdvisorAnalysis>(M);631if (!IA)632OS << "No Inline Advisor\n";633else634IA->getAdvisor()->print(OS);635return PreservedAnalyses::all();636}637638PreservedAnalyses InlineAdvisorAnalysisPrinterPass::run(639LazyCallGraph::SCC &InitialC, CGSCCAnalysisManager &AM, LazyCallGraph &CG,640CGSCCUpdateResult &UR) {641const auto &MAMProxy =642AM.getResult<ModuleAnalysisManagerCGSCCProxy>(InitialC, CG);643644if (InitialC.size() == 0) {645OS << "SCC is empty!\n";646return PreservedAnalyses::all();647}648Module &M = *InitialC.begin()->getFunction().getParent();649const auto *IA = MAMProxy.getCachedResult<InlineAdvisorAnalysis>(M);650if (!IA)651OS << "No Inline Advisor\n";652else653IA->getAdvisor()->print(OS);654return PreservedAnalyses::all();655}656657658