25 #ifndef LLVM_LIB_TRANSFORMS_COROUTINES_COROINSTR_H 26 #define LLVM_LIB_TRANSFORMS_COROUTINES_COROINSTR_H 36 enum { FrameArg, IndexArg };
45 IndexFirst = RestartTrigger
50 int64_t
Index = getRawIndex()->getValue().getSExtValue();
51 assert(Index >= IndexFirst && Index < IndexLast &&
52 "unexpected CoroSubFnInst index argument");
57 return cast<ConstantInt>(getArgOperand(IndexArg));
65 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
77 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
86 if (
auto *CA = dyn_cast<CoroAllocInst>(U))
93 if (
auto *II = dyn_cast<IntrinsicInst>(U))
94 if (II->getIntrinsicID() == Intrinsic::coro_begin)
102 return ID == Intrinsic::coro_id ||
103 ID == Intrinsic::coro_id_retcon ||
104 ID == Intrinsic::coro_id_retcon_once;
108 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
114 enum { AlignArg, PromiseArg, CoroutineArg, InfoArg };
118 Value *
Arg = getArgOperand(PromiseArg);
119 return isa<ConstantPointerNull>(
Arg)
125 Value *
Arg = getArgOperand(PromiseArg);
126 setArgOperand(PromiseArg,
128 if (isa<AllocaInst>(Arg))
130 assert((isa<BitCastInst>(Arg) || isa<GetElementPtrInst>(Arg)) &&
131 "unexpected instruction designating the promise");
134 auto *Inst = cast<Instruction>(
Arg);
135 if (Inst->use_empty()) {
136 Inst->eraseFromParent();
139 Inst->moveBefore(getCoroBegin()->getNextNode());
168 assert(GV->isConstant() && GV->hasDefinitiveInitializer());
169 Constant *Initializer = GV->getInitializer();
170 if ((Result.
OutlinedParts = dyn_cast<ConstantStruct>(Initializer)))
173 Result.
Resumers = cast<ConstantArray>(Initializer);
177 return cast<Constant>(getArgOperand(InfoArg)->stripPointerCasts());
183 return cast<Function>(getArgOperand(CoroutineArg)->stripPointerCasts());
186 assert(isa<ConstantPointerNull>(getArgOperand(CoroutineArg)) &&
187 "Coroutine argument is already assigned");
189 setArgOperand(CoroutineArg,
198 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
205 enum { SizeArg, AlignArg, StorageArg, PrototypeArg, AllocArg, DeallocArg };
208 void checkWellFormed()
const;
211 return cast<ConstantInt>(getArgOperand(SizeArg))->getZExtValue();
215 return cast<ConstantInt>(getArgOperand(AlignArg))->getZExtValue();
219 return getArgOperand(StorageArg);
226 return cast<Function>(getArgOperand(PrototypeArg)->stripPointerCasts());
231 return cast<Function>(getArgOperand(AllocArg)->stripPointerCasts());
236 return cast<Function>(getArgOperand(DeallocArg)->stripPointerCasts());
242 return ID == Intrinsic::coro_id_retcon
243 ||
ID == Intrinsic::coro_id_retcon_once;
246 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
259 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
272 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
284 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
290 enum { IdArg, FrameArg };
300 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
306 enum { IdArg, MemArg };
310 return cast<AnyCoroIdInst>(getArgOperand(IdArg));
320 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
332 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
338 enum { FrameArg, AlignArg, FromArg };
342 return cast<Constant>(getArgOperand(FromArg))->isOneValue();
345 return cast<ConstantInt>(getArgOperand(AlignArg))->getZExtValue();
353 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
367 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
373 enum { SaveArg, FinalArg };
377 Value *
Arg = getArgOperand(SaveArg);
378 if (
auto *
SI = dyn_cast<CoroSaveInst>(Arg))
380 assert(isa<ConstantTokenNone>(Arg));
385 return cast<Constant>(getArgOperand(FinalArg))->isOneValue();
393 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
398 if (
auto Suspend = dyn_cast<CoroSuspendInst>(
this))
399 return Suspend->getCoroSave();
413 return make_range(value_begin(), value_end());
416 return make_range(value_begin(), value_end());
424 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
436 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
442 enum { FrameArg, UnwindArg };
447 return cast<Constant>(getArgOperand(UnwindArg))->isOneValue();
455 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
461 enum { SizeArg, AlignArg };
464 return getArgOperand(SizeArg);
467 return cast<ConstantInt>(getArgOperand(AlignArg))->getZExtValue();
475 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
484 return cast<CoroAllocaAllocInst>(getArgOperand(AllocArg));
492 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
501 return cast<CoroAllocaAllocInst>(getArgOperand(AllocArg));
509 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
IntrinsicInst * getCoroBegin()
This represents the llvm.coro.suspend.retcon instruction.
static bool classof(const IntrinsicInst *I)
static bool classof(const Value *V)
unsigned getAlignment() const
This represents the llvm.coro.alloca.get instruction.
This represents the llvm.coro.promise instruction.
This represents the llvm.coro.id instruction.
This class represents lattice values for constants.
static bool classof(const Value *V)
static bool classof(const IntrinsicInst *I)
static bool classof(const IntrinsicInst *I)
static bool classof(const IntrinsicInst *I)
unsigned getAlignment() const
ConstantInt * getRawIndex() const
This represents the llvm.coro.alloca.alloc instruction.
static bool classof(const IntrinsicInst *I)
Value * getStorage() const
static bool classof(const IntrinsicInst *I)
static bool classof(const Value *V)
A Use represents the edge between a Value definition and its users.
This represents the llvm.coro.alloca.free instruction.
This represents the llvm.coro.suspend instruction.
Function * getAllocFunction() const
Return the function to use for allocating memory.
static bool classof(const IntrinsicInst *I)
AllocaInst * getPromise() const
This class represents the llvm.coro.subfn.addr instruction.
ConstantStruct * OutlinedParts
static bool classof(const IntrinsicInst *I)
This represents the llvm.coro.alloc instruction.
static bool classof(const IntrinsicInst *I)
uint64_t getStorageAlignment() const
static bool classof(const Value *V)
static bool classof(const Value *V)
bool isFallthrough() const
static bool classof(const Value *V)
static Function * getFunction(Constant *C)
This represents either the llvm.coro.id.retcon or llvm.coro.id.retcon.once instruction.
const_op_iterator value_end() const
static Constant * getBitCast(Constant *C, Type *Ty, bool OnlyIfReduced=false)
iterator_range< const_op_iterator > value_operands() const
This represents a common base class for llvm.coro.id instructions.
This represents the llvm.coro.size instruction.
static ConstantPointerNull * get(PointerType *T)
Static factory methods - Return objects of the specified value.
This is an important base class in LLVM.
ResumeKind getIndex() const
static bool classof(const Value *V)
This represents the llvm.coro.end instruction.
iterator_range< op_iterator > value_operands()
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
bool isFromPromise() const
This represents the llvm.coro.save instruction.
#define LLVM_LIBRARY_VISIBILITY
LLVM_LIBRARY_VISIBILITY - If a class marked with this attribute is linked into a shared library...
static bool classof(const Value *V)
This represents the llvm.coro.id.retcon.once instruction.
static bool classof(const Value *V)
const Value * stripPointerCasts() const
Strip off pointer casts, all-zero GEPs and address space casts.
static PointerType * getInt8PtrTy(LLVMContext &C, unsigned AS=0)
This represents the llvm.coro.free instruction.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
static bool classof(const IntrinsicInst *I)
CoroAllocInst * getCoroAlloc()
Intrinsic::ID getIntrinsicID() const
Return the intrinsic ID of this intrinsic.
Function * getDeallocFunction() const
Return the function to use for deallocating memory.
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
static bool classof(const IntrinsicInst *I)
AnyCoroIdInst * getId() const
static bool classof(const Value *V)
This is the shared class of boolean and integer constants.
Function * getPrototype() const
Return the prototype for the continuation function.
static bool classof(const IntrinsicInst *I)
CoroSaveInst * getCoroSave() const
static bool classof(const Value *V)
bool hasOutlinedParts() const
CoroAllocaAllocInst * getAlloc() const
op_iterator value_begin()
const_op_iterator value_begin() const
This class represents the llvm.coro.begin instruction.
A range adaptor for a pair of iterators.
static bool classof(const Value *V)
ConstantArray - Constant Array Declarations.
CoroAllocaAllocInst * getAlloc() const
static bool classof(const Value *V)
static bool classof(const IntrinsicInst *I)
static bool classof(const IntrinsicInst *I)
This represents the llvm.coro.id.retcon instruction.
static bool classof(const Value *V)
static bool classof(const Value *V)
uint64_t getStorageSize() const
static bool classof(const IntrinsicInst *I)
static bool classof(const IntrinsicInst *I)
static bool classof(const Value *V)
static bool classof(const IntrinsicInst *I)
Function * getCoroutine() const
static bool classof(const Value *V)
static bool classof(const IntrinsicInst *I)
static bool classof(const IntrinsicInst *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)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This represents the llvm.coro.frame instruction.
LLVM Value Representation.
static bool classof(const Value *V)
void setInfo(Constant *C)
static bool classof(const Value *V)
static bool classof(const IntrinsicInst *I)
static bool classof(const Value *V)
CoroSaveInst * getCoroSave() const
A wrapper class for inspecting calls to intrinsic functions.
an instruction to allocate memory on the stack
Constant * getRawInfo() const