17 #ifndef LLVM_IR_STATEPOINT_H 18 #define LLVM_IR_STATEPOINT_H 76 template <
typename FunTy,
typename InstructionTy,
typename ValueTy,
79 CallSiteTy StatepointCS;
84 StatepointCS = CallSiteTy(I);
85 assert(StatepointCS &&
"isStatepoint implies CallSite");
100 CalledFunctionPos = 2,
103 CallArgsBeginPos = 5,
107 void *
operator new(
size_t s) =
delete;
109 explicit operator bool()
const {
111 return (
bool)StatepointCS;
116 assert(*
this &&
"check validity first!");
121 return cast<ConstantInt>(getCallSite().getArgument(FlagsPos))
127 const Value *IDVal = getCallSite().getArgument(IDPos);
128 return cast<ConstantInt>(IDVal)->getZExtValue();
133 const Value *NumPatchBytesVal = getCallSite().getArgument(NumPatchBytesPos);
134 uint64_t NumPatchBytes =
135 cast<ConstantInt>(NumPatchBytesVal)->getZExtValue();
137 return NumPatchBytes;
142 return getCallSite().getArgument(CalledFunctionPos);
146 return getCallSite().getInstruction();
156 FunTy *
getCaller()
const {
return getCallSite().getCaller(); }
161 return getCallSite().doesNotThrow() || (F ? F->
doesNotThrow() :
false);
167 auto *FTy = cast<FunctionType>(
168 cast<PointerType>(getCalledValue()->getType())->getElementType());
169 return FTy->getReturnType();
174 const Value *NumCallArgsVal = getCallSite().getArgument(NumCallArgsPos);
175 return cast<ConstantInt>(NumCallArgsVal)->getZExtValue();
178 size_t arg_size()
const {
return getNumCallArgs(); }
180 assert(CallArgsBeginPos <= (
int)getCallSite().arg_size());
181 return getCallSite().arg_begin() + CallArgsBeginPos;
183 typename CallSiteTy::arg_iterator
arg_end()
const {
184 auto I = arg_begin() + arg_size();
185 assert((getCallSite().arg_end() -
I) >= 0);
190 assert(Index < arg_size() &&
"out of bounds!");
191 return *(arg_begin() +
Index);
202 return getCallSite().paramHasAttr(i + CallArgsBeginPos, A) ||
208 const Value *NumGCTransitionArgs = *arg_end();
209 return cast<ConstantInt>(NumGCTransitionArgs)->getZExtValue();
212 auto I = arg_end() + 1;
213 assert((getCallSite().arg_end() -
I) >= 0);
217 auto I = gc_transition_args_begin() + getNumTotalGCTransitionArgs();
218 assert((getCallSite().arg_end() -
I) >= 0);
224 return make_range(gc_transition_args_begin(), gc_transition_args_end());
230 const Value *NumVMSArgs = *gc_transition_args_end();
231 return cast<ConstantInt>(NumVMSArgs)->getZExtValue();
235 auto I = gc_transition_args_end() + 1;
236 assert((getCallSite().arg_end() -
I) >= 0);
240 auto I = deopt_begin() + getNumTotalVMSArgs();
241 assert((getCallSite().arg_end() -
I) >= 0);
247 return make_range(deopt_begin(), deopt_end());
254 return getCallSite().
arg_end();
258 return gc_args_begin() - getInstruction()->op_begin();
263 return make_range(gc_args_begin(), gc_args_end());
270 std::vector<const GCRelocateInst *> getRelocates()
const;
276 for (
auto *U : getInstruction()->
users())
277 if (
auto *GRI = dyn_cast<GCResultInst>(U))
287 assert(getNumCallArgs() >= 0 &&
288 "number of arguments to actually callee can't be negative");
293 (void)gc_transition_args_begin();
294 (void)gc_transition_args_end();
297 (void)gc_args_begin();
306 :
public StatepointBase<const Function, const Instruction, const Value,
338 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
344 const Value *Token = getArgOperand(0);
346 return isa<LandingPadInst>(Token) || isa<InvokeInst>(Token);
351 const Value *Token = getArgOperand(0);
355 if (!isa<LandingPadInst>(Token)) {
357 return cast<Instruction>(Token);
362 cast<Instruction>(Token)->
getParent()->getUniquePredecessor();
364 assert(InvokeBB &&
"safepoints should have unique landingpads");
365 assert(InvokeBB->getTerminator() &&
366 "safepoint block should be well formed");
369 return InvokeBB->getTerminator();
381 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
388 return cast<ConstantInt>(getArgOperand(1))->getZExtValue();
394 return cast<ConstantInt>(getArgOperand(2))->getZExtValue();
399 return *(CS.
arg_begin() + getBasePtrIndex());
404 return *(CS.
arg_begin() + getDerivedPtrIndex());
416 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
420 template <
typename FunTy,
typename InstructionTy,
typename ValueTy,
422 std::vector<const GCRelocateInst *>
426 std::vector<const GCRelocateInst *> Result;
428 CallSiteTy StatepointCS = getCallSite();
433 for (
const User *U : getInstruction()->
users())
434 if (
auto *Relocate = dyn_cast<GCRelocateInst>(U))
435 Result.push_back(Relocate);
437 if (!StatepointCS.isInvoke())
442 cast<InvokeInst>(getInstruction())->getLandingPadInst();
445 for (
const User *LandingPadUser : LandingPad->
users()) {
446 if (
auto *Relocate = dyn_cast<GCRelocateInst>(LandingPadUser))
447 Result.push_back(Relocate);
460 static const uint64_t DefaultStatepointID = 0xABCDEF00;
461 static const uint64_t DeoptBundleStatepointID = 0xABCDEF0F;
474 #endif // LLVM_IR_STATEPOINT_H FunTy * getCaller() const
Return the caller function for this statepoint.
ImmutableStatepoint(const Instruction *I)
Represents calls to the gc.result intrinsic.
static bool classof(const Value *V)
iterator_range< arg_iterator > gc_transition_args() const
range adapter for GC transition arguments
This class represents lattice values for constants.
Statepoint(Instruction *I)
StatepointFlags
The statepoint intrinsic accepts a set of flags as its third argument.
ValueTy * getCalledValue() const
Return the value actually being called or invoked.
StatepointDirectives parseStatepointDirectivesFromAttrs(AttributeList AS)
Parse out statepoint directives from the function attributes present in AS.
A specialization of it's base class for read only access to a gc.statepoint.
This provides a very simple, boring adaptor for a begin and end iterator into a range type...
uint64_t getID() const
Return the ID associated with this statepoint.
FunTy * getCalledFunction() const
Return the function being called if this is a direct call, otherwise return null (if it's an indirect...
CallSiteTy getCallSite() const
Return the underlying CallSite.
CallSiteTy::arg_iterator arg_begin() const
Common base class for representing values projected from a statepoint.
bool hasAttribute(unsigned Index, Attribute::AttrKind Kind) const
Return true if the attribute exists at the given index.
bool isGCRelocate(ImmutableCallSite CS)
CallSiteTy::arg_iterator arg_end() const
CallSiteTy::arg_iterator gc_args_begin() const
iterator_range< arg_iterator > deopt_operands() const
range adapter for vm state arguments
CallSiteTy::arg_iterator deopt_begin() const
CallSiteTy::arg_iterator gc_transition_args_end() const
CallSiteTy::arg_iterator gc_transition_args_begin() const
Value * getDerivedPtr() const
This file contains the simple types necessary to represent the attributes associated with functions a...
iterator_range< arg_iterator > call_args() const
range adapter for call arguments
InstructionTy * getInstruction() const
uint32_t getNumPatchBytes() const
Return the number of patchable bytes associated with this statepoint.
ValueTy * getArgument(unsigned Index)
CallSiteTy::arg_iterator gc_args_end() const
static bool classof(const IntrinsicInst *I)
AttributeList getAttributes() const
Return the attribute list for this Function.
bool doesNotThrow() const
Determine if the statepoint cannot unwind.
int getNumCallArgs() const
Number of arguments to be passed to the actual callee.
const Instruction * getStatepoint() const
The statepoint with which this gc.relocate is associated.
The landingpad instruction holds all of the information necessary to generate correct exception handl...
const GCResultInst * getGCResult() const
Get the experimental_gc_result call tied to this statepoint.
int getNumTotalGCTransitionArgs() const
Number of GC transition args.
LLVM Basic Block Representation.
The instances of the Type class are immutable: once they are created, they are never changed...
bool isTiedToInvoke() const
Return true if this relocate is tied to the invoke statepoint.
This file contains the declarations for the subclasses of Constant, which represent the different fla...
StatepointBase(CallSiteTy CS)
Optional< uint32_t > NumPatchBytes
void verify()
Asserts if this statepoint is malformed.
bool isGCResult(ImmutableCallSite CS)
A specialization of it's base class for read-write access to a gc.statepoint.
unsigned getBasePtrIndex() const
The index into the associate statepoint's argument list which contains the base pointer of the pointe...
unsigned getDerivedPtrIndex() const
The index into the associate statepoint's argument list which contains the pointer whose relocation t...
Intrinsic::ID getIntrinsicID() const
Return the intrinsic ID of this intrinsic.
bool doesNotThrow() const
Determine if the function cannot unwind.
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
static bool classof(const IntrinsicInst *I)
static bool classof(const Value *V)
constexpr bool isInt< 32 >(int64_t x)
CallSiteTy::arg_iterator deopt_end() const
Indicates that this statepoint is a transition from GC-aware code to code that is not GC-aware...
static const Function * getCalledFunction(const Value *V, bool LookThroughBitCast, bool &IsNoBuiltin)
A range adaptor for a pair of iterators.
bool isStatepointDirectiveAttr(Attribute Attr)
Return true if the Attr is an attribute that is a statepoint directive.
Optional< uint64_t > StatepointID
typename CallSite ::arg_iterator arg_iterator
iterator_range< user_iterator > users()
Call sites that get wrapped by a gc.statepoint (currently only in RewriteStatepointsForGC and potenti...
static bool classof(const IntrinsicInst *I)
Establish a view to a call site for examination.
static bool classof(const Value *V)
StatepointBase(InstructionTy *I)
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
ImmutableStatepoint(ImmutableCallSite CS)
std::vector< const GCRelocateInst * > getRelocates() const
Get list of all gc reloactes linked to this statepoint May contain several relocations for the same b...
Type * getActualReturnType() const
Return the type of the value returned by the call underlying the statepoint.
bool isStatepoint(ImmutableCallSite CS)
bool paramHasAttr(unsigned i, Attribute::AttrKind A) const
Return true if the call or the callee has the given attribute.
int getNumTotalVMSArgs() const
Number of additional arguments excluding those intended for garbage collection.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Represents calls to the gc.relocate intrinsic.
Mark the deopt arguments associated with the statepoint as only being "live-in".
LLVM Value Representation.
Analogous to CallSiteBase, this provides most of the actual functionality for Statepoint and Immutabl...
static const Function * getParent(const Value *V)
iterator_range< arg_iterator > gc_args() const
range adapter for gc arguments
unsigned gcArgsStartIdx() const
Value * getBasePtr() const
uint64_t getFlags() const
A bitmask that includes all valid flags.
A wrapper class for inspecting calls to intrinsic functions.
AttrKind
This enumeration lists the attributes that can be associated with parameters, function results...