31#define DEBUG_TYPE "inline"
56 CB, IFI,
true, &GetAAR(Callee), InsertLifetime,
57 NewCallSites !=
nullptr);
61 <<
"'" <<
ore::NV(
"Callee", &Callee) <<
"' is not inlined into '"
79 if (!
F.hasFnAttribute(Attribute::Flatten))
91 if (!Callee || Callee->isDeclaration())
98 while (!Worklist.
empty()) {
101 int InlineHistoryID = Item.second;
111 <<
"'" <<
ore::NV(
"Callee", Callee)
112 <<
"' is not inlined into '"
114 <<
"': recursive call during flattening";
124 if (!Decision || !Decision->isSuccess())
127 if (!TryInline(*CB, *Callee, ORE,
"flatten attribute", &NewCallSites))
133 if (!NewCallSites.
empty()) {
134 int NewHistoryID = InlineHistory.
size();
135 InlineHistory.
push_back({Callee, InlineHistoryID});
136 for (
CallBase *NewCB : NewCallSites) {
137 Function *NewCallee = NewCB->getCalledFunction();
139 Worklist.
push_back({NewCB, NewHistoryID});
146 if (
F.isPresplitCoroutine())
154 for (
User *U :
F.users())
157 CB->
hasFnAttr(Attribute::AlwaysInline) &&
163 Changed |= TryInline(*CB,
F, ORE,
"always inline attribute");
166 F.removeDeadConstantUsers();
167 if (
F.hasFnAttribute(Attribute::AlwaysInline) &&
F.isDefTriviallyDead()) {
172 FAM->clear(
F,
F.getName());
173 M.getFunctionList().erase(
F);
179 if (!InlinedComdatFunctions.
empty()) {
184 for (
Function *
F : InlinedComdatFunctions) {
186 FAM->clear(*
F,
F->getName());
187 M.getFunctionList().erase(
F);
195struct AlwaysInlinerLegacyPass :
public ModulePass {
198 AlwaysInlinerLegacyPass()
199 : AlwaysInlinerLegacyPass(
true) {}
201 AlwaysInlinerLegacyPass(
bool InsertLifetime)
205 bool runOnModule(
Module &M)
override {
207 auto &PSI = getAnalysis<ProfileSummaryInfoWrapperPass>().getPSI();
209 return getAnalysis<AAResultsWrapperPass>(
F).getAAResults();
212 return getAnalysis<AssumptionCacheTracker>().getAssumptionCache(
F);
215 return getAnalysis<TargetTransformInfoWrapperPass>().getTTI(
F);
218 return getAnalysis<TargetLibraryInfoWrapperPass>().getTLI(
F);
221 return AlwaysInlineImpl(M, InsertLifetime, PSI,
nullptr,
222 GetAssumptionCache, GetAAR, GetTTI, GetTLI);
238char AlwaysInlinerLegacyPass::ID = 0;
240 "Inliner for always_inline functions",
false,
false)
250 return new AlwaysInlinerLegacyPass(InsertLifetime);
271 bool Changed = AlwaysInlineImpl(M, InsertLifetime, PSI, &
FAM,
272 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.
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 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.
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.