31#define DEBUG_TYPE "inline"
57 &GetAAR(Callee), InsertLifetime);
61 <<
"'" <<
ore::NV(
"Callee", &Callee) <<
"' is not inlined into '"
79 if (
F.hasFnAttribute(Attribute::Flatten))
82 if (
F.isPresplitCoroutine())
90 for (
User *U :
F.users())
99 Changed |= TryInline(*CB,
F, ORE,
"always inline attribute");
102 F.removeDeadConstantUsers();
103 if (
F.hasFnAttribute(Attribute::AlwaysInline) &&
F.isDefTriviallyDead()) {
108 FAM->clear(
F,
F.getName());
109 M.getFunctionList().erase(
F);
127 if (!Callee || Callee->isDeclaration())
134 while (!Worklist.
empty()) {
137 int InlineHistoryID = Item.second;
148 <<
"'" <<
ore::NV(
"Callee", Callee)
149 <<
"' is not inlined into '"
151 <<
"': recursive call during flattening";
161 if (!Decision || !Decision->isSuccess())
164 if (!TryInline(*CB, *Callee, ORE,
"flatten attribute", &NewCallSites))
170 if (!NewCallSites.
empty()) {
171 int NewHistoryID = InlineHistory.
size();
172 InlineHistory.
push_back({Callee, InlineHistoryID});
173 for (
CallBase *NewCB : NewCallSites) {
174 Function *NewCallee = NewCB->getCalledFunction();
176 Worklist.
push_back({NewCB, NewHistoryID});
182 if (!InlinedComdatFunctions.
empty()) {
187 for (
Function *
F : InlinedComdatFunctions) {
189 FAM->clear(*
F,
F->getName());
190 M.getFunctionList().erase(
F);
198struct AlwaysInlinerLegacyPass :
public ModulePass {
201 AlwaysInlinerLegacyPass()
202 : AlwaysInlinerLegacyPass(
true) {}
204 AlwaysInlinerLegacyPass(
bool InsertLifetime)
208 bool runOnModule(
Module &M)
override {
210 auto &PSI = getAnalysis<ProfileSummaryInfoWrapperPass>().getPSI();
212 return getAnalysis<AAResultsWrapperPass>(
F).getAAResults();
215 return getAnalysis<AssumptionCacheTracker>().getAssumptionCache(
F);
218 return getAnalysis<TargetTransformInfoWrapperPass>().getTTI(
F);
221 return getAnalysis<TargetLibraryInfoWrapperPass>().getTLI(
F);
224 return AlwaysInlineImpl(M, InsertLifetime, PSI,
nullptr,
225 GetAssumptionCache, GetAAR, GetTTI, GetTLI);
241char AlwaysInlinerLegacyPass::ID = 0;
243 "Inliner for always_inline functions",
false,
false)
253 return new AlwaysInlinerLegacyPass(InsertLifetime);
274 bool Changed = AlwaysInlineImpl(M, InsertLifetime, PSI, &
FAM,
275 GetAssumptionCache, GetAAR, GetTTI, GetTLI);
Provides passes to inlining "always_inline" functions.
Module.h This file contains the declarations for the Module class.
FunctionAnalysisManager FAM
ModuleAnalysisManager MAM
#define INITIALIZE_PASS_DEPENDENCY(depName)
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
This file implements a set that has insertion order iteration characteristics.
A manager for alias analyses.
A wrapper pass to provide the legacy pass manager access to a suitably prepared AAResults object.
This templated class represents "all analyses that operate over <aparticular IR unit>" (e....
LLVM_ABI PreservedAnalyses run(Module &M, ModuleAnalysisManager &)
Represent the analysis usage information of a pass.
AnalysisUsage & addRequired()
A function analysis which provides an AssumptionCache.
An immutable pass that tracks lazily created AssumptionCache objects.
A cache of @llvm.assume calls within a function.
LLVM Basic Block Representation.
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...
bool hasFnAttr(Attribute::AttrKind Kind) const
Determine whether this call has the given attribute.
AttributeList getAttributes() const
Return the attributes for this call.
LLVM_ABI Function * getCaller()
Helper to get the caller (the parent function).
LLVM_ABI bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
static InlineCost getAlways(const char *Reason, std::optional< CostBenefitPair > CostBenefit=std::nullopt)
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.
const char * getFailureReason() const
const DebugLoc & getDebugLoc() const
Return the debug location for this node as a DebugLoc.
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
A Module instance is used to store all the information related to an LLVM module.
Pass interface - Implemented by all 'passes'.
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.
PreservedAnalyses & preserveSet()
Mark an analysis set as preserved.
An analysis pass based on the new PM to deliver ProfileSummaryInfo.
An analysis pass based on legacy pass manager to deliver ProfileSummaryInfo.
Analysis providing profile information.
void clear()
Completely clear the SetVector.
bool insert(const value_type &X)
Insert a new element into the SetVector.
A SetVector that performs no allocations if smaller than a certain size.
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 TargetTransformInfo.
Analysis pass providing the TargetLibraryInfo.
Provides information about what library functions are available for the current target.
An efficient, type-erasing, non-owning reference to a callable.
const ParentTy * getParent() const
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
DiagnosticInfoOptimizationBase::Argument NV
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI InlineResult InlineFunction(CallBase &CB, InlineFunctionInfo &IFI, bool MergeAttributes=false, AAResults *CalleeAAR=nullptr, bool InsertLifetime=true, Function *ForwardVarArgsTo=nullptr, OptimizationRemarkEmitter *ORE=nullptr)
This function inlines the called function into the basic block of the caller.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
iterator_range< early_inc_iterator_impl< detail::IterOfRange< RangeT > > > make_early_inc_range(RangeT &&Range)
Make a range that does early increment to allow mutation of the underlying range without disrupting i...
InnerAnalysisManagerProxy< FunctionAnalysisManager, Module > FunctionAnalysisManagerModuleProxy
Provide the FunctionAnalysisManager to Module proxy.
LLVM_ABI bool inlineHistoryIncludes(Function *F, int InlineHistoryID, ArrayRef< std::pair< Function *, int > > InlineHistory)
Check if Function F appears in the inline history chain.
LLVM_ABI InlineResult isInlineViable(Function &Callee)
Check if it is mechanically possible to inline the function Callee, based on the contents of the func...
LLVM_ABI 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).
LLVM_ABI Pass * createAlwaysInlinerLegacyPass(bool InsertLifetime=true)
Create a legacy pass manager instance of a pass to inline and remove functions marked as "always_inli...
LLVM_ABI std::optional< InlineResult > getAttributeBasedInliningDecision(CallBase &Call, Function *Callee, TargetTransformInfo &CalleeTTI, function_ref< const TargetLibraryInfo &(Function &)> GetTLI)
Returns InlineResult::success() if the call site should be always inlined because of user directives,...
LLVM_ABI void filterDeadComdatFunctions(SmallVectorImpl< Function * > &DeadComdatFunctions)
Filter out potentially dead comdat functions where other entries keep the entire comdat group alive.
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.
AnalysisManager< Module > ModuleAnalysisManager
Convenience typedef for the Module analysis manager.