#include "llvm/Analysis/InlineAdvisor.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/Analysis/AssumptionCache.h"
#include "llvm/Analysis/InlineCost.h"
#include "llvm/Analysis/OptimizationRemarkEmitter.h"
#include "llvm/Analysis/ProfileSummaryInfo.h"
#include "llvm/Analysis/ReplayInlineAdvisor.h"
#include "llvm/Analysis/TargetLibraryInfo.h"
#include "llvm/Analysis/TargetTransformInfo.h"
#include "llvm/Analysis/Utils/ImportedFunctionsInliningStatistics.h"
#include "llvm/IR/DebugInfoMetadata.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/PassManager.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/raw_ostream.h"
usingnamespacellvm;
#define DEBUG_TYPE …
#ifdef LLVM_HAVE_TF_AOT_INLINERSIZEMODEL
#define LLVM_HAVE_TF_AOT
#endif
STATISTIC(NumCallerCallersAnalyzed, "Number of caller-callers analyzed");
static cl::opt<bool>
InlineRemarkAttribute("inline-remark-attribute", cl::init(false),
cl::Hidden,
cl::desc("Enable adding inline-remark attribute to"
" callsites processed by inliner but decided"
" to be not inlined"));
static cl::opt<bool> EnableInlineDeferral("inline-deferral", cl::init(false),
cl::Hidden,
cl::desc("Enable deferred inlining"));
static cl::opt<int>
InlineDeferralScale("inline-deferral-scale",
cl::desc("Scale to limit the cost of inline deferral"),
cl::init(2), cl::Hidden);
static cl::opt<bool>
AnnotateInlinePhase("annotate-inline-phase", cl::Hidden, cl::init(false),
cl::desc("If true, annotate inline advisor remarks "
"with LTO and pass information."));
namespace llvm {
extern cl::opt<InlinerFunctionImportStatsOpts> InlinerFunctionImportStats;
}
namespace {
usingnamespacellvm::ore;
class MandatoryInlineAdvice : public InlineAdvice { … };
}
void DefaultInlineAdvice::recordUnsuccessfulInliningImpl(
const InlineResult &Result) { … }
void DefaultInlineAdvice::recordInliningWithCalleeDeletedImpl() { … }
void DefaultInlineAdvice::recordInliningImpl() { … }
std::optional<llvm::InlineCost> static getDefaultInlineAdvice(
CallBase &CB, FunctionAnalysisManager &FAM, const InlineParams &Params) { … }
std::unique_ptr<InlineAdvice>
DefaultInlineAdvisor::getAdviceImpl(CallBase &CB) { … }
InlineAdvice::InlineAdvice(InlineAdvisor *Advisor, CallBase &CB,
OptimizationRemarkEmitter &ORE,
bool IsInliningRecommended)
: … { … }
void InlineAdvice::recordInlineStatsIfNeeded() { … }
void InlineAdvice::recordInlining() { … }
void InlineAdvice::recordInliningWithCalleeDeleted() { … }
AnalysisKey InlineAdvisorAnalysis::Key;
AnalysisKey PluginInlineAdvisorAnalysis::Key;
bool PluginInlineAdvisorAnalysis::HasBeenRegistered = …;
bool InlineAdvisorAnalysis::Result::tryCreate(
InlineParams Params, InliningAdvisorMode Mode,
const ReplayInlinerSettings &ReplaySettings, InlineContext IC) { … }
static bool
shouldBeDeferred(Function *Caller, TargetTransformInfo &CalleeTTI,
InlineCost IC, int &TotalSecondaryCost,
function_ref<InlineCost(CallBase &CB)> GetInlineCost) { … }
namespace llvm {
static raw_ostream &operator<<(raw_ostream &R, const ore::NV &Arg) { … }
template <class RemarkT>
RemarkT &operator<<(RemarkT &&R, const InlineCost &IC) { … }
}
std::string llvm::inlineCostStr(const InlineCost &IC) { … }
void llvm::setInlineRemark(CallBase &CB, StringRef Message) { … }
std::optional<InlineCost>
llvm::shouldInline(CallBase &CB, TargetTransformInfo &CalleeTTI,
function_ref<InlineCost(CallBase &CB)> GetInlineCost,
OptimizationRemarkEmitter &ORE, bool EnableDeferral) { … }
std::string llvm::formatCallSiteLocation(DebugLoc DLoc,
const CallSiteFormat &Format) { … }
void llvm::addLocationToRemarks(OptimizationRemark &Remark, DebugLoc DLoc) { … }
void llvm::emitInlinedInto(
OptimizationRemarkEmitter &ORE, DebugLoc DLoc, const BasicBlock *Block,
const Function &Callee, const Function &Caller, bool AlwaysInline,
function_ref<void(OptimizationRemark &)> ExtraContext,
const char *PassName) { … }
void llvm::emitInlinedIntoBasedOnCost(
OptimizationRemarkEmitter &ORE, DebugLoc DLoc, const BasicBlock *Block,
const Function &Callee, const Function &Caller, const InlineCost &IC,
bool ForProfileContext, const char *PassName) { … }
InlineAdvisor::InlineAdvisor(Module &M, FunctionAnalysisManager &FAM,
std::optional<InlineContext> IC)
: … { … }
InlineAdvisor::~InlineAdvisor() { … }
std::unique_ptr<InlineAdvice> InlineAdvisor::getMandatoryAdvice(CallBase &CB,
bool Advice) { … }
static inline const char *getLTOPhase(ThinOrFullLTOPhase LTOPhase) { … }
static inline const char *getInlineAdvisorContext(InlinePass IP) { … }
std::string llvm::AnnotateInlinePassName(InlineContext IC) { … }
InlineAdvisor::MandatoryInliningKind
InlineAdvisor::getMandatoryKind(CallBase &CB, FunctionAnalysisManager &FAM,
OptimizationRemarkEmitter &ORE) { … }
std::unique_ptr<InlineAdvice> InlineAdvisor::getAdvice(CallBase &CB,
bool MandatoryOnly) { … }
OptimizationRemarkEmitter &InlineAdvisor::getCallerORE(CallBase &CB) { … }
PreservedAnalyses
InlineAdvisorAnalysisPrinterPass::run(Module &M, ModuleAnalysisManager &MAM) { … }
PreservedAnalyses InlineAdvisorAnalysisPrinterPass::run(
LazyCallGraph::SCC &InitialC, CGSCCAnalysisManager &AM, LazyCallGraph &CG,
CGSCCUpdateResult &UR) { … }