23 #define DEBUG_TYPE "coro-early"
37 : LowererBase(M), Builder(
Context),
49 void Lowerer::lowerResumeOrDestroy(
CallSite CS,
73 DL.getStructLayout(SampleStruct)->getElementOffset(2), Alignement);
77 Builder.SetInsertPoint(Intrin);
79 Builder.CreateConstInBoundsGEP1_32(Int8Ty, Operand, Offset);
93 auto *FrameTy = Int8Ptr;
96 Builder.SetInsertPoint(II);
97 auto *BCI = Builder.CreateBitCast(Operand, FramePtrTy);
98 auto *Gep = Builder.CreateConstInBoundsGEP1_32(FrameTy, BCI, 0);
99 auto *
Load = Builder.CreateLoad(Gep);
100 auto *Cond = Builder.CreateICmpEQ(
Load, NullPtr);
112 if (
auto *CB = dyn_cast<CoroBeginInst>(U))
113 CB->setCannotDuplicate();
116 bool Lowerer::lowerEarlyIntrinsics(
Function &
F) {
117 bool Changed =
false;
126 case Intrinsic::coro_free:
127 CoroFrees.
push_back(cast<CoroFreeInst>(&I));
129 case Intrinsic::coro_suspend:
132 if (cast<CoroSuspendInst>(&I)->isFinal())
135 case Intrinsic::coro_end:
138 if (cast<CoroEndInst>(&I)->isFallthrough())
141 case Intrinsic::coro_id:
144 if (
auto *CII = cast<CoroIdInst>(&I)) {
145 if (CII->getInfo().isPreSplit()) {
148 CII->setCoroutineSelf();
149 CoroId = cast<CoroIdInst>(&
I);
153 case Intrinsic::coro_resume:
156 case Intrinsic::coro_destroy:
159 case Intrinsic::coro_promise:
160 lowerCoroPromise(cast<CoroPromiseInst>(&I));
162 case Intrinsic::coro_done:
163 lowerCoroDone(cast<IntrinsicInst>(&I));
174 CF->setArgOperand(0, CoroId);
188 std::unique_ptr<Lowerer>
L;
192 bool doInitialization(
Module &M)
override {
194 "llvm.coro.done",
"llvm.coro.end",
195 "llvm.coro.free",
"llvm.coro.promise",
196 "llvm.coro.resume",
"llvm.coro.suspend"}))
197 L = llvm::make_unique<Lowerer>(M);
201 bool runOnFunction(
Function &F)
override {
205 return L->lowerEarlyIntrinsics(F);
Pass interface - Implemented by all 'passes'.
SymbolTableList< Instruction >::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
void push_back(const T &Elt)
A parsed version of the target data layout string in and methods for querying it. ...
This represents the llvm.coro.promise instruction.
This represents the llvm.coro.alloc instruction.
A Module instance is used to store all the information related to an LLVM module. ...
Pass * createCoroEarlyPass()
Lower coroutine intrinsics that are not needed by later passes.
uint64_t alignTo(uint64_t Value, uint64_t Align, uint64_t Skew=0)
Returns the next integer (mod 2**64) that is greater than or equal to Value and is a multiple of Alig...
unsigned getAlignment() const
inst_iterator inst_begin(Function *F)
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
static FunctionType * get(Type *Result, ArrayRef< Type * > Params, bool isVarArg)
This static method is the primary way of constructing a FunctionType.
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
Class to represent pointers.
#define CORO_PRESPLIT_ATTR
The instances of the Type class are immutable: once they are created, they are never changed...
Represent the analysis usage information of a pass.
static Type * getVoidTy(LLVMContext &C)
void setCallingConv(CallingConv::ID CC)
FunctionPass class - This class is used to implement most global optimizations.
This represents the llvm.coro.free instruction.
void setCannotDuplicate()
InstrTy * getInstruction() const
static StructType * get(LLVMContext &Context, ArrayRef< Type * > Elements, bool isPacked=false)
This static method is the primary way to create a literal StructType.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Module.h This file contains the declarations for the Module class.
#define UNPREPARED_FOR_SPLIT
void setPreservesCFG()
This function should be called by the pass, iff they do not:
bool isFromPromise() const
Value * getArgOperand(unsigned i) const
getArgOperand/setArgOperand - Return/set the i-th call argument.
iterator_range< user_iterator > users()
INITIALIZE_PASS(CoroEarly,"coro-early","Lower early coroutine intrinsics", false, false) Pass *llvm
static void setCannotDuplicate(CoroIdInst *CoroId)
Intrinsic::ID getIntrinsicID() const
Return the intrinsic ID of the intrinsic called by this CallSite, or Intrinsic::not_intrinsic if the ...
LLVM Value Representation.
ValTy * getArgOperand(unsigned i) const
bool declaresIntrinsics(Module &M, std::initializer_list< StringRef >)
void addFnAttr(Attribute::AttrKind Kind)
Add function attributes to this function.
PointerType * getPointerTo(unsigned AddrSpace=0) const
Return a pointer to the current type.
inst_iterator inst_end(Function *F)
Fast - This calling convention attempts to make calls as fast as possible (e.g.
static IntegerType * getInt8Ty(LLVMContext &C)
void setCalledFunction(Value *V)
setCalledFunction - Set the callee to the specified value.
A wrapper class for inspecting calls to intrinsic functions.