16 #ifndef LLVM_IR_STATEPOINT_H 17 #define LLVM_IR_STATEPOINT_H 72 template <
typename FunTy,
typename InstructionTy,
typename ValueTy,
75 CallBaseTy *StatepointCall;
79 StatepointCall =
isStatepoint(I) ? cast<CallBaseTy>(
I) :
nullptr;
92 CalledFunctionPos = 2,
99 void *
operator new(
size_t s) =
delete;
101 explicit operator bool()
const {
103 return (
bool)StatepointCall;
108 assert(*
this &&
"check validity first!");
109 return StatepointCall;
113 return cast<ConstantInt>(getCall()->getArgOperand(FlagsPos))
119 const Value *IDVal = getCall()->getArgOperand(IDPos);
120 return cast<ConstantInt>(IDVal)->getZExtValue();
125 const Value *NumPatchBytesVal = getCall()->getArgOperand(NumPatchBytesPos);
126 uint64_t NumPatchBytes =
127 cast<ConstantInt>(NumPatchBytesVal)->getZExtValue();
129 return NumPatchBytes;
134 return getCall()->getArgOperand(CalledFunctionPos);
147 FunTy *
getCaller()
const {
return getCall()->getCaller(); }
152 return getCall()->doesNotThrow() || (F ? F->
doesNotThrow() :
false);
158 auto *FTy = cast<FunctionType>(
159 cast<PointerType>(getCalledValue()->getType())->getElementType());
160 return FTy->getReturnType();
165 const Value *NumCallArgsVal = getCall()->getArgOperand(NumCallArgsPos);
166 return cast<ConstantInt>(NumCallArgsVal)->getZExtValue();
169 size_t arg_size()
const {
return getNumCallArgs(); }
171 assert(CallArgsBeginPos <= (
int)getCall()->arg_size());
172 return getCall()->arg_begin() + CallArgsBeginPos;
175 auto I = arg_begin() + arg_size();
176 assert((getCall()->arg_end() -
I) >= 0);
181 assert(Index < arg_size() &&
"out of bounds!");
182 return *(arg_begin() +
Index);
193 return getCall()->paramHasAttr(i + CallArgsBeginPos, A) ||
199 const Value *NumGCTransitionArgs = *arg_end();
200 return cast<ConstantInt>(NumGCTransitionArgs)->getZExtValue();
203 auto I = arg_end() + 1;
204 assert((getCall()->arg_end() -
I) >= 0);
208 auto I = gc_transition_args_begin() + getNumTotalGCTransitionArgs();
209 assert((getCall()->arg_end() -
I) >= 0);
215 return make_range(gc_transition_args_begin(), gc_transition_args_end());
221 const Value *NumVMSArgs = *gc_transition_args_end();
222 return cast<ConstantInt>(NumVMSArgs)->getZExtValue();
226 auto I = gc_transition_args_end() + 1;
227 assert((getCall()->arg_end() -
I) >= 0);
231 auto I = deopt_begin() + getNumTotalVMSArgs();
232 assert((getCall()->arg_end() -
I) >= 0);
238 return make_range(deopt_begin(), deopt_end());
245 return gc_args_begin() - getCall()->op_begin();
250 return make_range(gc_args_begin(), gc_args_end());
257 std::vector<const GCRelocateInst *> getRelocates()
const;
263 for (
auto *U : getInstruction()->
users())
264 if (
auto *GRI = dyn_cast<GCResultInst>(U))
274 assert(getNumCallArgs() >= 0 &&
275 "number of arguments to actually callee can't be negative");
280 (void)gc_transition_args_begin();
281 (void)gc_transition_args_end();
284 (void)gc_args_begin();
293 :
public StatepointBase<const Function, const Instruction, const Value,
319 return I->
getIntrinsicID() == Intrinsic::experimental_gc_relocate ||
324 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
330 const Value *Token = getArgOperand(0);
332 return isa<LandingPadInst>(Token) || isa<InvokeInst>(Token);
337 const Value *Token = getArgOperand(0);
341 if (!isa<LandingPadInst>(Token)) {
343 return cast<CallBase>(Token);
348 cast<Instruction>(Token)->
getParent()->getUniquePredecessor();
350 assert(InvokeBB &&
"safepoints should have unique landingpads");
351 assert(InvokeBB->getTerminator() &&
352 "safepoint block should be well formed");
355 return cast<CallBase>(InvokeBB->getTerminator());
363 return I->
getIntrinsicID() == Intrinsic::experimental_gc_relocate;
367 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
374 return cast<ConstantInt>(getArgOperand(1))->getZExtValue();
380 return cast<ConstantInt>(getArgOperand(2))->getZExtValue();
384 return *(getStatepoint()->arg_begin() + getBasePtrIndex());
388 return *(getStatepoint()->arg_begin() + getDerivedPtrIndex());
400 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
404 template <
typename FunTy,
typename InstructionTy,
typename ValueTy,
406 std::vector<const GCRelocateInst *>
409 std::vector<const GCRelocateInst *> Result;
414 for (
const User *U : StatepointCall->
users())
415 if (
auto *Relocate = dyn_cast<GCRelocateInst>(U))
416 Result.push_back(Relocate);
419 if (!StatepointInvoke)
423 LandingPadInst *LandingPad = StatepointInvoke->getLandingPadInst();
426 for (
const User *LandingPadUser : LandingPad->
users()) {
427 if (
auto *Relocate = dyn_cast<GCRelocateInst>(LandingPadUser))
428 Result.push_back(Relocate);
441 static const uint64_t DefaultStatepointID = 0xABCDEF00;
442 static const uint64_t DeoptBundleStatepointID = 0xABCDEF0F;
455 #endif // LLVM_IR_STATEPOINT_H ImmutableStatepoint(const Instruction *I)
Represents calls to the gc.result intrinsic.
static bool classof(const Value *V)
ValueTy * getArgument(unsigned Index)
This class represents lattice values for constants.
Statepoint(Instruction *I)
StatepointFlags
The statepoint intrinsic accepts a set of flags as its third argument.
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...
Type * getActualReturnType() const
Return the type of the value returned by the call underlying the statepoint.
iterator_range< arg_iterator > gc_transition_args() const
range adapter for GC transition arguments
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
CallBaseTy * getCall() const
Return the underlying call instruction.
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.
typename CallBase ::const_op_iterator arg_iterator
const CallBase * getStatepoint() const
The statepoint with which this gc.relocate is associated.
void verify()
Asserts if this statepoint is malformed.
InstructionTy * getInstruction() const
iterator_range< arg_iterator > deopt_operands() const
range adapter for vm state arguments
Value * getDerivedPtr() const
StatepointBase(CallBaseTy *Call)
This file contains the simple types necessary to represent the attributes associated with functions a...
const GCResultInst * getGCResult() const
Get the experimental_gc_result call tied to this statepoint.
arg_iterator gc_args_begin() const
arg_iterator gc_transition_args_begin() const
static bool classof(const IntrinsicInst *I)
bool isStatepoint(const CallBase *Call)
iterator_range< arg_iterator > gc_args() const
range adapter for gc arguments
AttributeList getAttributes() const
Return the attribute list for this Function.
uint64_t getID() const
Return the ID associated with this statepoint.
arg_iterator deopt_end() const
The landingpad instruction holds all of the information necessary to generate correct exception handl...
LLVM Basic Block Representation.
The instances of the Type class are immutable: once they are created, they are never changed...
FunTy * getCalledFunction() const
Return the function being called if this is a direct call, otherwise return null (if it's an indirect...
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...
Optional< uint32_t > NumPatchBytes
FunTy * getCaller() const
Return the caller function for this statepoint.
arg_iterator arg_begin() const
arg_iterator gc_transition_args_end() const
A specialization of it's base class for read-write access to a gc.statepoint.
int getNumCallArgs() const
Number of arguments to be passed to the actual callee.
StatepointBase(InstructionTy *I)
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...
bool isGCRelocate(const CallBase *Call)
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)
Statepoint(CallBase *Call)
constexpr bool isInt< 32 >(int64_t x)
arg_iterator gc_args_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
iterator_range< user_iterator > users()
int getNumTotalGCTransitionArgs() const
Number of GC transition args.
Call sites that get wrapped by a gc.statepoint (currently only in RewriteStatepointsForGC and potenti...
static bool classof(const IntrinsicInst *I)
uint32_t getNumPatchBytes() const
Return the number of patchable bytes associated with this statepoint.
static bool classof(const Value *V)
iterator_range< arg_iterator > call_args() const
range adapter for call arguments
arg_iterator arg_end() const
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
std::vector< const GCRelocateInst * > getRelocates() const
Get list of all gc reloactes linked to this statepoint May contain several relocations for the same b...
uint64_t getFlags() const
bool paramHasAttr(unsigned i, Attribute::AttrKind A) const
Return true if the call or the callee has the given attribute.
ValueTy * getCalledValue() const
Return the value actually being called or invoked.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
ImmutableStatepoint(const CallBase *Call)
Represents calls to the gc.relocate intrinsic.
Mark the deopt arguments associated with the statepoint as only being "live-in".
LLVM Value Representation.
A wrapper around a GC intrinsic call, this provides most of the actual functionality for Statepoint a...
static const Function * getParent(const Value *V)
int getNumTotalVMSArgs() const
Number of additional arguments excluding those intended for garbage collection.
Value * getBasePtr() const
A bitmask that includes all valid flags.
bool isGCResult(const CallBase *Call)
arg_iterator deopt_begin() const
bool doesNotThrow() const
Determine if the statepoint cannot unwind.
A wrapper class for inspecting calls to intrinsic functions.
AttrKind
This enumeration lists the attributes that can be associated with parameters, function results...
unsigned gcArgsStartIdx() const