================
@@ -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();
----------------
Andres-Salamanca wrote:

Hi Andy,
I tried implementing this, but it doesn't seem to work because I can't branch 
to the suspend-point block. The verifier rejects it with:
```text
reference to block defined in another region
```
So I'm a little stuck on what the appropriate way to represent a suspend point 
would be.
One idea I had was to introduce something like a `cir.label` or a dedicated 
`cir.suspend.point` op to mark the suspend point. The downside is that I would 
then need to walk the function to find that marker during flattening, which is 
something I was hoping to avoid. That's also why I originally used the uses of 
the alloca to recover the suspend point.

Do you think something along those lines would make sense, or do you have a 
better idea for representing the suspend point?


https://github.com/llvm/llvm-project/pull/203802
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to