================
@@ -1805,11 +1813,212 @@ class CIRTryOpFlattening : public
mlir::OpRewritePattern<cir::TryOp> {
}
};
+static mlir::Block *getOrCreateBlockForSuspendPoint(
+ cir::FuncOp funcOp, mlir::PatternRewriter &rewriter, mlir::Location loc) {
+ mlir::Block &entryBlock = funcOp.getBody().front();
+
+ auto it = llvm::find_if(entryBlock, [](auto &op) {
+ return mlir::isa<AllocaOp>(&op) &&
+ mlir::cast<AllocaOp>(&op).getCoroutineSuspendPoint();
+ });
+
+ assert(it->hasOneUse() &&
+ "coroutine suspend point alloca must have exactly one use");
+ auto storeOp = cast<cir::StoreOp>(*it->getUses().begin()->getOwner());
+ auto suspendPoint =
cast<cir::ConstantOp>(storeOp.getValue().getDefiningOp());
+ mlir::Block *suspendBlock = suspendPoint->getBlock();
+ if (&suspendBlock->front() == suspendPoint)
+ return suspendBlock;
+
+ mlir::OpBuilder::InsertionGuard guard(rewriter);
+ mlir::Block *remainingBlock =
+ rewriter.splitBlock(suspendBlock, suspendPoint->getIterator());
+ rewriter.setInsertionPointToEnd(suspendBlock);
+ cir::BrOp::create(rewriter, loc, remainingBlock);
+ return remainingBlock;
+}
+
+class CIRAwaitOpFlattening : public mlir::OpRewritePattern<cir::AwaitOp> {
+public:
+ using OpRewritePattern<cir::AwaitOp>::OpRewritePattern;
+
+ mlir::LogicalResult
+ matchAndRewrite(cir::AwaitOp awaitOp,
----------------
Andres-Salamanca wrote:
I've added comments explaining. Does this address your concern?
https://github.com/llvm/llvm-project/pull/203802
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits