47#define DEBUG_TYPE "module-inline"
49STATISTIC(NumInlined,
"Number of functions inlined");
50STATISTIC(NumDeleted,
"Number of functions deleted because all callers found");
54 cl::desc(
"If using a contextual profile in this module, and an indirect "
55 "call target is marked as alwaysinline, perform indirect call "
56 "promotion for that target. If multiple targets for an indirect "
57 "call site fit this description, they are all promoted."));
75 OwnedAdvisor = std::make_unique<DefaultInlineAdvisor>(
80 assert(IAA->getAdvisor() &&
81 "Expected a present InlineAdvisorAnalysis also have an "
82 "InlineAdvisor initialized");
83 return *IAA->getAdvisor();
99 if (!IAA.tryCreate(Params, Mode, {},
101 M.getContext().emitError(
102 "Could not setup Inlining Advisor for the requested "
103 "mode and/or options");
135 assert(Calls !=
nullptr &&
"Expected an initialized InlineOrder");
140 if (
F.isDeclaration())
145 if (
Function *Callee = CB->getCalledFunction()) {
146 if (!Callee->isDeclaration())
153 << NV(
"Callee", Callee) <<
" will not be inlined into "
154 << NV(
"Caller", CB->getCaller())
155 <<
" because its definition is unavailable"
160 CtxProf.isInSpecializedModule() && CB->isIndirectCall()) {
167 for (
auto &[CB,
Target] : ICPCandidates) {
169 Calls->push(DirectCB);
179 while (!Calls->empty()) {
185 <<
" Function size: " <<
F.getInstructionCount()
193 auto Advice = Advisor.
getAdvice(*CB,
false);
195 if (!Advice->isInliningRecommended()) {
196 Advice->recordUnattemptedInlining();
203 GetAssumptionCache, PSI,
212 if (!
IR.isSuccess()) {
213 Advice->recordUnsuccessfulInlining(
IR);
220 LLVM_DEBUG(
dbgs() <<
" Size after inlining: " <<
F.getInstructionCount()
226 Function *NewCallee = ICB->getCalledFunction();
233 if (CtxProf.isInSpecializedModule())
235 NewCallee = ICB->getCalledFunction();
247 bool CalleeWasDeleted =
false;
248 if (Callee.hasLocalLinkage()) {
251 Callee.removeDeadConstantUsers();
259 Advice->recordInliningWithCalleeDeleted();
264 Callee.dropAllReferences();
266 "Cannot put cause a function to become dead twice!");
268 CalleeWasDeleted =
true;
271 if (!CalleeWasDeleted)
272 Advice->recordInlining();
281 for (
Function *DeadF : DeadFunctions) {
283 FAM.clear(*DeadF, DeadF->getName());
286 M.getFunctionList().erase(DeadF);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
Expand Atomic instructions
Module.h This file contains the declarations for the Module class.
This header defines various interfaces for pass management in LLVM.
static bool isKnownLibFunction(Function &F, TargetLibraryInfo &TLI)
Legalize the Machine IR a function s Machine IR
static cl::opt< bool > CtxProfPromoteAlwaysInline("ctx-prof-promote-alwaysinline", cl::init(false), cl::Hidden, cl::desc("If using a contextual profile in this module, and an indirect " "call target is marked as alwaysinline, perform indirect call " "promotion for that target. If multiple targets for an indirect " "call site fit this description, they are all promoted."))
FunctionAnalysisManager FAM
ModuleAnalysisManager MAM
This file defines the scope_exit class, which executes user-defined cleanup logic at scope exit.
This file defines the SmallVector class.
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
A manager for alias analyses.
A function analysis which provides an AssumptionCache.
A cache of @llvm.assume calls within a function.
Analysis pass which computes BlockFrequencyInfo.
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
Function * getCalledFunction() const
Returns the function called, or null if this is an indirect function invocation or the function signa...
LLVM_ABI Function * getCaller()
Helper to get the caller (the parent function).
static LLVM_ABI void collectIndirectCallPromotionList(CallBase &IC, Result &Profile, SetVector< std::pair< CallBase *, Function * > > &Candidates)
LLVM_ABI bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
The InlineAdvisorAnalysis is a module pass because the InlineAdvisor needs to capture state right bef...
Interface for deciding whether to inline a call site or not.
virtual void onPassEntry(LazyCallGraph::SCC *SCC=nullptr)
This must be called when the Inliner pass is entered, to allow the InlineAdvisor update internal stat...
virtual void onPassExit(LazyCallGraph::SCC *SCC=nullptr)
This must be called when the Inliner pass is exited, as function passes may be run subsequently.
std::unique_ptr< InlineAdvice > getAdvice(CallBase &CB, bool MandatoryOnly=false)
Get an InlineAdvice containing a recommendation on whether to inline or not.
This class captures the data input to the InlineFunction call, and records the auxiliary results prod...
SmallVector< CallBase *, 8 > InlinedCallSites
All of the new call sites inlined into the caller.
InlineResult is basically true or false.
LLVM_ABI PreservedAnalyses run(Module &, ModuleAnalysisManager &)
A Module instance is used to store all the information related to an LLVM module.
A set of analyses that are preserved following a run of a transformation pass.
static PreservedAnalyses none()
Convenience factory function for the empty preserved set.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
An analysis pass based on the new PM to deliver ProfileSummaryInfo.
Analysis providing profile information.
A vector that has set insertion semantics.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Analysis pass providing the TargetLibraryInfo.
Provides information about what library functions are available for the current target.
bool isKnownVectorFunctionInLibrary(StringRef F) const
Check if the function "F" is listed in a library known to LLVM.
LibFunc getLibFunc(StringRef funcName) const
Searches for a particular function name.
Target - Wrapper for Target specific information.
initializer< Ty > init(const Ty &Val)
Add a small namespace to avoid name clashes with the classes used in the streaming interface.
This is an optimization pass for GlobalISel generic memory operations.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
LLVM_ABI CallBase & promoteCallWithIfThenElse(CallBase &CB, Function *Callee, MDNode *BranchWeights=nullptr)
Promote the given indirect call site to conditionally call Callee.
InnerAnalysisManagerProxy< FunctionAnalysisManager, Module > FunctionAnalysisManagerModuleProxy
Provide the FunctionAnalysisManager to Module proxy.
LLVM_ABI void setInlineRemark(CallBase &CB, StringRef Message)
Set the inline-remark attribute.
LLVM_ABI InlineResult InlineFunction(CallBase &CB, InlineFunctionInfo &IFI, bool MergeAttributes=false, AAResults *CalleeAAR=nullptr, bool InsertLifetime=true, bool TrackInlineHistory=false, Function *ForwardVarArgsTo=nullptr, OptimizationRemarkEmitter *ORE=nullptr)
This function inlines the called function into the basic block of the caller.
auto reverse(ContainerTy &&C)
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
LLVM_ABI std::unique_ptr< InlineOrder > getInlineOrder(FunctionAnalysisManager &FAM, const InlineParams &Params, ModuleAnalysisManager &MAM, Module &M)
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
LLVM_ABI bool tryPromoteCall(CallBase &CB)
Try to promote (devirtualize) a virtual call on an Alloca.
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.
AnalysisManager< Module > ModuleAnalysisManager
Convenience typedef for the Module analysis manager.
Provides context on when an inline advisor is constructed in the pipeline (e.g., link phase,...