23#include "llvm/Support/MathExtras.h"
24#include "llvm/Support/SaveAndRestore.h"
32class ConditionalEvaluationFinder
34 bool foundConditional =
false;
35 bool inResumeExpr =
false;
37 bool traverseSuspendExpr(CoroutineSuspendExpr *e) {
38 return TraverseStmt(e->
getCommonExpr()) && traverseResumeExpr(e);
43 bool traverseResumeExpr(CoroutineSuspendExpr *e) {
45 if (
auto *bind = dyn_cast_if_present<CXXBindTemporaryExpr>(resume))
46 resume = bind->getSubExpr();
47 llvm::SaveAndRestore inResume(inResumeExpr,
true);
48 return TraverseStmt(resume);
52 static bool needsCleanupScope(
const Stmt *s) {
53 ConditionalEvaluationFinder finder;
54 finder.TraverseStmt(
const_cast<Stmt *
>(s));
55 return finder.foundConditional;
58 static bool resumeExprDefersCleanups(
const CoroutineSuspendExpr &s) {
59 ConditionalEvaluationFinder finder;
60 finder.traverseResumeExpr(
const_cast<CoroutineSuspendExpr *
>(&s));
61 return finder.foundConditional;
66 bool shouldVisitImplicitCode()
const {
return true; }
68 bool VisitAbstractConditionalOperator(AbstractConditionalOperator *) {
69 foundConditional =
true;
73 bool VisitBinaryOperator(BinaryOperator *e) {
75 foundConditional =
true;
81 bool VisitCXXNewExpr(CXXNewExpr *e) {
86 foundConditional =
true;
96 if (init && !TraverseStmt(init))
100 bool TraverseBlockExpr(BlockExpr *) {
return true; }
101 bool TraverseStmtExpr(StmtExpr *) {
return true; }
103 bool TraverseGCCAsmStmt(GCCAsmStmt *s) {
105 if (!TraverseStmt(operand))
113 bool TraverseCoawaitExpr(CoawaitExpr *e) {
return traverseSuspendExpr(e); }
114 bool TraverseCoyieldExpr(CoyieldExpr *e) {
return traverseSuspendExpr(e); }
116 bool VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *) {
119 foundConditional =
true;
123 bool VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *e) {
126 foundConditional =
true;
141 struct alignas(EHScopeStack::ScopeStackAlignment) StorageUnit {
142 char bytes[EHScopeStack::ScopeStackAlignment];
144 llvm::SmallVector<StorageUnit, 8 *
sizeof(
void *) /
sizeof(StorageUnit)> data;
150 explicit SavedCleanup(EHCleanupScope &scope)
151 : size(scope.getCleanupSize()), activeFlag(scope.getActiveFlag()) {
152 unsigned cleanupKind = 0;
161 data.resize_for_overwrite(llvm::divideCeil(size,
sizeof(StorageUnit)));
165 const void *getData()
const {
return data.data(); }
166 size_t getSize()
const {
return size; }
168 Address getActiveFlag()
const {
return activeFlag; }
170 EHScopeStack::Cleanup *getCleanup() {
171 return reinterpret_cast<EHScopeStack::Cleanup *
>(data.data());
174 EHScopeStack::Cleanup::Flags getFlags()
const {
175 EHScopeStack::Cleanup::Flags flags;
190 return ConditionalEvaluationFinder::resumeExprDefersCleanups(s);
201 mlir::Location loc = builder.getUnknownLoc();
214 mlir::OpBuilder::InsertionGuard guard(builder);
217 builder.createFlagStore(loc,
false, active.
getPointer());
222 builder.createFlagStore(loc,
true, active.
getPointer());
233 assert(!cleanup.hasActiveFlag() &&
"cleanup already has active flag?");
234 cleanup.setActiveFlag(activeFlag);
236 cleanup.setTestFlagInNormalCleanup(cleanup.isNormalCleanup());
237 cleanup.setTestFlagInEHCleanup(cleanup.isEHCleanup());
242 : cgf(cgf), cleanups(cgf), scope(
nullptr),
249 assert(s &&
"expected an AST root for a cleanup boundary");
250 if (ConditionalEvaluationFinder::needsCleanupScope(s)) {
251 mlir::Location loc = cgf.builder.getUnknownLoc();
252 cir::CleanupKind cleanupKind = cgf.getLangOpts().Exceptions
253 ? cir::CleanupKind::All
254 : cir::CleanupKind::Normal;
255 scope = cir::CleanupScopeOp::create(
256 cgf.builder, loc, cleanupKind,
258 [&](mlir::OpBuilder &b, mlir::Location loc) {},
260 [&](mlir::OpBuilder &b, mlir::Location loc) {});
261 cgf.builder.setInsertionPointToEnd(&scope.getBodyRegion().front());
266 cgf.currentFullExprCleanupScope = scope;
271 if (cgf.outermostConditional)
272 cgf.hiddenOutermostConditional = cgf.outermostConditional;
273 cgf.outermostConditional =
nullptr;
280 cir::CleanupScopeOp scope) {
287 auto cur = alloca->getParentOfType<cir::CleanupScopeOp>();
288 while (cur && cur != scope)
289 cur = cur->getParentOfType<cir::CleanupScopeOp>();
296 mlir::Block *parentBlock = scope->getBlock();
297 mlir::OpBuilder::InsertPoint ip =
299 alloca->moveBefore(parentBlock, ip.getPoint());
308 for (mlir::Operation *cur = ptr.getDefiningOp(); cur && cur != alloca;) {
309 auto cast = mlir::dyn_cast<cir::CastOp>(cur);
312 casts.push_back(
cast);
313 cur =
cast.getSrc().getDefiningOp();
316 mlir::Operation *prev = alloca;
317 for (cir::CastOp
cast : llvm::reverse(casts)) {
318 cast->moveAfter(prev);
331 cir::CleanupScopeOp scope = condScope.
scope;
334 bool hasDeferredCleanups = stack.size() > base;
338 mlir::OpBuilder::InsertionGuard guard(builder);
339 mlir::Block &lastBodyBlock = scope.getBodyRegion().back();
340 builder.setInsertionPointToEnd(&lastBodyBlock);
341 if (lastBodyBlock.empty() ||
342 !lastBodyBlock.back().hasTrait<mlir::OpTrait::IsTerminator>())
350 if (hasDeferredCleanups) {
352 llvm::make_range(stack.begin() + base, stack.end()))
357 mlir::OpBuilder::InsertionGuard guard(builder);
358 mlir::Block &cleanupBlock = scope.getCleanupRegion().front();
359 builder.setInsertionPointToEnd(&cleanupBlock);
362 llvm::reverse(llvm::make_range(stack.begin() + base, stack.end()))) {
363 if (entry.activeFlag.isValid()) {
371 assert(entry.addr.getUnderlyingAllocaOp() &&
372 (entry.addr.getUnderlyingAllocaOp()->getBlock() ==
373 entry.addr.getPointer().getDefiningOp()->getBlock()) &&
374 "alloca and cast are in different blocks");
375 mlir::Value flag = builder.
createLoad(scope.getLoc(), entry.activeFlag);
376 cir::IfOp::create(builder, scope.getLoc(), flag,
378 [&](mlir::OpBuilder &b, mlir::Location loc) {
379 cgf.emitDestroy(entry.addr, entry.type,
381 builder.createYield(loc);
384 cgf.
emitDestroy(entry.addr, entry.type, entry.destroyer);
390 stack.truncate(base);
396 mlir::Block *insertBlock = builder.getInsertionBlock();
398 scope.getBodyRegion().findAncestorBlockInRegion(*insertBlock))
399 builder.setInsertionPointAfter(scope);
404 assert(!exited &&
"FullExprCleanupScope::exit called twice");
407 cgf.currentFullExprCleanupScope = oldFullExprCleanupScope;
408 cgf.outermostConditional = oldOutermostConditional;
409 cgf.hiddenOutermostConditional = oldHiddenOutermostConditional;
411 size_t oldSize = deferredCleanupStackSize;
414 assert(cgf.conditionalCleanupScopes.size() == conditionalScopeDepth &&
415 "conditional cleanup scope opened without one to close it");
416 cgf.deferredConditionalCleanupStack.truncate(oldSize);
417 cleanups.forceCleanup(valuesToReload);
423 for (mlir::Value *valPtr : valuesToReload) {
424 mlir::Value val = *valPtr;
429 Address temp = cgf.createDefaultAlignTempAlloca(val.getType(), val.getLoc(),
431 tempAllocas.push_back(temp);
432 cgf.builder.createStore(val.getLoc(), val, temp);
438 while (cgf.conditionalCleanupScopes.size() > conditionalScopeDepth)
440 cgf.conditionalCleanupScopes.pop_back_val());
445 cleanups.forceCleanupExceptLifetimeExtended();
449 mlir::OpBuilder::InsertionGuard guard(cgf.builder);
450 mlir::Block &lastBodyBlock = scope.getBodyRegion().back();
451 cgf.builder.setInsertionPointToEnd(&lastBodyBlock);
452 if (lastBodyBlock.empty() ||
453 !lastBodyBlock.back().hasTrait<mlir::OpTrait::IsTerminator>())
454 cgf.builder.createYield(scope.getLoc());
461 mlir::OpBuilder::InsertionGuard guard(cgf.builder);
462 mlir::Block &cleanupBlock = scope.getCleanupRegion().front();
463 cgf.builder.setInsertionPointToEnd(&cleanupBlock);
464 cgf.builder.createYield(scope.getLoc());
467 assert(cgf.deferredConditionalCleanupStack.size() == oldSize &&
468 "deferred cleanups were not consumed by a conditional scope");
469 cgf.builder.setInsertionPointAfter(scope);
475 cleanups.forceLifetimeExtendedCleanups();
478 for (
auto [addr, valPtr] : llvm::zip(tempAllocas, valuesToReload)) {
481 *valPtr = cgf.builder.createLoad(valPtr->getLoc(), addr);
489void EHScopeStack::Cleanup::anchor() {}
493 stable_iterator si = getInnermostNormalCleanup();
494 stable_iterator se = stable_end();
497 if (cleanup.isActive())
499 si = cleanup.getEnclosingNormalCleanup();
505char *EHScopeStack::allocate(
size_t size) {
506 size = llvm::alignTo(size, ScopeStackAlignment);
507 if (!startOfBuffer) {
508 unsigned capacity = llvm::PowerOf2Ceil(std::max<size_t>(size, 1024ul));
509 startOfBuffer = std::make_unique<char[]>(capacity);
510 startOfData = endOfBuffer = startOfBuffer.get() + capacity;
511 }
else if (
static_cast<size_t>(startOfData - startOfBuffer.get()) < size) {
512 unsigned currentCapacity = endOfBuffer - startOfBuffer.get();
513 unsigned usedCapacity =
514 currentCapacity - (startOfData - startOfBuffer.get());
515 unsigned requiredCapacity = usedCapacity + size;
518 unsigned newCapacity = llvm::PowerOf2Ceil(requiredCapacity);
520 std::unique_ptr<char[]> newStartOfBuffer =
521 std::make_unique<char[]>(newCapacity);
522 char *newEndOfBuffer = newStartOfBuffer.get() + newCapacity;
523 char *newStartOfData = newEndOfBuffer - usedCapacity;
524 memcpy(newStartOfData, startOfData, usedCapacity);
525 startOfBuffer.swap(newStartOfBuffer);
526 endOfBuffer = newEndOfBuffer;
527 startOfData = newStartOfData;
530 assert(startOfBuffer.get() + size <= startOfData);
535void EHScopeStack::deallocate(
size_t size) {
536 startOfData += llvm::alignTo(size, ScopeStackAlignment);
544 bool skipCleanupScope =
false;
546 cir::CleanupKind cleanupKind = cir::CleanupKind::All;
547 if (isEHCleanup && cgf->getLangOpts().Exceptions) {
549 isNormalCleanup ? cir::CleanupKind::All : cir::CleanupKind::EH;
555 cleanupKind = cir::CleanupKind::Normal;
557 skipCleanupScope =
true;
563 if (capturingCleanups)
564 skipCleanupScope =
true;
566 cir::CleanupScopeOp cleanupScope =
nullptr;
567 if (!skipCleanupScope) {
568 CIRGenBuilderTy &builder = cgf->getBuilder();
569 mlir::Location loc = builder.getUnknownLoc();
570 cleanupScope = cir::CleanupScopeOp::create(
571 builder, loc, cleanupKind,
573 [&](mlir::OpBuilder &b, mlir::Location loc) {
577 [&](mlir::OpBuilder &b, mlir::Location loc) {
581 builder.setInsertionPointToEnd(&cleanupScope.getBodyRegion().back());
588 if (innermostEHScope != stable_end() &&
592 EHCleanupScope *scope =
new (buffer)
593 EHCleanupScope(isNormalCleanup, isEHCleanup, size, cleanupScope,
594 innermostNormalCleanup, innermostEHScope);
597 innermostNormalCleanup = stable_begin();
600 innermostEHScope = stable_begin();
602 if (isLifetimeMarker)
606 if (cgf->getLangOpts().EHAsynch && isEHCleanup && !isLifetimeMarker &&
607 cgf->getTarget().getCXXABI().isMicrosoft())
608 cgf->cgm.errorNYI(
"push seh cleanup");
614 assert(!empty() &&
"popping exception stack when not empty");
618 innermostNormalCleanup =
cleanup.getEnclosingNormalCleanup();
619 innermostEHScope =
cleanup.getEnclosingEHScope();
620 deallocate(
cleanup.getAllocatedSize());
622 cir::CleanupScopeOp cleanupScope =
cleanup.getCleanupScopeOp();
624 auto *block = &cleanupScope.getBodyRegion().back();
625 if (!block->mightHaveTerminator()) {
626 mlir::OpBuilder::InsertionGuard guard(cgf->getBuilder());
627 cgf->getBuilder().setInsertionPointToEnd(block);
628 cir::YieldOp::create(cgf->getBuilder(),
629 cgf->getBuilder().getUnknownLoc());
633 mlir::Block *insertBlock = cgf->getBuilder().getInsertionBlock();
635 cleanupScope.getBodyRegion().findAncestorBlockInRegion(*insertBlock))
636 cgf->getBuilder().setInsertionPointAfter(cleanupScope);
644 for (stable_iterator si = getInnermostEHScope(); si != stable_end();) {
645 if (
auto *cleanup = dyn_cast<EHCleanupScope>(&*find(si))) {
646 if (
cleanup->isLifetimeMarker()) {
648 si =
cleanup->getEnclosingEHScope();
661 mlir::Operation *dominatingIP) {
680 if (!var.isValid()) {
681 mlir::Location loc = builder.getUnknownLoc();
684 loc,
"cleanup.isactive");
687 assert(dominatingIP &&
"no existing variable and no dominating IP!");
690 mlir::Value val = builder.
getBool(
true, loc);
693 mlir::OpBuilder::InsertionGuard guard(builder);
694 builder.setInsertionPoint(dominatingIP);
702 mlir::Location loc = builder.getUnknownLoc();
711 return op->isProperAncestor(condScope.scope);
717 mlir::Operation *dominatingIP) {
718 assert(c !=
ehStack.stable_end() &&
"deactivating bottom of stack?");
720 assert(scope.
isActive() &&
"double deactivation");
725 if (c ==
ehStack.stable_begin() &&
740 Address activeFlag, mlir::Location loc) {
748 cir::IfOp::create(builder, loc, isActive,
751 [&](mlir::OpBuilder &, mlir::Location) {
752 cleanup->emit(cgf, flags);
754 "cleanup ended with no insertion point?");
758 cleanup->emit(cgf, flags);
759 assert(cgf.
haveInsertPoint() &&
"cleanup ended with no insertion point?");
764 EHScopeStack::Cleanup *cleanup,
768 mlir::Block &block = cleanupScope.getCleanupRegion().back();
770 mlir::OpBuilder::InsertionGuard guard(builder);
771 builder.setInsertionPointToStart(&block);
773 emitCleanupBody(cgf, cleanup, flags, activeFlag, cleanupScope.getLoc());
775 mlir::Block &cleanupRegionLastBlock = cleanupScope.getCleanupRegion().back();
776 if (cleanupRegionLastBlock.empty() ||
777 !cleanupRegionLastBlock.back().hasTrait<mlir::OpTrait::IsTerminator>()) {
778 mlir::OpBuilder::InsertionGuard guardCase(builder);
779 builder.setInsertionPointToEnd(&cleanupRegionLastBlock);
790 .walk([&](mlir::Operation *op) {
792 return mlir::WalkResult::interrupt();
793 return mlir::WalkResult::advance();
803 assert(!
ehStack.empty() &&
"cleanup stack is empty!");
813 "missing cir.cleanup.scope for active cleanup");
835 if (forDeactivation && requiresNormalCleanup) {
842 mlir::Location loc = builder.getUnknownLoc();
849 mlir::OpBuilder::InsertionGuard guard(builder);
850 builder.setInsertionPoint(cleanupScope);
851 builder.createFlagStore(loc,
true, activeFlag.
getPointer());
855 assert(builder.getInsertionBlock() ==
856 &cleanupScope.getBodyRegion().back() &&
857 "expected insertion point in cleanup body");
858 builder.createFlagStore(loc,
false, activeFlag.
getPointer());
865 if (requiresEHCleanup)
866 cleanupScope.setCleanupKind(cir::CleanupKind::EH);
867 requiresNormalCleanup =
false;
879 if (!requiresNormalCleanup && !requiresEHCleanup) {
884 mlir::Block &cleanupBlock = cleanupScope.getCleanupRegion().back();
885 if (!cleanupBlock.mightHaveTerminator()) {
886 mlir::OpBuilder::InsertionGuard guard(builder);
887 builder.setInsertionPointToEnd(&cleanupBlock);
888 cir::YieldOp::create(builder, builder.getUnknownLoc());
894 SavedCleanup cleanup(scope);
897 Address cleanupActiveFlag = normalActiveFlag.
isValid() ? normalActiveFlag
898 : ehActiveFlag.
isValid() ? ehActiveFlag
906 emitCleanup(*
this, cleanupScope, cleanup.getCleanup(), cleanup.getFlags(),
911 mlir::Location loc) {
916 while (
ehStack.stable_begin() != depth) {
920 "captured cleanup should not own a cleanup scope");
930 SavedCleanup cleanup(scope);
933 cleanup.getActiveFlag(), loc);
943 while (
ehStack.stable_begin() != depth) {
947 "captured cleanup should not own a cleanup scope");
948 assert(!scope.
hasActiveFlag() &&
"captured cleanup with an active flag");
949 captured.emplace_back(scope);
955 for (
const SavedCleanup &cleanup : llvm::reverse(captured)) {
956 ehStack.pushCopyOfCleanup(cleanup.getKind(), cleanup.getData(),
971 bool requiresCleanup =
false;
972 for (
auto it =
ehStack.begin(), ie =
ehStack.find(oldCleanupStackDepth);
975 requiresCleanup =
true;
984 if (requiresCleanup) {
985 for (mlir::Value *valPtr : valuesToReload) {
986 mlir::Value val = *valPtr;
994 tempAllocas.push_back(temp);
995 builder.createStore(val.getLoc(), val, temp);
1001 while (
ehStack.stable_begin() != oldCleanupStackDepth)
1005 if (requiresCleanup) {
1006 for (
auto [addr, valPtr] : llvm::zip(tempAllocas, valuesToReload)) {
1007 mlir::Location loc = valPtr->getLoc();
1008 *valPtr = builder.createLoad(loc, addr);
static void setupCleanupBlockDeactivation(CIRGenFunction &cgf, EHScopeStack::stable_iterator c, mlir::Operation *dominatingIP)
The given cleanup block is being deactivated.
static bool bodyHasBranchThroughExits(mlir::Region &bodyRegion)
Check whether a cleanup scope body contains any non-yield exits that branch through the cleanup.
static void closeConditionalCleanupScope(CIRGenFunction &cgf, const CIRGenFunction::ConditionalCleanupScope &condScope)
Close a cleanup scope opened by a ConditionalEvaluation.
static bool enclosesOpenConditionalCleanupScope(CIRGenFunction &cgf, EHCleanupScope &scope)
static void hoistAllocaOutOfCleanupScope(CIRGenFunction &cgf, Address addr, cir::CleanupScopeOp scope)
If the alloca that backs addr is currently nested inside the body region of scope,...
static void emitCleanupBody(CIRGenFunction &cgf, EHScopeStack::Cleanup *cleanup, EHScopeStack::Cleanup::Flags flags, Address activeFlag, mlir::Location loc)
static void emitCleanup(CIRGenFunction &cgf, cir::CleanupScopeOp cleanupScope, EHScopeStack::Cleanup *cleanup, EHScopeStack::Cleanup::Flags flags, Address activeFlag)
static Decl::Kind getKind(const Decl *D)
*collection of selector each with an associated kind and an ordered *collection of selectors A selector has a kind
__DEVICE__ void * memcpy(void *__a, const void *__b, size_t __c)
cir::ConstantOp getBool(bool state, mlir::Location loc)
cir::StoreOp createFlagStore(mlir::Location loc, bool val, mlir::Value dst)
static OpBuilder::InsertPoint getBestAllocaInsertPoint(mlir::Block *block)
cir::YieldOp createYield(mlir::Location loc, mlir::ValueRange value={})
Create a yield operation.
cir::LoadOp createFlagLoad(mlir::Location loc, mlir::Value addr)
Emit a load from an boolean flag variable.
cir::BoolType getBoolTy()
static bool isLogicalOp(Opcode Opc)
mlir::Value getPointer() const
cir::AllocaOp getUnderlyingAllocaOp() const
Return the underlying alloca for this address, if any.
cir::LoadOp createLoad(mlir::Location loc, Address addr, bool isVolatile=false, bool isNontemporal=false)
FullExprCleanupScope(CIRGenFunction &cgf, const Stmt *s)
s is the AST root for one cleanup boundary: a full-expression, an asm statement, or the construction ...
void exit(ArrayRef< mlir::Value * > valuesToReload={})
llvm::SmallVector< PendingCleanupEntry > lifetimeExtendedCleanupStack
ConditionalEvaluation * hiddenOutermostConditional
void initFullExprCleanup()
Set up the last cleanup that was pushed as a conditional full-expression cleanup.
void emitCapturedCleanups(EHScopeStack::stable_iterator depth, mlir::Location loc)
Emit the captured cleanups (those pushed above depth while EHScopeStack was capturing cleanups) at th...
mlir::Block * getCurFunctionEntryBlock()
bool isInConditionalBranch() const
void setBeforeOutermostConditional(mlir::Value value, Address addr)
void emitCapturedCleanupsAsScopes(EHScopeStack::stable_iterator depth, mlir::Location loc)
Like emitCapturedCleanups, but push the captured cleanups again as ordinary cleanups,...
ConditionalEvaluation * outermostConditional
static bool resumeExprDefersCleanups(const CoroutineSuspendExpr &s)
Whether the resume expression of s contains a construct that defers cleanups to the end of the enclos...
EHScopeStack ehStack
Tracks function scope overall cleanup handling.
llvm::SmallVector< PendingCleanupEntry > deferredConditionalCleanupStack
Cleanups for temporaries constructed inside a conditional.
llvm::SmallVector< ConditionalCleanupScope > conditionalCleanupScopes
void pushDestroy(QualType::DestructionKind dtorKind, Address addr, QualType type)
Push the standard destructor for the given type as at least a normal cleanup.
static Destroyer destroyCXXObject
void initFullExprCleanupWithFlag(Address activeFlag)
Address createCleanupActiveFlag()
Create an active flag variable for use with conditional cleanups.
void deactivateCleanupBlock(EHScopeStack::stable_iterator cleanup, mlir::Operation *dominatingIP)
Deactivates the given cleanup block.
bool haveInsertPoint() const
True if an insertion point is defined.
void emitCXXTemporary(const CXXTemporary *temporary, QualType tempType, Address ptr)
Emits all the code to cause the given temporary to be cleaned up.
void popCleanupBlocks(EHScopeStack::stable_iterator oldCleanupStackDepth, ArrayRef< mlir::Value * > valuesToReload={})
Takes the old cleanup stack size and emits the cleanup blocks that have been added.
CIRGenBuilderTy & getBuilder()
void emitDestroy(Address addr, QualType type, Destroyer *destroyer)
Immediately perform the destruction of the given object.
void pushPendingCleanupToEHStack(const PendingCleanupEntry &entry)
Promote a single pending cleanup entry onto the EH scope stack.
void popCleanupBlock(bool forDeactivation=false)
Pop a cleanup block from the stack.
cir::CleanupScopeOp currentFullExprCleanupScope
The cir.cleanup.scope of the innermost FullExprCleanupScope that materialized one,...
EHScopeStack::stable_iterator currentCleanupStackDepth
CIRGenFunction(CIRGenModule &cgm, CIRGenBuilderTy &builder, bool suppressNewContext=false)
Address createTempAllocaWithoutCast(mlir::Type ty, CharUnits align, mlir::Location loc, const Twine &name="tmp", mlir::Value arraySize=nullptr, mlir::OpBuilder::InsertPoint ip={})
This creates a alloca and inserts it into the entry block of the current region.
Address createDefaultAlignTempAlloca(mlir::Type ty, mlir::Location loc, const Twine &name)
CreateDefaultAlignTempAlloca - This creates an alloca with the default alignment of the corresponding...
A cleanup scope which generates the cleanup blocks lazily.
void setTestFlagInEHCleanup(bool value)
void setTestFlagInNormalCleanup(bool value)
Address getActiveFlag() const
bool isLifetimeMarker() const
cir::CleanupScopeOp getCleanupScopeOp()
bool shouldTestFlagInEHCleanup() const
static size_t getSizeForCleanupSize(size_t size)
Gets the size required for a lazy cleanup scope with the given cleanup-data requirements.
bool isNormalCleanup() const
bool hasActiveFlag() const
void setActiveFlag(Address var)
void * getCleanupBuffer()
bool shouldTestFlagInNormalCleanup() const
void setActive(bool isActive)
void setIsEHCleanupKind()
void setIsNormalCleanupKind()
A saved depth on the scope stack.
void popCleanup()
Pops a cleanup scope off the stack. This is private to CIRGenCleanup.cpp.
iterator find(stable_iterator savePoint) const
Turn a stable reference to a scope depth into a unstable pointer to the EH stack.
bool requiresCatchOrCleanup() const
stable_iterator getInnermostActiveNormalCleanup() const
bool hasInitializer() const
Whether this new-expression has any initializer at all.
bool shouldNullCheckAllocation() const
True if the allocation result needs to be null-checked.
Represents a C++ temporary.
static CharUnits One()
Construct a CharUnits quantity of one.
Represents an expression that might suspend coroutine execution; either a co_await or co_yield expres...
Expr * getResumeExpr() const
Expr * getCommonExpr() const
llvm::iterator_range< capture_init_iterator > capture_inits()
Retrieve the initialization expressions for this lambda's captures.
A (possibly-)qualified type.
DestructionKind isDestructedType() const
Returns a nonzero value if objects of this type require non-trivial work to clean up after.
A class that does preorder or postorder depth-first traversal on the entire Clang AST and visits each...
Stmt - This represents one statement.
@ EHCleanup
Denotes a cleanup that should run when a scope is exited using exceptional control flow (a throw stat...
@ NormalCleanup
Denotes a cleanup that should run when a scope is exited using normal control flow (falling off the e...
@ Address
A pointer to a ValueDecl.
Top level wrappers for InstallAPI frontend operations.
bool isa(CodeGen::Address addr)
if(T->getSizeExpr()) TRY_TO(TraverseStmt(const_cast< Expr * >(T -> getSizeExpr())))
nullptr
This class represents a compute construct, representing a 'Kind' of ‘parallel’, 'serial',...
U cast(CodeGen::Address addr)
One record per cir.cleanup.scope opened by a ConditionalEvaluation, as described above.
size_t deferredCleanupStackSize
The size of deferredConditionalCleanupStack when this scope was opened.
cir::CleanupScopeOp scope
A cleanup whose destructor call is not emitted where the cleanup is registered.