22 #define DEBUG_TYPE "coro-early" 38 : LowererBase(M), Builder(
Context),
50 void Lowerer::lowerResumeOrDestroy(
CallSite CS,
72 const DataLayout &DL = TheModule.getDataLayout();
74 DL.getStructLayout(SampleStruct)->getElementOffset(2), Alignement);
78 Builder.SetInsertPoint(Intrin);
80 Builder.CreateConstInBoundsGEP1_32(Int8Ty, Operand, Offset);
95 "resume function not at offset zero");
96 auto *FrameTy = Int8Ptr;
99 Builder.SetInsertPoint(II);
100 auto *BCI = Builder.CreateBitCast(Operand, FramePtrTy);
101 auto *
Load = Builder.CreateLoad(BCI);
102 auto *Cond = Builder.CreateICmpEQ(
Load, NullPtr);
118 auto *FnPtrTy = FnTy->getPointerTo();
119 FrameTy->
setBody({FnPtrTy, FnPtrTy});
124 "NoopCoro.ResumeDestroy", &M);
130 Constant* Values[] = {NoopFn, NoopFn};
134 "NoopCoro.Frame.Const");
137 Builder.SetInsertPoint(II);
138 auto *NoopCoroVoidPtr = Builder.CreateBitCast(NoopCoro, Int8Ptr);
149 if (
auto *CB = dyn_cast<CoroBeginInst>(U))
150 CB->setCannotDuplicate();
153 bool Lowerer::lowerEarlyIntrinsics(
Function &
F) {
154 bool Changed =
false;
163 case Intrinsic::coro_free:
164 CoroFrees.
push_back(cast<CoroFreeInst>(&I));
166 case Intrinsic::coro_suspend:
169 if (cast<CoroSuspendInst>(&I)->isFinal())
172 case Intrinsic::coro_end:
175 if (cast<CoroEndInst>(&I)->isFallthrough())
178 case Intrinsic::coro_noop:
179 lowerCoroNoop(cast<IntrinsicInst>(&I));
181 case Intrinsic::coro_id:
184 if (
auto *CII = cast<CoroIdInst>(&I)) {
185 if (CII->getInfo().isPreSplit()) {
188 CII->setCoroutineSelf();
189 CoroId = cast<CoroIdInst>(&
I);
193 case Intrinsic::coro_id_retcon:
194 case Intrinsic::coro_id_retcon_once:
197 case Intrinsic::coro_resume:
200 case Intrinsic::coro_destroy:
203 case Intrinsic::coro_promise:
204 lowerCoroPromise(cast<CoroPromiseInst>(&I));
206 case Intrinsic::coro_done:
207 lowerCoroDone(cast<IntrinsicInst>(&I));
218 CF->setArgOperand(0, CoroId);
234 std::unique_ptr<Lowerer> L;
238 bool doInitialization(
Module &M)
override {
240 "llvm.coro.id.retcon",
241 "llvm.coro.id.retcon.once",
249 "llvm.coro.suspend"}))
250 L = std::make_unique<Lowerer>(M);
258 return L->lowerEarlyIntrinsics(F);
265 return "Lower early coroutine intrinsics";
272 "Lower early coroutine intrinsics",
false,
false)
Pass interface - Implemented by all 'passes'.
SymbolTableList< Instruction >::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
A parsed version of the target data layout string in and methods for querying it. ...
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
This represents the llvm.coro.promise instruction.
This represents the llvm.coro.id instruction.
This class represents lattice values for constants.
A Module instance is used to store all the information related to an LLVM module. ...
void push_back(const T &Elt)
Like Internal, but omit from symbol table.
void setCallingConv(CallingConv::ID CC)
Set the calling convention of the call.
LLVMContext & getContext() const
All values hold a context through their type.
unsigned getAlignment() const
static ReturnInst * Create(LLVMContext &C, Value *retVal=nullptr, Instruction *InsertBefore=nullptr)
Value * getArgOperand(unsigned i) const
inst_iterator inst_begin(Function *F)
void setCannotDuplicate()
Class to represent struct types.
PointerType * getPointerTo(unsigned AddrSpace=0) const
Return a pointer to the current type.
INITIALIZE_PASS(CoroEarlyLegacy, "coro-early", "Lower early coroutine intrinsics", false, false) Pass *llvm
static StructType * get(LLVMContext &Context, ArrayRef< Type *> Elements, bool isPacked=false)
This static method is the primary way to create a literal StructType.
#define PREPARED_FOR_SPLIT
InstrTy * getInstruction() const
Type * getType() const
All values are typed, get the type of this value.
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
void setBody(ArrayRef< Type *> Elements, bool isPacked=false)
Specify a body for an opaque identified type.
Pass * createCoroEarlyLegacyPass()
Lower coroutine intrinsics that are not needed by later passes.
Class to represent pointers.
static bool runOnFunction(Function &F, bool PostInlining)
void setCallingConv(CallingConv::ID CC)
static Function * Create(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace, const Twine &N="", Module *M=nullptr)
void setCalledFunction(Value *V)
Set the callee to the specified value.
#define CORO_PRESPLIT_ATTR
The instances of the Type class are immutable: once they are created, they are never changed...
This is an important class for using LLVM in a threaded context.
This is an important base class in LLVM.
void initializeCoroEarlyLegacyPass(PassRegistry &)
Represent the analysis usage information of a pass.
static Type * getVoidTy(LLVMContext &C)
FunctionPass class - This class is used to implement most global optimizations.
static FunctionType * get(Type *Result, ArrayRef< Type *> Params, bool isVarArg)
This static method is the primary way of constructing a FunctionType.
static Constant * get(StructType *T, ArrayRef< Constant *> V)
bool isFromPromise() const
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
This represents the llvm.coro.free instruction.
bool declaresIntrinsics(const Module &M, const std::initializer_list< StringRef >)
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:
const Module * getModule() const
Return the module owning the function this instruction belongs to or nullptr it the function does not...
iterator_range< user_iterator > users()
Intrinsic::ID getIntrinsicID() const
Return the intrinsic ID of the intrinsic called by this CallSite, or Intrinsic::not_intrinsic if the ...
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
static void setCannotDuplicate(CoroIdInst *CoroId)
LLVM Value Representation.
Fast - This calling convention attempts to make calls as fast as possible (e.g.
static StructType * create(LLVMContext &Context, StringRef Name)
This creates an identified struct.
void addFnAttr(Attribute::AttrKind Kind)
Add function attributes to this function.
StringRef - Represent a constant reference to a string, i.e.
inst_iterator inst_end(Function *F)
static IntegerType * getInt8Ty(LLVMContext &C)
ValTy * getArgOperand(unsigned i) const
A wrapper class for inspecting calls to intrinsic functions.