9#ifndef LLVM_ANALYSIS_INLINEADVISOR_H
10#define LLVM_ANALYSIS_INLINEADVISOR_H
23class OptimizationRemark;
24class ImportedFunctionsInliningStatistics;
25class OptimizationRemarkEmitter;
26struct ReplayInlinerSettings;
82 assert(Recorded &&
"InlineAdvice should have been informed of the "
83 "inliner's decision in all cases");
134 void markRecorded() {
135 assert(!Recorded &&
"Recording should happen exactly once");
138 void recordInlineStatsIfNeeded();
140 bool Recorded =
false;
146 std::optional<InlineCost> OIC,
149 OIC(OIC), EmitRemarks(EmitRemarks) {}
152 void recordUnsuccessfulInliningImpl(
const InlineResult &Result)
override;
153 void recordInliningWithCalleeDeletedImpl()
override;
154 void recordInliningImpl()
override;
158 std::optional<InlineCost> OIC;
179 bool MandatoryOnly =
false);
193 OS <<
"Unimplemented InlineAdvisor print\n";
203 std::optional<InlineContext>
IC = std::nullopt);
210 const std::optional<InlineContext>
IC;
236 std::unique_ptr<InlineAdvice> getAdviceImpl(
CallBase &CB)
override;
290 assert(Factory !=
nullptr &&
291 "The plugin advisor factory should not be a null pointer.");
318 return !PAC.preservedWhenStateless();
328 std::unique_ptr<InlineAdvisor> Advisor;
349std::unique_ptr<InlineAdvisor>
351 std::function<
bool(CallBase &)> GetDefaultAdvice);
353std::unique_ptr<InlineAdvisor>
355 std::function<
bool(
CallBase &)> GetDefaultAdvice);
364std::optional<InlineCost>
372 const Function &Caller,
bool IsMandatory,
378 const BasicBlock *
Block,
const Function &Callee,
379 const Function &Caller,
const InlineCost &IC,
380 bool ForProfileContext =
false,
This header provides classes for managing passes over SCCs of the call graph.
This header defines various interfaces for pass management in LLVM.
Implements a lazy call graph analysis and related passes for the new pass manager.
Machine Check Debug Module
FunctionAnalysisManager FAM
ModuleAnalysisManager MAM
static cl::opt< RegAllocEvictionAdvisorAnalysis::AdvisorMode > Mode("regalloc-enable-advisor", cl::Hidden, cl::init(RegAllocEvictionAdvisorAnalysis::AdvisorMode::Default), cl::desc("Enable regalloc advisor mode"), cl::values(clEnumValN(RegAllocEvictionAdvisorAnalysis::AdvisorMode::Default, "default", "Default"), clEnumValN(RegAllocEvictionAdvisorAnalysis::AdvisorMode::Release, "release", "precompiled"), clEnumValN(RegAllocEvictionAdvisorAnalysis::AdvisorMode::Development, "development", "for training")))
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static const char PassName[]
API to communicate dependencies between analyses during invalidation.
A container for analyses that lazily runs them and caches their results.
LLVM Basic Block Representation.
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
DefaultInlineAdvice(InlineAdvisor *Advisor, CallBase &CB, std::optional< InlineCost > OIC, OptimizationRemarkEmitter &ORE, bool EmitRemarks=true)
The default (manual heuristics) implementation of the InlineAdvisor.
DefaultInlineAdvisor(Module &M, FunctionAnalysisManager &FAM, InlineParams Params, InlineContext IC)
Capture state between an inlining decision having had been made, and its impact being observable.
Function *const Caller
Caller and Callee are pre-inlining.
InlineAdvice(InlineAdvice &&)=delete
void recordUnsuccessfulInlining(const InlineResult &Result)
Call after the decision for a call site was to not inline.
InlineAdvice(const InlineAdvice &)=delete
virtual void recordInliningWithCalleeDeletedImpl()
void recordUnattemptedInlining()
Call to indicate inlining was not attempted.
const DebugLoc & getOriginalCallSiteDebugLoc() const
virtual void recordInliningImpl()
const BasicBlock *const Block
const BasicBlock * getOriginalCallSiteBasicBlock() const
void recordInlining()
Exactly one of the record* APIs must be called.
OptimizationRemarkEmitter & ORE
virtual void recordUnsuccessfulInliningImpl(const InlineResult &Result)
InlineAdvisor *const Advisor
virtual void recordUnattemptedInliningImpl()
void recordInliningWithCalleeDeleted()
Call after inlining succeeded, and results in the callee being delete-able, meaning,...
bool isInliningRecommended() const
Get the inlining recommendation.
const bool IsInliningRecommended
Printer pass for the InlineAdvisorAnalysis results.
PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM)
InlineAdvisorAnalysisPrinterPass(raw_ostream &OS)
The InlineAdvisorAnalysis is a module pass because the InlineAdvisor needs to capture state right bef...
Result run(Module &M, ModuleAnalysisManager &MAM)
InlineAdvisorAnalysis()=default
Interface for deciding whether to inline a call site or not.
const std::optional< InlineContext > IC
OptimizationRemarkEmitter & getCallerORE(CallBase &CB)
FunctionAnalysisManager & FAM
static MandatoryInliningKind getMandatoryKind(CallBase &CB, FunctionAnalysisManager &FAM, OptimizationRemarkEmitter &ORE)
virtual void print(raw_ostream &OS) const
Support for printer pass.
const std::string AnnotatedInlinePassName
virtual std::unique_ptr< InlineAdvice > getMandatoryAdvice(CallBase &CB, bool Advice)
std::unique_ptr< ImportedFunctionsInliningStatistics > ImportedFunctionsStats
virtual void onPassEntry(LazyCallGraph::SCC *SCC=nullptr)
This must be called when the Inliner pass is entered, to allow the InlineAdvisor update internal stat...
const char * getAnnotatedInlinePassName() const
NOTE pass name is annotated only when inline advisor constructor provides InlineContext.
virtual void onPassExit(LazyCallGraph::SCC *SCC=nullptr)
This must be called when the Inliner pass is exited, as function passes may be run subsequently.
InlineAdvisor(InlineAdvisor &&)=delete
virtual std::unique_ptr< InlineAdvice > getAdviceImpl(CallBase &CB)=0
std::unique_ptr< InlineAdvice > getAdvice(CallBase &CB, bool MandatoryOnly=false)
Get an InlineAdvice containing a recommendation on whether to inline or not.
Represents the cost of inlining a function.
InlineResult is basically true or false.
An SCC of the call graph.
A lazily constructed view of the call graph of a module.
A Module instance is used to store all the information related to an LLVM module.
Used for dynamically registering InlineAdvisors as plugins.
PluginInlineAdvisorAnalysis(AdvisorFactory Factory)
InlineAdvisor *(* AdvisorFactory)(Module &M, FunctionAnalysisManager &FAM, InlineParams Params, InlineContext IC)
Result run(Module &M, ModuleAnalysisManager &MAM)
A set of analyses that are preserved following a run of a transformation pass.
PreservedAnalysisChecker getChecker() const
Build a checker for this PreservedAnalyses and the specified analysis type.
An efficient, type-erasing, non-owning reference to a callable.
This class implements an extremely fast bulk output stream that can only output to a stream.
@ BasicBlock
Various leaf nodes.
This is an optimization pass for GlobalISel generic memory operations.
@ ReplaySampleProfileInliner
void emitInlinedInto(OptimizationRemarkEmitter &ORE, DebugLoc DLoc, const BasicBlock *Block, const Function &Callee, const Function &Caller, bool IsMandatory, function_ref< void(OptimizationRemark &)> ExtraContext={}, const char *PassName=nullptr)
Emit ORE message.
std::string inlineCostStr(const InlineCost &IC)
Utility for extracting the inline cost message to a string.
InliningAdvisorMode
There are 4 scenarios we can use the InlineAdvisor:
std::optional< InlineCost > shouldInline(CallBase &CB, TargetTransformInfo &CalleeTTI, function_ref< InlineCost(CallBase &CB)> GetInlineCost, OptimizationRemarkEmitter &ORE, bool EnableDeferral=true)
Return the cost only if the inliner should attempt to inline at the given CallSite.
std::unique_ptr< InlineAdvisor > getReleaseModeAdvisor(Module &M, ModuleAnalysisManager &MAM, std::function< bool(CallBase &)> GetDefaultAdvice)
void setInlineRemark(CallBase &CB, StringRef Message)
Set the inline-remark attribute.
std::string AnnotateInlinePassName(InlineContext IC)
ThinOrFullLTOPhase
This enumerates the LLVM full LTO or ThinLTO optimization phases.
void emitInlinedIntoBasedOnCost(OptimizationRemarkEmitter &ORE, DebugLoc DLoc, const BasicBlock *Block, const Function &Callee, const Function &Caller, const InlineCost &IC, bool ForProfileContext=false, const char *PassName=nullptr)
Emit ORE message based in cost (default heuristic).
std::unique_ptr< InlineAdvisor > getDevelopmentModeAdvisor(Module &M, ModuleAnalysisManager &MAM, std::function< bool(CallBase &)> GetDefaultAdvice)
void addLocationToRemarks(OptimizationRemark &Remark, DebugLoc DLoc)
Add location info to ORE message.
@ Default
The result values are uniform if and only if all operands are uniform.
AnalysisManager< Module > ModuleAnalysisManager
Convenience typedef for the Module analysis manager.
A CRTP mix-in that provides informational APIs needed for analysis passes.
A special type used by analysis passes to provide an address that identifies that particular analysis...
Support structure for SCC passes to communicate updates the call graph back to the CGSCC pass manager...
bool tryCreate(InlineParams Params, InliningAdvisorMode Mode, const ReplayInlinerSettings &ReplaySettings, InlineContext IC)
InlineAdvisor * getAdvisor() const
Result(Module &M, ModuleAnalysisManager &MAM)
bool invalidate(Module &, const PreservedAnalyses &PA, ModuleAnalysisManager::Invalidator &)
Provides context on when an inline advisor is constructed in the pipeline (e.g., link phase,...
ThinOrFullLTOPhase LTOPhase
Thresholds to tune inline cost analysis.
A CRTP mix-in to automatically provide informational APIs needed for passes.