14#include "mlir/Support/LLVM.h"
68struct GetParamRef :
public StmtVisitor<GetParamRef> {
73 assert(
expr ==
nullptr &&
"multilple declref in param move");
76 void VisitStmt(
Stmt *s) {
87struct ParamReferenceReplacerRAII {
92 : localDeclMap(localDeclMap) {}
94 void addCopy(
const DeclStmt *pm) {
98 const VarDecl *vd =
static_cast<const VarDecl *
>(pm->
getSingleDecl());
99 const Expr *initExpr = vd->
getInit();
101 visitor.Visit(
const_cast<Expr *
>(initExpr));
102 assert(visitor.expr);
103 DeclRefExpr *dreOrig = visitor.expr;
106 auto it = localDeclMap.find(pd);
107 assert(it != localDeclMap.end() &&
"parameter is not found");
108 savedLocals.insert({pd, it->second});
110 auto copyIt = localDeclMap.find(vd);
111 assert(copyIt != localDeclMap.end() &&
"parameter copy is not found");
112 it->second = copyIt->getSecond();
115 ~ParamReferenceReplacerRAII() {
116 for (
auto &&savedLocal : savedLocals) {
117 localDeclMap.insert({savedLocal.first, savedLocal.second});
133 cir::CoroIdOp coroId,
134 CallExpr const *coroIdExpr =
nullptr) {
138 cgf.
cgm.
error(coroIdExpr->getBeginLoc(),
139 "only one __builtin_coro_id can be used in a function");
141 cgf.
cgm.
error(coroIdExpr->getBeginLoc(),
142 "__builtin_coro_id shall not be used in a C++ coroutine");
144 llvm_unreachable(
"EmitCoroutineBodyStatement called twice?");
154static mlir::LogicalResult
164 if (cgf.
emitStmt(body,
true).failed())
165 return mlir::failure();
176 const bool canFallthrough = !currLexScope->
hasCoreturn();
179 if (cgf.
emitStmt(onFallthrough,
true).failed())
180 return mlir::failure();
182 return mlir::success();
192 auto coroId = cir::CoroIdOp::create(
cgm.getBuilder(), loc, args);
200 cgm.error(e->
getBeginLoc(),
"this builtin expect that __builtin_coro_id has"
201 " been used earlier in this function");
205 return cir::CoroAllocOp::create(
206 cgm.getBuilder(), loc,
207 mlir::ValueRange{curCoro.data->coroId.getResult()});
214 cgm.error(e->
getBeginLoc(),
"this builtin expect that __builtin_coro_id has"
215 " been used earlier in this function");
219 args.push_back(
curCoro.data->coroId.getResult());
223 auto coroBegin = cir::CoroBeginOp::create(
cgm.getBuilder(), loc, args);
224 curCoro.data->coroBegin = coroBegin;
235 args.push_back(cir::TokenNoneOp::create(builder, loc));
236 return cir::CoroEndOp::create(builder, loc, {
cgm.voidTy}, args);
243 cgm.error(e->
getBeginLoc(),
"this builtin expect that __builtin_coro_id has"
244 " been used earlier in this function");
249 cir::CoroFreeOp::create(
cgm.getBuilder(), loc,
250 mlir::ValueRange{curCoro.data->coroId.getResult(),
251 curCoro.data->coroBegin});
253 curCoro.data->lastCoroFree = coroFree;
259 return cir::CoroSizeOp::create(
cgm.getBuilder(), loc,
265 return cir::CoroAlignOp::create(
cgm.getBuilder(), loc,
277 auto coroPromise = cir::CoroPromiseOp::create(
cgm.getBuilder(), loc, args);
283 return cir::CoroDoneOp::create(
cgm.getBuilder(), loc,
289 return cir::CoroResumeOp::create(
cgm.getBuilder(), loc,
296 return cir::CoroDestroyOp::create(
cgm.getBuilder(), loc,
302 return cir::CoroNoopOp::create(
cgm.getBuilder(), loc);
309 args.push_back(cir::TokenNoneOp::create(builder, loc));
312 return cir::CoroSuspendOp::create(
cgm.getBuilder(), loc, args);
315static mlir::LogicalResult
329 ~handlerEmitter()
override =
default;
340 cir::ConstantOp nullPtrCst = builder.getNullPtr(
voidPtrTy, openCurlyLoc);
342 auto fn = mlir::cast<cir::FuncOp>(
curFn);
343 fn.setCoroutineKind(cir::CoroutineKind::Coroutine);
347 cir::CoroIdOp coroId = cir::CoroIdOp::create(
348 cgm.getBuilder(), openCurlyLoc,
349 mlir::ValueRange{builder.getUInt32(newAlign, openCurlyLoc), nullPtrCst,
350 nullPtrCst, nullPtrCst});
355 cir::CoroAllocOp coroAlloc = cir::CoroAllocOp::create(
356 cgm.getBuilder(), openCurlyLoc,
357 mlir::ValueRange{curCoro.data->coroId.getResult()});
364 openCurlyLoc,
"__coro_frame_addr",
367 mlir::Value storeAddr = coroFrame.
getPointer();
368 builder.CIRBaseBuilderTy::createStore(openCurlyLoc, nullPtrCst, storeAddr);
369 mlir::LogicalResult res = mlir::success();
371 builder, openCurlyLoc, coroAlloc.getResult(),
373 [&](mlir::OpBuilder &b, mlir::Location loc) {
374 mlir::Value allocatedPtr = emitScalarExpr(s.getAllocate());
375 builder.CIRBaseBuilderTy::createStore(loc, allocatedPtr, storeAddr);
377 if (Stmt *retOnAllocFailure = s.getReturnStmtOnAllocFailure()) {
378 mlir::Value isPtrNull = builder.createPtrIsNull(allocatedPtr);
379 assert(!cir::MissingFeatures::emitCondLikelihoodViaExpectIntrinsic());
380 cir::IfOp::create(builder, loc, isPtrNull, false,
381 [&](mlir::OpBuilder &b, mlir::Location loc) {
382 res = emitStmt(retOnAllocFailure,
384 cir::UnreachableOp::create(builder, loc);
387 cir::YieldOp::create(builder, loc);
393 curCoro.
data->coroBegin = cir::CoroBeginOp::create(
396 curCoro.data->coroId.getResult(),
397 cir::LoadOp::create(builder, openCurlyLoc, allocaTy, storeAddr)});
406 assert((paramMoves.size() == 0 || (paramMoves.size() ==
fnArgs.size())) &&
407 "ParamMoves and FnArgs should be the same size for coroutine "
417 CapturedCleanups frameCleanups(*
this,
true);
419 bool frameDestructorMayThrow =
false;
420 auto emitFrameObject = [&](
const VarDecl &var) {
423 frameDestructorMayThrow =
true;
430 for (
auto *pm : paramMoves) {
433 paramReplacer.addCopy(paramMove);
437 auto initialSuspendBuilder = [&]() -> mlir::LogicalResult {
438 emitFrameObject(*s.getPromiseDecl());
443 mlir::OpBuilder::InsertionGuard guard(builder);
444 builder.setInsertionPoint(coroId);
447 coroId.getPromiseMutable().assign(promisePtr);
451 assert(
returnValue.isValid() == (
bool)s.getReturnStmt());
466 s.getReturnValue()->getType().getQualifiers(),
470 curCoro.data->currentAwaitKind = cir::AwaitKind::Init;
471 curCoro.data->exceptionHandler = s.getExceptionHandler();
473 if (
emitStmt(s.getInitSuspendStmt(),
true).failed())
474 return mlir::failure();
476 cir::YieldOp::create(builder, openCurlyLoc);
477 return mlir::success();
482 auto bodyBuilder = [&]() -> mlir::LogicalResult {
484 curCoro.data->currentAwaitKind = cir::AwaitKind::User;
486 if (
curCoro.data->exceptionHandler) {
502 if (
curCoro.data->resumeEHVar.isValid()) {
503 mlir::Value shouldSkip = builder.createFlagLoad(
504 openCurlyLoc,
curCoro.data->resumeEHVar.getPointer());
505 mlir::LogicalResult res = mlir::success();
506 cir::IfOp::create(builder, openCurlyLoc, shouldSkip,
508 [&](mlir::OpBuilder &b, mlir::Location loc) {
510 builder.createYield(openCurlyLoc);
514 return mlir::failure();
517 return mlir::failure();
521 return mlir::failure();
524 return mlir::success();
529 auto finalSuspendBuilder = [&]() -> mlir::LogicalResult {
538 const bool canFallthrough =
curLexScope->hasCoreturn();
539 const bool hasCoreturns =
curCoro.data->coreturnCount > 0;
540 if (canFallthrough || hasCoreturns) {
541 curCoro.data->currentAwaitKind = cir::AwaitKind::Final;
542 if (
emitStmt(s.getFinalSuspendStmt(),
true)
544 return mlir::failure();
546 cir::YieldOp::create(builder, openCurlyLoc);
547 return mlir::success();
551 auto emitDeallocate = [&]() -> mlir::LogicalResult {
552 Stmt *deallocate = s.getDeallocate();
553 if (
emitStmt(deallocate,
true).failed()) {
555 "failed to emit coroutine deallocation expression");
556 return mlir::failure();
559 cir::CoroFreeOp coroFree =
curCoro.data->lastCoroFree;
563 "Deallocation expression does not refer to coro.free");
564 return mlir::failure();
567 mlir::OpBuilder::InsertionGuard guard(builder);
568 builder.setInsertionPointAfter(coroFree);
569 mlir::Value isPtrNotNull =
570 builder.createPtrIsNotNull(coroFree.getResult());
572 llvm::SmallVector<mlir::Operation *> opsToMove;
573 mlir::Block *block = builder.getInsertionBlock();
574 mlir::Block::iterator it(isPtrNotNull.getDefiningOp());
576 for (++it; it != block->end(); ++it)
577 opsToMove.push_back(&*it);
579 auto ifOp = cir::IfOp::create(
582 [&](mlir::OpBuilder &builder, mlir::Location loc) {
583 cir::YieldOp::create(builder, loc);
586 mlir::Operation *yieldOp = ifOp.getThenRegion().back().getTerminator();
587 for (
auto *op : opsToMove)
588 op->moveBefore(yieldOp);
590 return mlir::success();
600 auto destroyBuilder = [&]() -> mlir::LogicalResult {
602 !frameDestructorMayThrow) {
603 frameCleanups.emitIntoCleanupRegion(openCurlyLoc);
604 if (emitDeallocate().failed())
605 return mlir::failure();
606 cir::YieldOp::create(builder, openCurlyLoc);
607 return mlir::success();
610 mlir::LogicalResult deallocRes = mlir::success();
611 auto deallocScope = cir::CleanupScopeOp::create(
612 builder, openCurlyLoc, cir::CleanupKind::All,
613 [](mlir::OpBuilder &, mlir::Location) {},
615 [&](mlir::OpBuilder &b, mlir::Location loc) {
616 deallocRes = emitDeallocate();
617 cir::YieldOp::create(b, loc);
619 builder.setInsertionPointToEnd(&deallocScope.getBodyRegion().back());
620 frameCleanups.emitAsNestedScopes(openCurlyLoc);
621 cir::YieldOp::create(builder, openCurlyLoc);
622 builder.setInsertionPointAfter(deallocScope);
623 cir::YieldOp::create(builder, openCurlyLoc);
631 auto exitBuilder = [&]() {
632 cir::ConstantOp nullHandler =
633 builder.getNullPtr(builder.getVoidPtrTy(), openCurlyLoc);
634 cir::ConstantOp noUnwind = builder.getBool(
false, openCurlyLoc);
635 auto tkNone = cir::TokenNoneOp::create(builder, openCurlyLoc);
636 cir::CoroEndOp::create(builder, openCurlyLoc, nullHandler, noUnwind,
639 if (
auto *ret = cast_or_null<ReturnStmt>(s.getReturnStmt())) {
642 Expr *previousRetValue = ret->getRetValue();
643 ret->setRetValue(
nullptr);
645 return mlir::failure();
646 mlir::Block *block = builder.getInsertionBlock();
652 ret->setRetValue(previousRetValue);
654 cir::ReturnOp::create(builder, openCurlyLoc);
657 return mlir::success();
660 cir::CoroutineOp coro = cir::CoroutineOp::create(
661 builder, openCurlyLoc,
663 [&](mlir::OpBuilder &b, mlir::Location loc) {
664 if (initialSuspendBuilder().failed())
665 res = mlir::failure();
668 [&](mlir::OpBuilder &b, mlir::Location loc) {
669 if (bodyBuilder().failed())
670 res = mlir::failure();
673 [&](mlir::OpBuilder &b, mlir::Location loc) {
674 if (finalSuspendBuilder().failed())
675 res = mlir::failure();
678 [&](mlir::OpBuilder &b, mlir::Location loc) {
679 if (destroyBuilder().failed())
680 res = mlir::failure();
683 [&](mlir::OpBuilder &b, mlir::Location loc) {
684 if (exitBuilder().failed())
685 res = mlir::failure();
688 if (coro && !coro.getBody().empty()) {
689 mlir::Block &lastBlock = coro.getBody().back();
690 mlir::Block *prevBlock = lastBlock.getPrevNode();
691 if (lastBlock.empty() && lastBlock.hasNoPredecessors() && prevBlock &&
694 }
else if (!lastBlock.mightHaveTerminator()) {
695 mlir::OpBuilder::InsertionGuard guard(builder);
696 builder.setInsertionPointToEnd(&lastBlock);
697 cir::YieldOp::create(builder, openCurlyLoc);
714 if (
const auto *ce = dyn_cast<CallExpr>(s)) {
721 if (
const auto *te = dyn_cast<CXXBindTemporaryExpr>(s))
725 return llvm::any_of(s->
children(), [](
const Stmt *child) {
726 return child && stmtCanThrow(child);
747struct LValueOrRValue {
763 mlir::Block *scopeParentBlock,
764 mlir::Value &tmpResumeRValAddr,
bool forLValue) {
765 [[maybe_unused]] mlir::LogicalResult awaitBuild = mlir::success();
766 LValueOrRValue awaitRes;
781 std::optional<CIRGenFunction::ConditionalEvaluation> resumeEval;
782 const bool resumeDefersCleanups =
786 else if (resumeDefersCleanups)
788 "resume expression cleanups without a full-expression "
798 resultBind = dyn_cast<CXXBindTemporaryExpr>(s.
getResumeExpr());
811 [[maybe_unused]] cir::AwaitOp awaitOp = cir::AwaitOp::create(
814 [&](mlir::OpBuilder &b, mlir::Location loc) {
815 Expr *condExpr = s.getReadyExpr()->IgnoreParens();
816 builder.createCondition(cgf.evaluateExprAsBool(condExpr));
819 [&](mlir::OpBuilder &b, mlir::Location loc) {
824 switch (s.getSuspendReturnType()) {
825 case CoroutineSuspendExpr::SuspendReturnType::SuspendBool: {
826 mlir::Value suspendRet = cgf.evaluateExprAsBool(s.getSuspendExpr());
828 cir::CoroSuspendPoint::create(builder, loc, suspendRet);
831 case CoroutineSuspendExpr::SuspendReturnType::SuspendVoid:
832 cgf.emitScalarExpr(s.getSuspendExpr());
834 cir::CoroSuspendPoint::create(builder, loc);
836 case CoroutineSuspendExpr::SuspendReturnType::SuspendHandle:
837 cgf.cgm.errorNYI(s.getSourceRange(),
838 "await_suspend returning handle");
839 cir::CoroSuspendPoint::create(builder, loc);
844 [&](mlir::OpBuilder &b, mlir::Location loc) {
846 resumeEval->beginEvaluation();
858 ASTContext &ctx = cgf.getContext();
859 SourceLocation resumeLoc = s.getResumeExpr()->getExprLoc();
860 mlir::Location mlirLoc = cgf.getLoc(resumeLoc);
861 coro.resumeEHVar = cgf.createTempAlloca(
864 builder.createFlagStore(mlirLoc,
false,
865 coro.resumeEHVar.getPointer());
867 CXXCatchStmt catchStmt(resumeLoc,
868 nullptr, coro.exceptionHandler);
871 resumeLoc, resumeLoc);
872 CXXTryStmt *tryStmt =
875 struct resumeEmitter final : CIRGenFunction::cxxTryBodyEmitter {
876 const CXXTryStmt &tryStmt;
877 const Expr *resumeExpr;
879 mlir::Value resumeEHVar;
880 resumeEmitter(
const CXXTryStmt &tryStmt,
const Expr *resumeExpr,
881 mlir::Location loc, Address resumeEHVar)
882 : tryStmt(tryStmt), resumeExpr(resumeExpr), loc(loc),
883 resumeEHVar(resumeEHVar.getPointer()) {}
885 mlir::LogicalResult operator()(CIRGenFunction &cgf)
override {
888 CIRGenFunction::FullExprCleanupScope fullExpr(cgf, resumeExpr);
889 mlir::LogicalResult res =
890 cgf.
emitStmt(tryStmt.getTryBlock(),
true);
896 ~resumeEmitter()
override =
default;
897 } emitter{*tryStmt, s.getResumeExpr(), mlirLoc, coro.resumeEHVar};
903 }
else if (forLValue) {
904 awaitRes.lv = cgf.
emitLValue(s.getResumeExpr());
905 assert(awaitRes.lv.isSimple() &&
906 "expected simple lvalue for coroutine resume");
907 mlir::Value ptr = awaitRes.lv.getPointer();
908 llvm::StringRef tmpName =
kind == cir::AwaitKind::Yield
909 ?
"__coyield_resume_lval"
910 :
"__coawait_resume_lval";
913 builder.getBestAllocaInsertPoint(scopeParentBlock));
914 builder.CIRBaseBuilderTy::createStore(loc, ptr, tmpResumeRValAddr);
917 cgf.
emitAnyExpr(s.getResumeExpr(), aggSlot, ignoreResult);
918 if (!awaitRes.rv.isIgnored()) {
919 RValue rv = awaitRes.rv;
924 "__coawait_resume_rval", value.getType(), loc,
926 builder.getBestAllocaInsertPoint(scopeParentBlock));
928 builder.CIRBaseBuilderTy::createStore(loc, value,
931 assert(rv.
isAggregate() &&
"unexpected rvalue kind");
937 resumeEval->endEvaluation();
940 cir::YieldOp::create(builder, loc);
944 (resumeDefersCleanups && !resumeEval)) &&
945 "a resume expression cleanup was pushed in the resume region");
953 aggSlot.getAddress());
955 assert(awaitBuild.succeeded() &&
"Should know how to codegen");
973 [[maybe_unused]] mlir::Value tmpResumeRValAddr;
978 ignoreResult, currEntryBlock, tmpResumeRValAddr,
1001 bool ignoreResult) {
1008 bool ignoreResult) {
1017 assert(
isa<CallExpr>(re) &&
"unexpected suspend expression type");
1023 cir::AwaitKind
kind) {
1026 "Can't have a scalar return unless the return type is a "
1030 mlir::Value tmpResumeLValAddr;
1033 false, currEntryBlock,
1034 tmpResumeLValAddr,
true)
1036 if (!tmpResumeLValAddr) {
1038 "expected resume in try/catch");
1046 Address addr = lv.getAddress();
1047 mlir::Value loadedPtr =
1048 cir::LoadOp::create(cgf.
getBuilder(), scopeLoc,
1049 addr.
getPointer().getType(), tmpResumeLValAddr);
1063 ++
curCoro.data->coreturnCount;
1074 return mlir::failure();
1076 cir::CoReturnOp::create(builder, loc);
1081 builder.createBlock(builder.getBlock()->getParent());
1082 return mlir::success();
static void createCoroData(CIRGenFunction &cgf, CIRGenFunction::CGCoroInfo &curCoro, cir::CoroIdOp coroId, CallExpr const *coroIdExpr=nullptr)
static QualType getCoroutineSuspendExprReturnType(const ASTContext &ctx, const CoroutineSuspendExpr *e)
static LValueOrRValue emitSuspendExpression(CIRGenFunction &cgf, CGCoroData &coro, CoroutineSuspendExpr const &s, cir::AwaitKind kind, AggValueSlot aggSlot, bool ignoreResult, mlir::Block *scopeParentBlock, mlir::Value &tmpResumeRValAddr, bool forLValue)
static LValue emitSuspendLValue(CIRGenFunction &cgf, const CoroutineSuspendExpr *e, cir::AwaitKind kind)
static bool stmtCanThrow(const Stmt *s)
static RValue emitSuspendExpr(CIRGenFunction &cgf, const CoroutineSuspendExpr &e, cir::AwaitKind kind, AggValueSlot aggSlot, bool ignoreResult)
static bool functionCanThrow(const FunctionDecl *d)
static bool isResumeExprInTryCatch(const CGCoroData &coro, cir::AwaitKind kind, const CoroutineSuspendExpr &s)
static mlir::LogicalResult coroutineBodyExceptionHelper(CIRGenFunction &cgf, const CoroutineBodyStmt &s)
static mlir::LogicalResult emitBodyAndFallthrough(CIRGenFunction &cgf, const CoroutineBodyStmt &s, Stmt *body, const CIRGenFunction::LexicalScope *currLexScope)
*collection of selector each with an associated kind and an ordered *collection of selectors A selector has a kind
cir::StoreOp createFlagStore(mlir::Location loc, bool val, mlir::Value dst)
cir::PointerType getPointerTo(mlir::Type ty)
cir::ConstantOp getNullPtr(mlir::Type ty, mlir::Location loc)
mlir::Value createBitcast(mlir::Value src, mlir::Type newTy)
cir::PointerType getVoidPtrTy(clang::LangAS langAS=clang::LangAS::Default)
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
CharUnits getTypeAlignInChars(QualType T) const
Return the ABI-specified alignment of a (complete) type T, in characters.
Address withPointer(mlir::Value newPtr) const
Return address with different pointer, but same element type and alignment.
mlir::Value getPointer() const
mlir::Value emitRawPointer() const
Return the pointer contained in this class after authenticating it and adding offset to it if necessa...
IsDestructed_t isExternallyDestructed() const
void setExternallyDestructed(bool destructed=true)
static AggValueSlot ignored()
Returns an aggregate value slot indicating that the aggregate value is being ignored.
An RAII object to set (and then clear) a mapping for an OpaqueValueExpr.
Enters a new scope for capturing cleanups, all of which will be executed once the scope is exited.
mlir::Type convertType(clang::QualType t)
mlir::LogicalResult emitCoreturnStmt(const CoreturnStmt &s)
const clang::LangOptions & getLangOpts() const
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,...
cir::CoroAllocOp emitCoroAllocBuiltinCall(const CallExpr *e)
llvm::DenseMap< const clang::Decl *, Address > DeclMapTy
LValue emitLValue(const clang::Expr *e)
Emit code to compute a designator that specifies the location of the expression.
cir::CoroNoopOp emitCoroNoopBuiltinCall(const CallExpr *e)
Address getAddrOfLocalVar(const clang::VarDecl *vd)
Return the address of a local variable.
cir::CoroSuspendOp emitCoroSuspendBuiltinCall(const CallExpr *e)
LValue makeNaturalAlignAddrLValue(mlir::Value val, QualType ty)
mlir::Location getLoc(clang::SourceLocation srcLoc)
Helpers to convert Clang's SourceLocation to a MLIR Location.
cir::CoroBeginOp emitCoroBeginBuiltinCall(const CallExpr *e)
void emitAnyExprToMem(const Expr *e, Address location, Qualifiers quals, bool isInitializer)
Emits the code necessary to evaluate an arbitrary expression into the given memory location.
static bool resumeExprDefersCleanups(const CoroutineSuspendExpr &s)
Whether the resume expression of s contains a construct that defers cleanups to the end of the enclos...
RValue emitCoyieldExpr(const CoyieldExpr &e, AggValueSlot aggSlot=AggValueSlot::ignored(), bool ignoreResult=false)
cir::CoroFreeOp emitCoroFreeBuiltin(const CallExpr *e)
LValue emitCoawaitLValue(const CoawaitExpr *e)
mlir::Operation * curFn
The current function or global initializer that is generated code for.
EHScopeStack ehStack
Tracks function scope overall cleanup handling.
llvm::SmallVector< const ParmVarDecl * > fnArgs
Save Parameter Decl for coroutine.
AggValueSlot createAggTemp(QualType ty, mlir::Location loc, const Twine &name="tmp", Address *alloca=nullptr)
Create a temporary memory object for the given aggregate type.
mlir::Type convertTypeForMem(QualType t)
RValue emitCoroutineFrame()
mlir::Value emitAlloca(llvm::StringRef name, mlir::Type ty, mlir::Location loc, clang::CharUnits alignment, bool insertIntoFnEntryBlock, mlir::Value arraySize=nullptr)
mlir::LogicalResult emitCXXTryStmt(const clang::CXXTryStmt &s, cxxTryBodyEmitter &bodyCallback, bool isFnTryBlock=false)
cir::CoroPromiseOp emitCoroPromiseBuiltinCall(const CallExpr *e)
Address returnValue
The temporary alloca to hold the return value.
void emitAutoVarDeclWithCapturedCleanups(const clang::VarDecl &d, CapturedCleanups &cleanups, bool guardDestruction=false, llvm::ArrayRef< QualType > extendedTemporaries={})
Emit d with captured cleanups.
cir::CoroDestroyOp emitCoroDestroyBuiltinCall(const CallExpr *e)
static bool destructorMayThrow(QualType type)
Whether destroying an object of type type, or its elements if it is an array, may throw an exception.
cir::CoroEndOp emitCoroEndBuiltinCall(const CallExpr *e)
void emitCXXTemporary(const CXXTemporary *temporary, QualType tempType, Address ptr)
Emits all the code to cause the given temporary to be cleaned up.
LValue emitCoyieldLValue(const CoyieldExpr *e)
mlir::Value emitScalarExpr(const clang::Expr *e, bool ignoreResultAssign=false)
Emit the computation of the specified expression of scalar type.
CIRGenBuilderTy & getBuilder()
DeclMapTy localDeclMap
This keeps track of the CIR allocas or globals for local C declarations.
RValue emitCoawaitExpr(const CoawaitExpr &e, AggValueSlot aggSlot=AggValueSlot::ignored(), bool ignoreResult=false)
RValue emitAnyExpr(const clang::Expr *e, AggValueSlot aggSlot=AggValueSlot::ignored(), bool ignoreResult=false)
Emit code to compute the specified expression which can have any type.
cir::CoroSizeOp emitCoroSizeBuiltinCall(const CallExpr *e)
cir::CleanupScopeOp currentFullExprCleanupScope
The cir.cleanup.scope of the innermost FullExprCleanupScope that materialized one,...
cir::CoroDoneOp emitCoroDoneBuiltinCall(const CallExpr *e)
cir::CoroResumeOp emitCoroResumeBuiltinCall(const CallExpr *e)
cir::CoroAlignOp emitCoroAlignBuiltinCall(const CallExpr *e)
LexicalScope * curLexScope
cir::CoroIdOp emitCoroIDBuiltinCall(const CallExpr *e)
bool inEHSpecTerminateScope()
Whether the wrapper opened by emitStartEHSpec is a terminate scope, whose handler calls std::terminat...
clang::ASTContext & getContext() const
mlir::LogicalResult emitCoroutineBody(const CoroutineBodyStmt &s)
mlir::LogicalResult emitStmt(const clang::Stmt *s, bool useCurrentScope, llvm::ArrayRef< const Attr * > attrs={})
void emitIgnoredExpr(const clang::Expr *e)
Emit code to compute the specified expression, ignoring the result.
DiagnosticBuilder errorNYI(SourceLocation, llvm::StringRef)
Helpers to emit "not yet implemented" error diagnostics.
CIRGenBuilderTy & getBuilder()
void error(SourceLocation loc, llvm::StringRef error)
Emit a general error that something can't be done.
A saved depth on the scope stack.
stable_iterator stable_begin() const
Create a stable reference to the top of the EH stack.
This trivial value class is used to represent the result of an expression that is evaluated.
static RValue get(mlir::Value v)
static RValue getComplex(mlir::Value v)
mlir::Value getValue() const
Return the value of this scalar value.
mlir::Value getComplexValue() const
Return the value of this complex value.
static RValue getIgnored()
Represents binding an expression to a temporary.
CXXCatchStmt - This represents a C++ catch block.
static CXXTryStmt * Create(const ASTContext &C, SourceLocation tryLoc, CompoundStmt *tryBlock, ArrayRef< Stmt * > handlers)
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Expr * getArg(unsigned Arg)
getArg - Return the specified argument.
SourceLocation getBeginLoc() const
static CharUnits One()
Construct a CharUnits quantity of one.
Represents a 'co_await' expression.
static CompoundStmt * Create(const ASTContext &C, ArrayRef< Stmt * > Stmts, FPOptionsOverride FPFeatures, SourceLocation LB, SourceLocation RB)
Represents a 'co_return' statement in the C++ Coroutines TS.
Expr * getOperand() const
Retrieve the operand of the 'co_return' statement.
Expr * getPromiseCall() const
Retrieve the promise call that results from this 'co_return' statement.
Represents the body of a coroutine.
CompoundStmt * getBody() const
Retrieve the body of the coroutine as written.
Stmt * getFallthroughHandler() const
SourceLocation getBeginLoc() const LLVM_READONLY
Represents an expression that might suspend coroutine execution; either a co_await or co_yield expres...
Expr * getResumeExpr() const
OpaqueValueExpr * getOpaqueValue() const
getOpaqueValue - Return the opaque value placeholder.
Represents a 'co_yield' expression.
A reference to a declared variable, function, enum, etc.
bool isSingleDecl() const
isSingleDecl - This method returns true if this DeclStmt refers to a single Decl.
const Decl * getSingleDecl() const
This represents one expression.
Represents a function declaration or definition.
Represents a prototype with parameter type info, e.g.
A (possibly-)qualified type.
StmtVisitor - This class implements a simple visitor for Stmt subclasses.
Stmt - This represents one statement.
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
SourceLocation getBeginLoc() const LLVM_READONLY
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
bool isReferenceType() const
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
const T * getAs() const
Member-template getAs<specific type>'.
Represents a variable declaration or definition.
const Expr * getInit() const
Defines the clang::TargetInfo interface.
const internal::VariadicDynCastAllOfMatcher< Stmt, Expr > expr
Matches expressions.
Top level wrappers for InstallAPI frontend operations.
CanQual< Type > CanQualType
Represents a canonical, potentially-qualified type.
bool isa(CodeGen::Address addr)
bool isNoexceptExceptionSpec(ExceptionSpecificationType ESpecType)
U cast(CodeGen::Address addr)
static bool coroOutsideFrameMD()
static bool coroGetRetObjManager()
static bool generateDebugInfo()
static bool coroUnwindRegion()
cir::AwaitKind currentAwaitKind
CallExpr const * coroIdExpr
cir::CoroFreeOp lastCoroFree
std::unique_ptr< CGCoroData > data
Represents a scope, including function bodies, compound statements, and the substatements of if/while...
mlir::Block * getEntryBlock()
clang::CharUnits getPointerAlign() const
cir::PointerType voidPtrTy
void* in address space 0