34#define DEBUG_TYPE "coro-annotation-elide"
38 cl::desc(
"Minimum BranchProbability to consider a elide a coroutine."));
57 Frame->setAlignment(FrameAlign);
82 NewArgs, Bundles,
"", NewCBInsertPt);
83 NewCI->setTailCallKind(CI->getTailCallKind());
87 II->getNormalDest(),
II->getUnwindDest(),
88 NewArgs, Bundles,
"", NewCBInsertPt);
103 if (
IR.isSuccess()) {
122 Function *NewCallee = Callee->getParent()->getFunction(
123 (Callee->getName() +
".noalloc").str());
128 for (
auto *U : Callee->users()) {
130 if (CB->getCalledFunction() == Callee)
134 auto FramePtrArgPosition = NewCallee->
arg_size() - 1;
142 for (
auto *CB :
Users) {
143 auto *Caller = CB->getFunction();
147 bool IsCallerPresplitCoroutine = Caller->isPresplitCoroutine();
148 bool HasAttr = CB->hasFnAttr(llvm::Attribute::CoroElideSafe);
149 if (IsCallerPresplitCoroutine && HasAttr) {
152 auto BlockFreq = BFI.getBlockFreq(CB->getParent()).getFrequency();
153 auto EntryFreq = BFI.getEntryFreq().getFrequency();
157 if (BlockFreq < MinFreq) {
160 DEBUG_TYPE,
"CoroAnnotationElideUnlikely", Caller)
161 <<
"'" <<
ore::NV(
"callee", Callee->getName())
162 <<
"' not elided in '"
163 <<
ore::NV(
"caller", Caller->getName())
164 <<
"' because of low frequency: "
165 <<
ore::NV(
"block_freq", BlockFreq)
166 <<
" (threshold: " <<
ore::NV(
"min_freq", MinFreq) <<
")";
171 auto *CallerN = CG.
lookup(*Caller);
172 auto *CallerC = CallerN ? CG.
lookupSCC(*CallerN) :
nullptr;
175 auto ShouldUpdateCallGraph = !!CallerC;
176 processCall(CB, Caller, NewCallee, FrameSize, FrameAlign);
180 <<
"'" <<
ore::NV(
"callee", Callee->getName())
181 <<
"' elided in '" <<
ore::NV(
"caller", Caller->getName())
182 <<
"' (block_freq: " <<
ore::NV(
"block_freq", BlockFreq)
188 if (ShouldUpdateCallGraph)
196 <<
"'" <<
ore::NV(
"callee", Callee->getName())
197 <<
"' not elided in '" <<
ore::NV(
"caller", Caller->getName())
198 <<
"' (caller_presplit="
199 <<
ore::NV(
"caller_presplit", IsCallerPresplitCoroutine)
200 <<
", elide_safe_attr=" <<
ore::NV(
"elide_safe_attr", HasAttr)
const AArch64InstrInfo MachineBasicBlock::iterator InsertPt
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
This header provides classes for managing passes over SCCs of the call graph.
static void processCall(CallBase *CB, Function *Caller, Function *NewCallee, uint64_t FrameSize, Align FrameAlign)
static cl::opt< float > CoroElideBranchRatio("coro-elide-branch-ratio", cl::init(0.55), cl::Hidden, cl::desc("Minimum BranchProbability to consider a elide a coroutine."))
static Instruction * getFirstNonAllocaInTheEntryBlock(Function *F)
static Value * allocateFrameInCaller(Function *Caller, uint64_t FrameSize, Align FrameAlign)
Module.h This file contains the declarations for the Module class.
This header defines various interfaces for pass management in LLVM.
iv Induction Variable Users
Implements a lazy call graph analysis and related passes for the new pass manager.
Legalize the Machine IR a function s Machine IR
uint64_t IntrinsicInst * II
FunctionAnalysisManager FAM
static const unsigned FramePtr
an instruction to allocate memory on the stack
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
static LLVM_ABI ArrayType * get(Type *ElementType, uint64_t NumElements)
This static method is the primary way to construct an ArrayType.
InstListType::iterator iterator
Instruction iterators...
Analysis pass which computes BlockFrequencyInfo.
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
void setCallingConv(CallingConv::ID CC)
LLVM_ABI void getOperandBundlesAsDefs(SmallVectorImpl< OperandBundleDef > &Defs) const
Return the list of operand bundles attached to this instruction as a vector of OperandBundleDefs.
CallingConv::ID getCallingConv() const
User::op_iterator arg_begin()
Return the iterator pointing to the beginning of the argument list.
void setAttributes(AttributeList A)
Set the attributes for this call.
User::op_iterator arg_end()
Return the iterator pointing to the end of the argument list.
void removeFnAttr(Attribute::AttrKind Kind)
Removes the attribute from the function.
AttributeList getAttributes() const
Return the attributes for this call.
void setCalledFunction(Function *Fn)
Sets the function called, including updating the function type.
static CallInst * Create(FunctionType *Ty, Value *F, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
A parsed version of the target data layout string in and methods for querying it.
A proxy from a FunctionAnalysisManager to an SCC.
FunctionType * getFunctionType() const
Returns the FunctionType for me.
uint64_t getParamDereferenceableBytes(unsigned ArgNo) const
Extract the number of dereferenceable bytes for a parameter.
MaybeAlign getParamAlign(unsigned ArgNo) const
This class captures the data input to the InlineFunction call, and records the auxiliary results prod...
InlineResult is basically true or false.
const DebugLoc & getDebugLoc() const
Return the debug location for this node as a DebugLoc.
LLVM_ABI InstListType::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
void setDebugLoc(DebugLoc Loc)
Set the debug location information for this instruction.
static InvokeInst * Create(FunctionType *Ty, Value *Func, BasicBlock *IfNormal, BasicBlock *IfException, ArrayRef< Value * > Args, const Twine &NameStr, InsertPosition InsertBefore=nullptr)
This is an important class for using LLVM in a threaded context.
A node in the call graph.
An SCC of the call graph.
A lazily constructed view of the call graph of a module.
SCC * lookupSCC(Node &N) const
Lookup a function's SCC in the graph.
Node * lookup(const Function &F) const
Lookup a function in the graph which has already been scanned and added.
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.
void append(ItTy in_start, ItTy in_end)
Add the specified range to the end of the SmallVector.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
static LLVM_ABI IntegerType * getInt8Ty(LLVMContext &C)
LLVM Value Representation.
LLVM_ABI void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
self_iterator getIterator()
Pass manager infrastructure for declaring and invalidating analyses.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
initializer< Ty > init(const Ty &Val)
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.
LLVM_ABI LazyCallGraph::SCC & updateCGAndAnalysisManagerForCGSCCPass(LazyCallGraph &G, LazyCallGraph::SCC &C, LazyCallGraph::Node &N, CGSCCAnalysisManager &AM, CGSCCUpdateResult &UR, FunctionAnalysisManager &FAM)
Helper to update the call graph after running a CGSCC pass.
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.
AnalysisManager< LazyCallGraph::SCC, LazyCallGraph & > CGSCCAnalysisManager
The CGSCC analysis manager.
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...
This struct is a compact representation of a valid (non-zero power of two) alignment.
Support structure for SCC passes to communicate updates the call graph back to the CGSCC pass manager...
LLVM_ABI PreservedAnalyses run(LazyCallGraph::SCC &C, CGSCCAnalysisManager &AM, LazyCallGraph &CG, CGSCCUpdateResult &UR)
Align valueOrOne() const
For convenience, returns a valid alignment or 1 if undefined.