26 #ifndef LLVM_IR_CALLSITE_H 27 #define LLVM_IR_CALLSITE_H 52 template <
typename FunTy =
const Function,
54 typename ValTy =
const Value,
55 typename UserTy =
const User,
56 typename UseTy =
const Use,
57 typename InstrTy =
const Instruction,
58 typename CallTy =
const CallInst,
59 typename InvokeTy =
const InvokeInst,
75 if (InstrTy *II = dyn_cast<InstrTy>(V)) {
78 else if (II->getOpcode() == Instruction::Invoke)
101 assert(getInstruction() &&
"Not a call or invoke instruction!");
108 return dyn_cast<FunTy>(getCalledValue());
113 const Value *V = getCalledValue();
116 if (isa<FunTy>(V) || isa<Constant>(V))
118 if (
const CallInst *CI = dyn_cast<CallInst>(getInstruction())) {
119 if (CI->isInlineAsm())
127 assert(getInstruction() &&
"Not a call or invoke instruction!");
136 return F->getIntrinsicID();
144 return isCallee(&UI.getUse());
152 return isArgOperand(&UI.getUse());
157 assert(getInstruction() == U->getUser());
158 return arg_begin() <= U && U < arg_end();
163 return isBundleOperand(&UI.getUse());
168 assert(getInstruction() == U->getUser());
169 if (!hasOperandBundles())
171 unsigned OperandNo = U - (*this)->op_begin();
172 return getBundleOperandsStartIndex() <= OperandNo &&
173 OperandNo < getBundleOperandsEndIndex();
178 return isDataOperand(&UI.getUse());
183 return data_operands_begin() <= U && U < data_operands_end();
187 assert(arg_begin() + ArgNo < arg_end() &&
"Argument # out of range!");
188 return *(arg_begin() + ArgNo);
192 assert(getInstruction() &&
"Not a call or invoke instruction!");
193 assert(arg_begin() + ArgNo < arg_end() &&
"Argument # out of range!");
194 getInstruction()->setOperand(ArgNo, newVal);
200 return getArgumentNo(&I.getUse());
206 assert(getInstruction() &&
"Not a call or invoke instruction!");
207 assert(isArgOperand(U) &&
"Argument # out of range!");
208 return U - arg_begin();
218 bool arg_empty()
const {
return arg_end() == arg_begin(); }
224 return getDataOperandNo(&UI.getUse());
230 assert(getInstruction() &&
"Not a call or invoke instruction!");
231 assert(isDataOperand(U) &&
"Data operand # out of range!");
232 return U - data_operands_begin();
246 assert(getInstruction() &&
"Not a call or invoke instruction!");
247 return (*this)->op_begin();
250 assert(getInstruction() &&
"Not a call or invoke instruction!");
251 return (*this)->op_end() - (isCall() ? 1 : 3);
254 return make_range(data_operands_begin(), data_operands_end());
257 return data_operands_end() == data_operands_begin();
260 return std::distance(data_operands_begin(), data_operands_end());
272 return isCall() && cast<CallInst>(getInstruction())->isMustTailCall();
277 return isCall() && cast<CallInst>(getInstruction())->isTailCall();
280 #define CALLSITE_DELEGATE_GETTER(METHOD) \ 281 InstrTy *II = getInstruction(); \ 283 ? cast<CallInst>(II)->METHOD \ 284 : cast<InvokeInst>(II)->METHOD 286 #define CALLSITE_DELEGATE_SETTER(METHOD) \ 287 InstrTy *II = getInstruction(); \ 289 cast<CallInst>(II)->METHOD; \ 291 cast<InvokeInst>(II)->METHOD 307 return cast<CallInst>(getInstruction())->isInlineAsm();
579 #undef CALLSITE_DELEGATE_GETTER 580 #undef CALLSITE_DELEGATE_SETTER 587 cast<CallInst>(II)->getOperandBundlesAsDefs(Defs);
589 cast<InvokeInst>(II)->getOperandBundlesAsDefs(Defs);
641 getType()->getPointerAddressSpace()))
650 for (
arg_iterator AI = this->arg_begin(),
E = this->arg_end(); AI !=
E;
652 if (AI->get() ==
Arg)
658 IterTy getCallee()
const {
659 return cast<CallBase>(getInstruction())->op_end() - 1;
664 Instruction, CallInst, InvokeInst,
691 CS.
I = BaseInfo::getEmptyKey();
697 CS.
I = BaseInfo::getTombstoneKey();
702 return BaseInfo::getHashValue(CS.
I);
723 #endif // LLVM_IR_CALLSITE_H
uint64_t getDereferenceableBytes(unsigned i) const
Extract the number of dereferenceable bytes for a call or parameter (0=unknown).
unsigned getArgumentNo(const Use *U) const
Given a use for an argument, get the argument number that corresponds to it.
ImmutableCallSite(const Value *V)
ImmutableCallSite(const Instruction *II)
static CallSite getEmptyKey()
unsigned arg_size() const
CallingConv::ID getCallingConv() const
Get the calling convention of the call.
This class represents lattice values for constants.
CallSite(Instruction *II)
unsigned getParamAlignment(unsigned ArgNo) const
Extract the alignment for a call or parameter (0=unknown).
PointerTy getPointer() const
bool operator!=(const CallSite &CS) const
bool onlyReadsMemory(unsigned OpNo) const
bool isInAllocaArgument(unsigned ArgNo) const
Determine whether this argument is passed in an alloca.
bool isBundleOperand(Value::const_user_iterator UI) const
Determine whether the passed iterator points to a bundle operand.
unsigned getDataOperandNo(const Use *U) const
Given a use for a data operand, get the data operand number that corresponds to it.
bool onlyAccessesArgMemory() const
Determine if the call can access memmory only using pointers based on its arguments.
Attribute getAttribute(unsigned i, StringRef Kind) const
void setDoesNotAccessMemory()
bool returnDoesNotAlias() const
Determine if the return value is marked with NoAlias attribute.
#define CALLSITE_DELEGATE_GETTER(METHOD)
This provides a very simple, boring adaptor for a begin and end iterator into a range type...
This class represents a function call, abstracting a target machine's calling convention.
iterator_range< IterTy > args() const
Optional< OperandBundleUse > getOperandBundle(uint32_t ID) const
static unsigned getHashValue(const CallSite &CS)
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 getBundleOperandsEndIndex() const
uint64_t getDereferenceableOrNullBytes(unsigned i) const
Extract the number of dereferenceable_or_null bytes for a call or parameter (0=unknown).
block Block Frequency true
bool isCallee(const Use *U) const
Determine whether this Use is the callee operand's Use.
bool isIndirectCall() const
Return true if the callsite is an indirect call.
This defines the Use class.
bool isNoInline() const
Return true if the call should not be inlined.
unsigned getBundleOperandsStartIndex() const
PointerIntPair< InstrTy *, 1, bool > I
void setOnlyAccessesInaccessibleMemory()
bool onlyReadsMemory() const
Determine if the call does not access or only reads memory.
bool doesNotReturn() const
Determine if the call cannot return.
amdgpu Simplify well known AMD library false Value Value const Twine & Name
InstrTy * operator->() const
unsigned data_operands_size() const
A Use represents the edge between a Value definition and its users.
bool isArgOperand(Value::const_user_iterator UI) const
Determine whether the passed iterator points to an argument operand.
bool isArgOperand(const Use *U) const
Determine whether the passed use points to an argument operand.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
This file contains the simple types necessary to represent the attributes associated with functions a...
InstrTy * getInstruction() const
bool isReturnNonNull() const
Return true if the return value is known to be not null.
bool hasInAllocaArgument() const
Determine if there are is an inalloca argument.
void setArgument(unsigned ArgNo, Value *newVal)
void setOnlyAccessesArgMemory()
AttributeList getAttributes(LLVMContext &C, ID id)
Return the attributes for an intrinsic.
ValTy * getCalledValue() const
Return the pointer to function that is being called.
IterTy data_operands_end() const
Class to represent function types.
static bool setDoesNotThrow(Function &F)
ValTy * getArgOperand(unsigned i) const
bool isNoBuiltin() const
Return true if the call should not be treated as a call to a builtin.
Intrinsic::ID getIntrinsicID() const
Return the intrinsic ID of the intrinsic called by this CallSite, or Intrinsic::not_intrinsic if the ...
unsigned getDataOperandNo(Value::const_user_iterator UI) const
Given a value use iterator, return the data operand corresponding to it.
bool paramHasAttr(unsigned ArgNo, Attribute::AttrKind Kind) const
Return true if the call or the callee has the given attribute.
void setDoesNotReadMemory()
bool isCall() const
Return true if a CallInst is enclosed.
Optional< OperandBundleUse > getOperandBundle(StringRef Name) const
bool isBundleOperand(const Use *U) const
Determine whether the passed use points to a bundle operand.
void setAttributes(AttributeList PAL)
Set the parameter attributes of the call.
bool isStrictFP() const
Return true if the call requires strict floating point semantics.
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
void setIsNoInline(bool Value=true)
void addAttribute(unsigned i, Attribute Attr)
The instances of the Type class are immutable: once they are created, they are never changed...
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
bool hasFnAttr(Attribute::AttrKind Kind) const
Return true if this function has the given attribute.
bool doesNotReadMemory(unsigned OpNo) const
void removeParamAttr(unsigned ArgNo, Attribute::AttrKind Kind)
static bool setOnlyReadsMemory(Function &F)
bool hasOperandBundles() const
unsigned getNumTotalBundleOperands() const
void setCallingConv(CallingConv::ID CC)
Set the calling convention of the call.
bool isDataOperand(const Use *U) const
Determine whether the passed use points to a data operand.
bool isDataOperand(Value::const_user_iterator UI) const
Determine whether the passed iterator points to a data operand.
bool hasFnAttr(StringRef Kind) const
Return true if this function has the given attribute.
bool operator<(const CallSite &CS) const
static bool setDoesNotAccessMemory(Function &F)
bool doesNotCapture(unsigned OpNo) const
Determine whether this data operand is not captured.
bool hasArgument(const Value *Arg) const
Returns true if this CallSite passes the given Value* as an argument to the called function...
unsigned getNumArgOperands() const
Attribute getAttribute(unsigned i, Attribute::AttrKind Kind) const
ImmutableCallSite(CallSite CS)
static bool isEqual(const CallSite &LHS, const CallSite &RHS)
bool doesNotAccessMemory(unsigned OpNo) const
bool isInvoke() const
Return true if a InvokeInst is enclosed.
void setCannotDuplicate()
static CallSite getTombstoneKey()
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
bool data_operands_empty() const
bool doesNotReadMemory() const
Determine if the call does not access or only writes memory.
ValTy * getArgument(unsigned ArgNo) const
OperandBundleUse getOperandBundleAt(unsigned Index) const
void removeAttribute(unsigned i, StringRef Kind)
FunctionType * getType(LLVMContext &Context, ID id, ArrayRef< Type *> Tys=None)
Return the function type for an intrinsic.
void setOnlyAccessesInaccessibleMemOrArgMem()
ImmutableCallSite(const InvokeInst *II)
bool onlyAccessesInaccessibleMemory() const
Determine if the function may only access memory that is inaccessible from the IR.
IterTy data_operands_begin() const
data_operands_begin/data_operands_end - Return iterators iterating over the call / invoke argument li...
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 ...
BBTy * getParent() const
Get the basic block containing the call site.
A range adaptor for a pair of iterators.
ImmutableCallSite(const CallInst *CI)
bool isBundleOperand(unsigned Idx) const
A lightweight accessor for an operand bundle meant to be passed around by value.
void addAttribute(unsigned i, Attribute::AttrKind Kind)
bool operator==(const CallSite &CS) const
bool doesNotAccessMemory() const
Determine if the call does not access memory.
user_iterator_impl< const User > const_user_iterator
amdgpu Simplify well known AMD library false Value Value * Arg
unsigned countOperandBundlesOfType(uint32_t ID) const
FunTy * getCaller() const
Return the caller function for this call site.
unsigned getNumOperandBundles() const
bool cannotDuplicate() const
Determine if the call can be duplicated.
#define CALLSITE_DELEGATE_SETTER(METHOD)
CallSiteBase(InvokeTy *II)
void getOperandBundlesAsDefs(SmallVectorImpl< OperandBundleDef > &Defs) const
iterator_range< IterTy > data_ops() 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)
bool doesNotThrow() const
Determine if the call cannot unwind.
void removeAttribute(unsigned i, Attribute::AttrKind Kind)
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 isByValOrInAllocaArgument(unsigned ArgNo) const
Determine whether this argument is passed by value or in an alloca.
Type * getType() const
Return the type of the instruction that generated this call site.
bool isByValArgument(unsigned ArgNo) const
Determine whether this argument is passed by value.
static void setCannotDuplicate(CoroIdInst *CoroId)
FunTy * getCalledFunction() const
Return the function being called if this is a direct call, otherwise return null (if it's an indirect...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
unsigned getRetAlignment() const
Extract the alignment of the return value.
bool isTailCall() const
Tests if this call site is marked as a tail call.
bool hasRetAttr(Attribute::AttrKind Kind) const
Return true if this return value has the given attribute.
Module * getParent()
Get the module that this global value is contained inside of...
LLVM Value Representation.
FunctionType * getFunctionType() const
void setOnlyReadsMemory()
unsigned getArgumentNo(Value::const_user_iterator I) const
Given a value use iterator, returns the argument that corresponds to it.
StringRef - Represent a constant reference to a string, i.e.
AttributeList getAttributes() const
Get the parameter attributes of the call.
bool isConvergent() const
Determine if the call is convergent.
ValTy * getReturnedArgOperand() const
bool isMustTailCall() const
Tests if this call site must be tail call optimized.
void setCalledFunction(Value *V)
Set the callee to the specified value.
void mutateFunctionType(FunctionType *Ty) const
void addParamAttr(unsigned ArgNo, Attribute::AttrKind Kind)
AttrKind
This enumeration lists the attributes that can be associated with parameters, function results...
bool onlyAccessesInaccessibleMemOrArgMem() const
Determine if the function may only access memory that is either inaccessible from the IR or pointed t...
bool isCallee(Value::const_user_iterator UI) const
Determine whether the passed iterator points to the callee operand's Use.