14#include "mlir/Support/LLVM.h"
39 assert(!
curCoro.
data &&
"EmitCoroutineBodyStatement called twice?");
46 mlir::Value nullPtr) {
47 cir::IntType int32Ty = builder.getUInt32Ty();
52 mlir::Operation *builtin =
cgm.getGlobalValue(
cgm.builtinCoroId);
56 fnOp =
cgm.createCIRBuiltinFunction(
57 loc,
cgm.builtinCoroId,
58 cir::FuncType::get({int32Ty, voidPtrTy, voidPtrTy, voidPtrTy}, int32Ty),
60 assert(fnOp &&
"should always succeed");
65 return builder.createCallOp(loc, fnOp,
66 mlir::ValueRange{builder.getUInt32(newAlign, loc),
67 nullPtr, nullPtr, nullPtr});
71 cir::BoolType boolTy = builder.getBoolTy();
73 mlir::Operation *builtin =
cgm.getGlobalValue(
cgm.builtinCoroAlloc);
77 fnOp =
cgm.createCIRBuiltinFunction(loc,
cgm.builtinCoroAlloc,
78 cir::FuncType::get({uInt32Ty}, boolTy),
80 assert(fnOp &&
"should always succeed");
85 return builder.createCallOp(
86 loc, fnOp, mlir::ValueRange{
curCoro.data->coroId.getResult()});
91 mlir::Value coroframeAddr) {
92 mlir::Operation *builtin =
cgm.getGlobalValue(
cgm.builtinCoroBegin);
96 fnOp =
cgm.createCIRBuiltinFunction(
97 loc,
cgm.builtinCoroBegin,
98 cir::FuncType::get({uInt32Ty, voidPtrTy},
voidPtrTy),
100 assert(fnOp &&
"should always succeed");
105 return builder.createCallOp(
107 mlir::ValueRange{
curCoro.data->coroId.getResult(), coroframeAddr});
112 mlir::Location openCurlyLoc =
getLoc(
s.getBeginLoc());
113 cir::ConstantOp nullPtrCst = builder.getNullPtr(
voidPtrTy, openCurlyLoc);
115 auto fn = mlir::cast<cir::FuncOp>(
curFn);
116 fn.setCoroutine(
true);
129 openCurlyLoc,
"__coro_frame_addr",
132 mlir::Value storeAddr = coroFrame.
getPointer();
133 builder.CIRBaseBuilderTy::createStore(openCurlyLoc, nullPtrCst, storeAddr);
135 builder, openCurlyLoc, coroAlloc.getResult(),
137 [&](mlir::OpBuilder &
b, mlir::Location loc) {
138 builder.CIRBaseBuilderTy::createStore(
139 loc, emitScalarExpr(s.getAllocate()), storeAddr);
140 cir::YieldOp::create(builder, loc);
145 cir::LoadOp::create(builder, openCurlyLoc, allocaTy, storeAddr))
149 if (
s.getReturnStmtOnAllocFailure())
150 cgm.errorNYI(
"handle coroutine return alloc failure");
154 return mlir::success();
static void createCoroData(CIRGenFunction &cgf, CIRGenFunction::CGCoroInfo &curCoro, cir::CallOp coroId)
__device__ __2f16 float __ockl_bool s
mlir::Value getPointer() const
cir::CallOp emitCoroIDBuiltinCall(mlir::Location loc, mlir::Value nullPtr)
cir::AllocaOp createTempAlloca(mlir::Type ty, mlir::Location loc, const Twine &name="tmp", mlir::Value arraySize=nullptr, bool insertIntoFnEntryBlock=false)
This creates an alloca and inserts it into the entry block if ArraySize is nullptr,...
mlir::Location getLoc(clang::SourceLocation srcLoc)
Helpers to convert Clang's SourceLocation to a MLIR Location.
mlir::Operation * curFn
The current function or global initializer that is generated code for.
mlir::Type convertTypeForMem(QualType t)
cir::CallOp emitCoroAllocBuiltinCall(mlir::Location loc)
clang::ASTContext & getContext() const
mlir::LogicalResult emitCoroutineBody(const CoroutineBodyStmt &s)
cir::CallOp emitCoroBeginBuiltinCall(mlir::Location loc, mlir::Value coroframeAddr)
Represents the body of a coroutine.
Exposes information about the current target.
unsigned getNewAlign() const
Return the largest alignment for which a suitably-sized allocation with 'operator new(size_t)' is gua...
unsigned getCharWidth() const
Defines the clang::TargetInfo interface.
The JSON file list parser is used to communicate input to InstallAPI.
CanQual< Type > CanQualType
Represents a canonical, potentially-qualified type.
U cast(CodeGen::Address addr)
static bool emitBodyAndFallthrough()
static bool generateDebugInfo()
std::unique_ptr< CGCoroData > data
cir::PointerType voidPtrTy
void* in address space 0