25 #ifndef LLVM_IR_CALLSITE_H 26 #define LLVM_IR_CALLSITE_H 52 typename ValTy =
const Value,
typename UserTy =
const User,
53 typename UseTy =
const Use,
typename InstrTy =
const Instruction,
54 typename CallTy =
const CallInst,
55 typename InvokeTy =
const InvokeInst,
56 typename CallBrTy =
const CallBrInst,
74 if (InstrTy *II = dyn_cast<InstrTy>(V)) {
77 if (II->getOpcode() == Instruction::Invoke)
79 if (II->getOpcode() == Instruction::CallBr)
105 assert(getInstruction() &&
"Not a call, invoke or callbr instruction!");
112 return dyn_cast<FunTy>(getCalledValue());
117 const Value *V = getCalledValue();
120 if (isa<FunTy>(V) || isa<Constant>(V))
122 if (
const CallBase *CB = dyn_cast<CallBase>(getInstruction()))
123 if (CB->isInlineAsm())
131 assert(getInstruction() &&
"Not a call, callbr, or invoke instruction!");
133 cast<CallBase>(getInstruction())->getFunctionType() &&
134 "New callee type does not match FunctionType on call");
143 return F->getIntrinsicID();
151 return isCallee(&UI.getUse());
159 return isArgOperand(&UI.getUse());
164 assert(getInstruction() == U->getUser());
165 return arg_begin() <= U && U < arg_end();
170 return isBundleOperand(&UI.getUse());
175 assert(getInstruction() == U->getUser());
176 if (!hasOperandBundles())
178 unsigned OperandNo = U - (*this)->op_begin();
179 return getBundleOperandsStartIndex() <= OperandNo &&
180 OperandNo < getBundleOperandsEndIndex();
185 return isDataOperand(&UI.getUse());
190 return data_operands_begin() <= U && U < data_operands_end();
194 assert(arg_begin() + ArgNo < arg_end() &&
"Argument # out of range!");
195 return *(arg_begin() + ArgNo);
199 assert(getInstruction() &&
"Not a call, invoke or callbr instruction!");
200 assert(arg_begin() + ArgNo < arg_end() &&
"Argument # out of range!");
201 getInstruction()->setOperand(ArgNo, newVal);
207 return getArgumentNo(&I.getUse());
213 assert(getInstruction() &&
"Not a call, invoke or callbr instruction!");
214 assert(isArgOperand(U) &&
"Argument # out of range!");
215 return U - arg_begin();
225 bool arg_empty()
const {
return arg_end() == arg_begin(); }
231 return getDataOperandNo(&UI.getUse());
237 assert(getInstruction() &&
"Not a call, invoke or callbr instruction!");
238 assert(isDataOperand(U) &&
"Data operand # out of range!");
239 return U - data_operands_begin();
254 assert(getInstruction() &&
"Not a call or invoke instruction!");
255 return cast<CallBase>(getInstruction())->data_operands_begin();
258 assert(getInstruction() &&
"Not a call or invoke instruction!");
259 return cast<CallBase>(getInstruction())->data_operands_end();
262 return make_range(data_operands_begin(), data_operands_end());
265 return data_operands_end() == data_operands_begin();
268 return std::distance(data_operands_begin(), data_operands_end());
280 return isCall() && cast<CallInst>(getInstruction())->isMustTailCall();
285 return isCall() && cast<CallInst>(getInstruction())->isTailCall();
288 #define CALLSITE_DELEGATE_GETTER(METHOD) \ 289 InstrTy *II = getInstruction(); \ 290 return isCall() ? cast<CallInst>(II)->METHOD \ 291 : isCallBr() ? cast<CallBrInst>(II)->METHOD \ 292 : cast<InvokeInst>(II)->METHOD 294 #define CALLSITE_DELEGATE_SETTER(METHOD) \ 295 InstrTy *II = getInstruction(); \ 297 cast<CallInst>(II)->METHOD; \ 298 else if (isCallBr()) \ 299 cast<CallBrInst>(II)->METHOD; \ 301 cast<InvokeInst>(II)->METHOD 316 return cast<CallBase>(getInstruction())->isInlineAsm();
592 #undef CALLSITE_DELEGATE_GETTER 593 #undef CALLSITE_DELEGATE_SETTER 598 cast<CallBase>(getInstruction())->getOperandBundlesAsDefs(Defs);
603 return dataOperandHasImpliedAttr(OpNo + 1, Attribute::NoCapture);
608 return paramHasAttr(ArgNo, Attribute::ByVal);
613 return paramHasAttr(ArgNo, Attribute::InAlloca);
618 return paramHasAttr(ArgNo, Attribute::ByVal) ||
619 paramHasAttr(ArgNo, Attribute::InAlloca);
625 return !arg_empty() && paramHasAttr(arg_size() - 1, Attribute::InAlloca);
629 return dataOperandHasImpliedAttr(OpNo + 1, Attribute::ReadNone);
633 return dataOperandHasImpliedAttr(OpNo + 1, Attribute::ReadOnly) ||
634 dataOperandHasImpliedAttr(OpNo + 1, Attribute::ReadNone);
638 return dataOperandHasImpliedAttr(OpNo + 1, Attribute::WriteOnly) ||
639 dataOperandHasImpliedAttr(OpNo + 1, Attribute::ReadNone);
646 if (hasRetAttr(Attribute::NonNull))
650 getType()->getPointerAddressSpace()))
659 for (
arg_iterator AI = this->arg_begin(),
E = this->arg_end(); AI !=
E;
661 if (AI->get() ==
Arg)
667 IterTy getCallee()
const {
668 return cast<CallBase>(getInstruction())->op_end() - 1;
673 Instruction, CallInst, InvokeInst,
674 CallBrInst, User::op_iterator> {
788 explicit operator bool()
const {
return (
bool)CS; }
815 return isCallee(&UI.getUse());
824 "Callback without parameter encoding!");
840 return getCallArgOperandNo(Arg.
getArgNo());
854 return getCallArgOperand(Arg.
getArgNo());
879 int CalleeArgIdx = getCallArgOperandNoForCallee();
880 assert(CalleeArgIdx >= 0 &&
881 unsigned(CalleeArgIdx) < getInstruction()->getNumOperands());
882 return getInstruction()->getOperandUse(CalleeArgIdx);
895 Value *V = getCalledValue();
905 CS.
I = BaseInfo::getEmptyKey();
911 CS.
I = BaseInfo::getTombstoneKey();
916 return BaseInfo::getHashValue(CS.
I);
926 #endif // LLVM_IR_CALLSITE_H bool dataOperandHasImpliedAttr(unsigned i, Attribute::AttrKind Kind) const
Return true if the data operand at index i directly or indirectly has the attribute A...
unsigned getNumTotalBundleOperands() const
ValTy * getReturnedArgOperand() const
void setIsNoInline(bool Value=true)
bool isCallee(const Use *U) const
Return true if U is the use that defines the callee of this ACS.
ImmutableCallSite(const Value *V)
int getCallArgOperandNo(Argument &Arg) const
Return the operand index of the underlying instruction associated with Arg.
ImmutableCallSite(const Instruction *II)
static CallSite getEmptyKey()
This class represents an incoming formal argument to a Function.
bool data_operands_empty() const
This class represents lattice values for constants.
CallSite(Instruction *II)
PointerTy getPointer() const
bool operator!=(const CallSite &CS) const
void setAttributes(AttributeList PAL)
Set the parameter attributes of the call.
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
bool isDataOperand(Value::const_user_iterator UI) const
Determine whether the passed iterator points to a data operand.
bool onlyReadsMemory(unsigned OpNo) const
#define CALLSITE_DELEGATE_GETTER(METHOD)
This provides a very simple, boring adaptor for a begin and end iterator into a range type...
Value * getCallArgOperand(Argument &Arg) const
Return the operand of the underlying instruction associated with Arg.
This class represents a function call, abstracting a target machine's calling convention.
static unsigned getHashValue(const CallSite &CS)
void setCallingConv(CallingConv::ID CC)
Set the calling convention of the call.
bool hasRetAttr(Attribute::AttrKind Kind) const
Return true if this return value has the given attribute.
void getOperandBundlesAsDefs(SmallVectorImpl< OperandBundleDef > &Defs) const
unsigned getBundleOperandsEndIndex() const
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
unsigned getDataOperandNo(Value::const_user_iterator UI) const
Given a value use iterator, return the data operand corresponding to it.
bool isTailCall() const
Tests if this call site is marked as a tail call.
FunTy * getCalledFunction() const
Return the function being called if this is a direct call, otherwise return null (if it's an indirect...
Optional< OperandBundleUse > getOperandBundle(StringRef Name) const
This defines the Use class.
The encoding of a callback with regards to the underlying instruction.
bool doesNotCapture(unsigned OpNo) const
Determine whether this data operand is not captured.
bool isBundleOperand(unsigned Idx) const
FunctionType * getFunctionType() const
CallingConv::ID getCallingConv() const
Get the calling convention of the call.
bool isBundleOperand(const Use *U) const
Determine whether the passed use points to a bundle operand.
void setCannotDuplicate()
InstrTy * operator->() const
A Use represents the edge between a Value definition and its users.
ValTy * getCalledValue() const
Return the pointer to function that is being called.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
uint64_t getDereferenceableOrNullBytes(unsigned i) const
Extract the number of dereferenceable_or_null bytes for a call or parameter (0=unknown).
unsigned getArgumentNo(Value::const_user_iterator I) const
Given a value use iterator, returns the argument that corresponds to it.
This file contains the simple types necessary to represent the attributes associated with functions a...
bool doesNotAccessMemory() const
Determine if the call does not access memory.
bool isReturnNonNull() const
Return true if the return value is known to be not null.
Type * getType() const
Return the type of the instruction that generated this call site.
int getCallArgOperandNo(unsigned ArgNo) const
Return the operand index of the underlying instruction associated with the function parameter number ...
bool hasArgument(const Value *Arg) const
Returns true if this CallSite passes the given Value* as an argument to the called function...
AttributeList getAttributes(LLVMContext &C, ID id)
Return the attributes for an intrinsic.
InstrTy * getInstruction() const
IterTy data_operands_end() const
Class to represent function types.
void setArgument(unsigned ArgNo, Value *newVal)
Type * getType() const
All values are typed, get the type of this value.
static bool setDoesNotThrow(Function &F)
bool isArgOperand(const Use *U) const
Determine whether the passed use points to an argument operand.
unsigned getRetAlignment() const
Extract the alignment of the return value.
bool isMustTailCall() const
Tests if this call site must be tail call optimized.
Optional< OperandBundleUse > getOperandBundle(uint32_t ID) const
void removeAttribute(unsigned i, Attribute::AttrKind Kind)
bool paramHasAttr(unsigned ArgNo, Attribute::AttrKind Kind) const
Return true if the call or the callee has the given attribute.
ParameterEncodingTy ParameterEncoding
void mutateFunctionType(FunctionType *Ty) const
bool doesNotThrow() const
Determine if the call cannot unwind.
void setDoesNotReadMemory()
static bool isDirectCall(Use &U)
bool onlyReadsMemory() const
Determine if the call does not access or only reads memory.
Attribute getAttribute(unsigned i, StringRef Kind) const
uint64_t getDereferenceableBytes(unsigned i) const
Extract the number of dereferenceable bytes for a call or parameter (0=unknown).
static xmlAttrPtr getAttribute(xmlNodePtr Node, const unsigned char *AttributeName)
bool isNoBuiltin() const
Return true if the call should not be treated as a call to a builtin.
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
void setCalledFunction(Value *V)
Set the callee to the specified value.
unsigned getNumArgOperands() const
bool isNoInline() const
Return true if the call should not be inlined.
Instruction * getInstruction() const
Return the underlying instruction.
The instances of the Type class are immutable: once they are created, they are never changed...
bool isIndirectCall() const
Return true if this ACS represents an indirect call.
bool cannotDuplicate() const
Determine if the call can be duplicated.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
bool doesNotReadMemory() const
Determine if the call does not access or only writes memory.
void removeParamAttr(unsigned ArgNo, Attribute::AttrKind Kind)
AttributeList getAttributes() const
Get the parameter attributes of the call.
bool onlyAccessesInaccessibleMemOrArgMem() const
Determine if the function may only access memory that is either inaccessible from the IR or pointed t...
ValTy * getArgument(unsigned ArgNo) const
static bool setOnlyReadsMemory(Function &F)
Function * getCalledFunction() const
Return the function being called if this is a direct call, otherwise return null (if it's an indirect...
bool onlyAccessesArgMemory() const
Determine if the call can access memmory only using pointers based on its arguments.
bool hasInAllocaArgument() const
Determine if there are is an inalloca argument.
CallSite(CallBrInst *CBI)
bool isInAllocaArgument(unsigned ArgNo) const
Determine whether this argument is passed in an alloca.
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
bool isByValOrInAllocaArgument(unsigned ArgNo) const
Determine whether this argument is passed by value or in an alloca.
bool isCallee(Value::const_user_iterator UI) const
Return true if UI is the use that defines the callee of this ACS.
unsigned countOperandBundlesOfType(uint32_t ID) const
bool operator<(const CallSite &CS) const
static bool setDoesNotAccessMemory(Function &F)
bool isStrictFP() const
Return true if the call requires strict floating point semantics.
iterator_range< IterTy > data_ops() const
const Value * stripPointerCasts() const
Strip off pointer casts, all-zero GEPs and address space casts.
unsigned getNumArgOperands() const
Return the number of parameters of the callee.
ImmutableCallSite(CallSite CS)
bool isCallee(const Use *U) const
Determine whether this Use is the callee operand's Use.
iterator_range< IterTy > args() const
static bool isEqual(const CallSite &LHS, const CallSite &RHS)
CallBr instruction, tracking function calls that may not return control but instead transfer it to a ...
void addAttribute(unsigned i, Attribute::AttrKind Kind)
static CallSite getTombstoneKey()
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
bool isArgOperand(Value::const_user_iterator UI) const
Determine whether the passed iterator points to an argument operand.
bool doesNotReadMemory(unsigned OpNo) const
unsigned getNumOperandBundles() const
FunctionType * getType(LLVMContext &Context, ID id, ArrayRef< Type *> Tys=None)
Return the function type for an intrinsic.
bool isConvergent() const
Determine if the call is convergent.
ImmutableCallSite(const CallBrInst *CBI)
unsigned arg_size() const
ImmutableCallSite(const InvokeInst *II)
Type * getParamByValType(unsigned ArgNo) const
Extract the byval type for a call or parameter (nullptr=unknown).
bool isDataOperand(const Use *U) const
Determine whether the passed use points to a data operand.
bool isCallbackCall() const
Return true if this ACS represents a callback call.
static const Function * getCalledFunction(const Value *V, bool LookThroughBitCast, bool &IsNoBuiltin)
bool NullPointerIsDefined(const Function *F, unsigned AS=0)
Check whether null pointer dereferencing is considered undefined behavior for a given function or an ...
bool isIndirectCall() const
Return true if the callsite is an indirect call.
A range adaptor for a pair of iterators.
ImmutableCallSite(const CallInst *CI)
bool hasFnAttr(Attribute::AttrKind Kind) const
Return true if this function has the given attribute.
int getCallArgOperandNoForCallee() const
Return the operand index of the underlying instruction associated with the callee of this ACS...
BBTy * getParent() const
Get the basic block containing the call site.
unsigned getArgNo() const
Return the index of this formal argument in its containing function.
A lightweight accessor for an operand bundle meant to be passed around by value.
Intrinsic::ID getIntrinsicID() const
Return the intrinsic ID of the intrinsic called by this CallSite, or Intrinsic::not_intrinsic if the ...
unsigned getBundleOperandsStartIndex() const
bool doesNotAccessMemory(unsigned OpNo) const
bool operator==(const CallSite &CS) const
bool isBundleOperand(Value::const_user_iterator UI) const
Determine whether the passed iterator points to a bundle operand.
user_iterator_impl< const User > const_user_iterator
unsigned getArgumentNo(const Use *U) const
Given a use for an argument, get the argument number that corresponds to it.
#define CALLSITE_DELEGATE_SETTER(METHOD)
CallSiteBase(CallBrTy *CBI)
void removeAttribute(unsigned i, StringRef Kind)
LLVM_NODISCARD bool empty() const
const Use * const_op_iterator
Establish a view to a call site for examination.
const Function * getParent() const
Return the enclosing method, or null if none.
static bool setOnlyAccessesArgMemory(Function &F)
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
bool onlyAccessesInaccessibleMemory() const
Determine if the function may only access memory that is inaccessible from the IR.
void setDoesNotAccessMemory()
PointerIntPair< InstrTy *, 2, int > I
bool isInvoke() const
Return true if a InvokeInst is enclosed.
bool isCallBr() const
Return true if a CallBrInst is enclosed.
static void setCannotDuplicate(CoroIdInst *CoroId)
Value * getCalledValue() const
Return the pointer to function that is being called.
bool isCallee(Value::const_user_iterator UI) const
Determine whether the passed iterator points to the callee operand's Use.
bool isCall() const
Return true if a CallInst is enclosed.
CallSite getCallSite() const
Return the call site abstraction for the underlying instruction.
bool isByValArgument(unsigned ArgNo) const
Determine whether this argument is passed by value.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Attribute getAttribute(unsigned i, Attribute::AttrKind Kind) const
bool hasFnAttr(StringRef Kind) const
Return true if this function has the given attribute.
Value * getCallArgOperand(unsigned ArgNo) const
Return the operand of the underlying instruction associated with the function parameter number ArgNo ...
Module * getParent()
Get the module that this global value is contained inside of...
LLVM Value Representation.
bool doesNotReturn() const
Determine if the call cannot return.
bool returnDoesNotAlias() const
Determine if the return value is marked with NoAlias attribute.
unsigned getParamAlignment(unsigned ArgNo) const
Extract the alignment for a call or parameter (0=unknown).
void addAttribute(unsigned i, Attribute Attr)
void setOnlyAccessesInaccessibleMemOrArgMem()
const Use & getCalleeUseForCallback() const
Return the use of the callee value in the underlying instruction.
StringRef - Represent a constant reference to a string, i.e.
OperandBundleUse getOperandBundleAt(unsigned Index) const
bool isDirectCall() const
Return true if this ACS represents a direct call.
unsigned getDataOperandNo(const Use *U) const
Given a use for a data operand, get the data operand number that corresponds to it.
void setOnlyAccessesInaccessibleMemory()
IterTy data_operands_begin() const
data_operands_begin/data_operands_end - Return iterators iterating over the call / invoke / callbr ar...
ValTy * getArgOperand(unsigned i) const
bool hasOperandBundles() const
CallSiteBase(InvokeTy *II)
void addParamAttr(unsigned ArgNo, Attribute::AttrKind Kind)
AttrKind
This enumeration lists the attributes that can be associated with parameters, function results...
void setOnlyAccessesArgMemory()
void setOnlyReadsMemory()
unsigned data_operands_size() const
FunTy * getCaller() const
Return the caller function for this call site.