Go to the documentation of this file.
9 #ifndef LLVM_ANALYSIS_INLINEADVISOR_H
10 #define LLVM_ANALYSIS_INLINEADVISOR_H
15 #include "llvm/Config/llvm-config.h"
24 class OptimizationRemark;
25 class ImportedFunctionsInliningStatistics;
26 class OptimizationRemarkEmitter;
27 struct ReplayInlinerSettings;
84 assert(Recorded &&
"InlineAdvice should have been informed of the "
85 "inliner's decision in all cases");
136 void markRecorded() {
137 assert(!Recorded &&
"Recording should happen exactly once");
140 void recordInlineStatsIfNeeded();
142 bool Recorded =
false;
148 std::optional<InlineCost> OIC,
151 OIC(OIC), EmitRemarks(EmitRemarks) {}
154 void recordUnsuccessfulInliningImpl(
const InlineResult &Result)
override;
155 void recordInliningWithCalleeDeletedImpl()
override;
156 void recordInliningImpl()
override;
160 std::optional<InlineCost> OIC;
181 bool MandatoryOnly =
false);
195 OS <<
"Unimplemented InlineAdvisor print\n";
205 std::optional<InlineContext>
IC = std::nullopt);
212 const std::optional<InlineContext>
IC;
238 std::unique_ptr<InlineAdvice> getAdviceImpl(
CallBase &CB)
override;
301 assert(Factory !=
nullptr &&
302 "The plugin advisor factory should not be a null pointer.");
329 return !PAC.preservedWhenStateless();
339 std::unique_ptr<InlineAdvisor> Advisor;
359 std::unique_ptr<InlineAdvisor>
362 std::unique_ptr<InlineAdvisor>
373 std::optional<InlineCost>
374 shouldInline(CallBase &CB, function_ref<InlineCost(CallBase &CB)> GetInlineCost,
375 OptimizationRemarkEmitter &ORE,
bool EnableDeferral =
true);
379 const BasicBlock *Block,
const Function &Callee,
380 const Function &Caller,
bool IsMandatory,
381 function_ref<
void(OptimizationRemark &)> ExtraContext = {},
386 const BasicBlock *Block,
const Function &Callee,
387 const Function &Caller,
const InlineCost &IC,
388 bool ForProfileContext =
false,
400 #endif // LLVM_ANALYSIS_INLINEADVISOR_H
virtual void print(raw_ostream &OS) const
Support for printer pass.
A set of analyses that are preserved following a run of a transformation pass.
virtual void onPassEntry(LazyCallGraph::SCC *SCC=nullptr)
This must be called when the Inliner pass is entered, to allow the InlineAdvisor update internal stat...
void recordInlining()
Exactly one of the record* APIs must be called.
InlineAdvisor * getAdvisor() const
This is an optimization pass for GlobalISel generic memory operations.
std::unique_ptr< InlineAdvisor > getReleaseModeAdvisor(Module &M, ModuleAnalysisManager &MAM)
We currently emits eax Perhaps this is what we really should generate is Is imull three or four cycles eax eax The current instruction priority is based on pattern complexity The former is more complex because it folds a load so the latter will not be emitted Perhaps we should use AddedComplexity to give LEA32r a higher priority We should always try to match LEA first since the LEA matching code does some estimate to determine whether the match is profitable if we care more about code then imull is better It s two bytes shorter than movl leal On a Pentium M
std::unique_ptr< ImportedFunctionsInliningStatistics > ImportedFunctionsStats
Used for dynamically registering InlineAdvisors as plugins.
A CRTP mix-in to automatically provide informational APIs needed for passes.
InlineAdvisor *(* AdvisorFactory)(Module &M, FunctionAnalysisManager &FAM, InlineParams Params, InlineContext IC)
Result run(Module &M, ModuleAnalysisManager &MAM)
std::optional< InlineCost > shouldInline(CallBase &CB, 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.
PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM)
Function *const Caller
Caller and Callee are pre-inlining.
DefaultInlineAdvice(InlineAdvisor *Advisor, CallBase &CB, std::optional< InlineCost > OIC, OptimizationRemarkEmitter &ORE, bool EmitRemarks=true)
FunctionAnalysisManager FAM
const std::optional< InlineContext > IC
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).
InlineAdvisorAnalysisPrinterPass(raw_ostream &OS)
AnalysisManager< Module > ModuleAnalysisManager
Convenience typedef for the Module analysis manager.
Thresholds to tune inline cost analysis.
void addLocationToRemarks(OptimizationRemark &Remark, DebugLoc DLoc)
Add location info to ORE message.
Result run(Module &M, ModuleAnalysisManager &MAM)
OptimizationRemarkEmitter & getCallerORE(CallBase &CB)
LLVM Basic Block Representation.
Printer pass for the FunctionPropertiesAnalysis results.
ThinOrFullLTOPhase
This enumerates the LLVM full LTO or ThinLTO optimization phases.
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.
const bool IsInliningRecommended
An SCC of the call graph.
virtual void onPassExit(LazyCallGraph::SCC *SCC=nullptr)
This must be called when the Inliner pass is exited, as function passes may be run subsequently.
OptimizationRemarkEmitter & ORE
The default (manual heuristics) implementation of the InlineAdvisor.
Clang compiles this i1 i64 store i64 i64 store i64 i64 store i64 i64 store i64 align Which gets codegen d xmm0 movaps rbp movaps rbp movaps rbp movaps rbp rbp rbp rbp rbp It would be better to have movq s of instead of the movaps s LLVM produces ret int
ModuleAnalysisManager MAM
This class implements an extremely fast bulk output stream that can only output to a stream.
const BasicBlock * getOriginalCallSiteBasicBlock() const
API to communicate dependencies between analyses during invalidation.
Provides context on when an inline advisor is constructed in the pipeline (e.g., link phase,...
Capture state between an inlining decision having had been made, and its impact being observable.
InliningAdvisorMode
There are 4 scenarios we can use the InlineAdvisor:
const char * getAnnotatedInlinePassName() const
NOTE pass name is annotated only when inline advisor constructor provides InlineContext.
InlineAdvisor(InlineAdvisor &&)=delete
void recordUnattemptedInlining()
Call to indicate inlining was not attempted.
void recordInliningWithCalleeDeleted()
Call after inlining succeeded, and results in the callee being delete-able, meaning,...
A special type used by analysis passes to provide an address that identifies that particular analysis...
const BasicBlock *const Block
virtual void recordInliningImpl()
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
void setInlineRemark(CallBase &CB, StringRef Message)
Set the inline-remark attribute.
@ BasicBlock
Various leaf nodes.
print Print MemDeps of function
A Module instance is used to store all the information related to an LLVM module.
A CRTP mix-in that provides informational APIs needed for analysis passes.
virtual void recordUnsuccessfulInliningImpl(const InlineResult &Result)
bool isInliningRecommended() const
Get the inlining recommendation.
bool tryCreate(InlineParams Params, InliningAdvisorMode Mode, const ReplayInlinerSettings &ReplaySettings, InlineContext IC)
Result(Module &M, ModuleAnalysisManager &MAM)
DefaultInlineAdvisor(Module &M, FunctionAnalysisManager &FAM, InlineParams Params, InlineContext IC)
Interface for deciding whether to inline a call site or not.
static bool HasBeenRegistered
InlineAdvisorAnalysis()=default
virtual void recordUnattemptedInliningImpl()
Machine Check Debug Module
virtual void recordInliningWithCalleeDeletedImpl()
@ ReplaySampleProfileInliner
virtual std::unique_ptr< InlineAdvice > getMandatoryAdvice(CallBase &CB, bool Advice)
Support structure for SCC passes to communicate updates the call graph back to the CGSCC pass manager...
PluginInlineAdvisorAnalysis(AdvisorFactory Factory)
FunctionAnalysisManager & FAM
std::unique_ptr< InlineAdvice > getAdvice(CallBase &CB, bool MandatoryOnly=false)
Get an InlineAdvice containing a recommendation on whether to inline or not.
virtual std::unique_ptr< InlineAdvice > getAdviceImpl(CallBase &CB)=0
std::string inlineCostStr(const InlineCost &IC)
Utility for extracting the inline cost message to a string.
static MandatoryInliningKind getMandatoryKind(CallBase &CB, FunctionAnalysisManager &FAM, OptimizationRemarkEmitter &ORE)
std::string AnnotateInlinePassName(InlineContext IC)
The InlineAdvisorAnalysis is a module pass because the InlineAdvisor needs to capture state right bef...
std::unique_ptr< InlineAdvisor > getDevelopmentModeAdvisor(Module &M, ModuleAnalysisManager &MAM, std::function< bool(CallBase &)> GetDefaultAdvice)
InlineAdvice(InlineAdvisor *Advisor, CallBase &CB, OptimizationRemarkEmitter &ORE, bool IsInliningRecommended)
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
const std::string AnnotatedInlinePassName
PreservedAnalysisChecker getChecker() const
Build a checker for this PreservedAnalyses and the specified analysis type.
A container for analyses that lazily runs them and caches their results.
A lazily constructed view of the call graph of a module.
const DebugLoc & getOriginalCallSiteDebugLoc() const
InlineAdvisor *const Advisor
InlineResult is basically true or false.
void recordUnsuccessfulInlining(const InlineResult &Result)
Call after the decision for a call site was to not inline.
static const char PassName[]
bool invalidate(Module &, const PreservedAnalyses &PA, ModuleAnalysisManager::Invalidator &)
ThinOrFullLTOPhase LTOPhase