46#define DEBUG_TYPE "module-inline"
48STATISTIC(NumInlined,
"Number of functions inlined");
49STATISTIC(NumDeleted,
"Number of functions deleted because all callers found");
56 while (InlineHistoryID != -1) {
57 assert(
unsigned(InlineHistoryID) < InlineHistory.size() &&
58 "Invalid inline history ID");
59 if (InlineHistory[InlineHistoryID].first ==
F)
61 InlineHistoryID = InlineHistory[InlineHistoryID].second;
82 OwnedAdvisor = std::make_unique<DefaultInlineAdvisor>(
87 assert(IAA->getAdvisor() &&
88 "Expected a present InlineAdvisorAnalysis also have an "
89 "InlineAdvisor initialized");
90 return *IAA->getAdvisor();
108 if (!IAA.tryCreate(Params, Mode, {},
110 M.getContext().emitError(
111 "Could not setup Inlining Advisor for the requested "
112 "mode and/or options");
116 bool Changed =
false;
142 assert(Calls !=
nullptr &&
"Expected an initialized InlineOrder");
148 if (
auto *CB = dyn_cast<CallBase>(&
I))
149 if (
Function *Callee = CB->getCalledFunction()) {
150 if (!Callee->isDeclaration())
151 Calls->push({CB, -1});
152 else if (!isa<IntrinsicInst>(
I)) {
157 << NV(
"Callee", Callee) <<
" will not be inlined into "
158 << NV(
"Caller", CB->getCaller())
159 <<
" because its definition is unavailable"
179 while (!Calls->empty()) {
180 auto P = Calls->pop();
182 const int InlineHistoryID =
P.second;
187 <<
" Function size: " <<
F.getInstructionCount()
195 if (InlineHistoryID != -1 &&
201 auto Advice = Advisor.getAdvice(*CB,
false);
203 if (!Advice->isInliningRecommended()) {
204 Advice->recordUnattemptedInlining();
211 GetAssumptionCache, PSI,
218 if (!
IR.isSuccess()) {
219 Advice->recordUnsuccessfulInlining(
IR);
226 LLVM_DEBUG(
dbgs() <<
" Size after inlining: " <<
F.getInstructionCount()
230 if (!IFI.InlinedCallSites.empty()) {
231 int NewHistoryID = InlineHistory.
size();
235 Function *NewCallee = ICB->getCalledFunction();
242 NewCallee = ICB->getCalledFunction();
246 Calls->push({ICB, NewHistoryID});
254 bool CalleeWasDeleted =
false;
255 if (
Callee.hasLocalLinkage()) {
258 Callee.removeDeadConstantUsers();
261 Calls->erase_if([&](
const std::pair<CallBase *, int> &Call) {
262 return Call.first->getCaller() == &Callee;
268 Callee.dropAllReferences();
270 "Cannot put cause a function to become dead twice!");
272 CalleeWasDeleted =
true;
275 if (CalleeWasDeleted)
276 Advice->recordInliningWithCalleeDeleted();
278 Advice->recordInlining();
287 for (
Function *DeadF : DeadFunctions) {
289 FAM.
clear(*DeadF, DeadF->getName());
292 M.getFunctionList().erase(DeadF);
Expand Atomic instructions
static bool inlineHistoryIncludes(Function *F, int InlineHistoryID, const SmallVectorImpl< std::pair< Function *, int > > &InlineHistory)
Return true if the specified inline history ID indicates an inline history that includes the specifie...
static bool isKnownLibFunction(Function &F, TargetLibraryInfo &TLI)
Legalize the Machine IR a function s Machine IR
static bool inlineHistoryIncludes(Function *F, int InlineHistoryID, const SmallVectorImpl< std::pair< Function *, int > > &InlineHistory)
Return true if the specified inline history ID indicates an inline history that includes the specifie...
Module.h This file contains the declarations for the Module class.
FunctionAnalysisManager FAM
ModuleAnalysisManager MAM
This header defines various interfaces for pass management in LLVM.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file defines the make_scope_exit function, which executes user-defined cleanup logic at scope ex...
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 container for analyses that lazily runs them and caches their results.
void clear(IRUnitT &IR, llvm::StringRef Name)
Clear any cached analysis results for a single unit of IR.
PassT::Result * getCachedResult(IRUnitT &IR) const
Get the cached result of an analysis pass for a given IR unit.
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
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...
Function * getCaller()
Helper to get the caller (the parent function).
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.
This class captures the data input to the InlineFunction call, and records the auxiliary results prod...
InlineResult is basically true or false.
An analysis over an "outer" IR unit that provides access to an analysis manager over an "inner" IR un...
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.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
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.
bool getLibFunc(StringRef funcName, LibFunc &F) const
Searches for a particular function name.
This is an optimization pass for GlobalISel generic memory operations.
detail::scope_exit< std::decay_t< Callable > > make_scope_exit(Callable &&F)
void setInlineRemark(CallBase &CB, StringRef Message)
Set the inline-remark attribute.
auto reverse(ContainerTy &&C)
std::unique_ptr< InlineOrder< std::pair< CallBase *, int > > > getInlineOrder(FunctionAnalysisManager &FAM, const InlineParams &Params, ModuleAnalysisManager &MAM, Module &M)
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
InlineResult InlineFunction(CallBase &CB, InlineFunctionInfo &IFI, bool MergeAttributes=false, AAResults *CalleeAAR=nullptr, bool InsertLifetime=true, Function *ForwardVarArgsTo=nullptr)
This function inlines the called function into the basic block of the caller.
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
bool tryPromoteCall(CallBase &CB)
Try to promote (devirtualize) a virtual call on an Alloca.
Provides context on when an inline advisor is constructed in the pipeline (e.g., link phase,...