================
@@ -4702,6 +4619,131 @@ def CIR_CoReturnOp : CIR_Op<"co_return", [
let hasLLVMLowering = false;
}
+//===----------------------------------------------------------------------===//
+// Coroutine intrinsics
+//===----------------------------------------------------------------------===//
+
+class CIR_CoroIntrinsicOp<string mnem, dag ins, dag outs,
+ list<Trait> traits = []>
+ : CIR_Op<"coro.intrinsic." # mnem, traits> {
+ let hasLLVMLowering = 1;
+ let arguments = ins;
+ let results = outs;
+
+ let assemblyFormat = [{
+ `(` operands `)` `:` functional-type(operands, results) attr-dict
+ }];
+}
+//===----------------------------------------------------------------------===//
+// Coroutine intrinsic IdOp
+//===----------------------------------------------------------------------===//
+
+// TODO: This operation should return an MLIR `token` once the type becomes
+// available. `CIR_UInt32` is used as a temporary placeholder.
+def CIR_CoroIntrinsicIdOp : CIR_CoroIntrinsicOp<"id",
+ (ins CIR_AnyIntType:$align, CIR_VoidPtrType:$promise,
+ CIR_VoidPtrType:$coroaddr, CIR_VoidPtrType:$fnaddrs),
+ (outs CIR_UInt32:$result)> {
+ let summary = "Represents llvm.coro.id";
+ let description = [{
+ Marks the beginning of a coroutine's lifetime and identifies it to the
+ rest of the coroutine intrinsics. Takes the required alignment of the
+ coroutine frame, a pointer to the coroutine promise (or null if none),
+ the address of the coroutine function itself, and an opaque pointer used
+ by the frontend to convey additional information to the coroutine
+ lowering passes (or null).
+
+ The result is a token that must be passed to every other
+ `coro.intrinsic.*` operation associated with this coroutine
+ (`coro.alloc`, `coro.begin`, `coro.free`, etc.), tying them all to the
+ same coroutine instance.
+ }];
+}
+
+//===----------------------------------------------------------------------===//
+// Coroutine intrinsic AllocOp
+//===----------------------------------------------------------------------===//
+
+def CIR_CoroIntrinsicAllocOp : CIR_CoroIntrinsicOp<"alloc",
+ (ins CIR_AnyIntType:$id),
+ (outs CIR_AnyBoolType:$result)> {
+ let summary = "Represents llvm.coro.alloc";
+ let description = [{
+ Queries whether the coroutine identified by `id` needs a dynamically
+ allocated frame. Returns `true` if the coroutine frame must be allocated,
+ or `false` otherwise.
+ }];
+}
+
+// TODO: Replace the `id` operand with MLIR's `token` type once it becomes
+// available. This operand corresponds to the token produced by `llvm.coro.id`.
+//===----------------------------------------------------------------------===//
+// Coroutine intrinsic BeginOp
+//===----------------------------------------------------------------------===//
+def CIR_CoroIntrinsicBeginOp : CIR_CoroIntrinsicOp<"begin",
+ (ins CIR_UInt32:$id, CIR_VoidPtrType:$coroframeAddr),
+ (outs CIR_VoidPtrType:$result)> {
+ let summary = "Represents llvm.coro.begin";
+ let description = [{
+ Initializes the coroutine frame using `coroframeAddr`. `id` is the token
+ from `coro.intrinsic.id`, and `coroframeAddr` points to the memory used
+ for the coroutine frame. Returns the coroutine handle.
+ }];
+}
+
+//===----------------------------------------------------------------------===//
+// Coroutine intrinsic EndOp
+//===----------------------------------------------------------------------===//
+def CIR_CoroIntrinsicEndOp : CIR_CoroIntrinsicOp<"end",
+ (ins CIR_VoidPtrType:$handle, CIR_AnyBoolType:$unwind),
+ (outs CIR_AnyBoolType:$result)> {
+ let summary = "Represents llvm.coro.end";
+ let description = [{
+ Marks a point at which a coroutine must be suspended or destroyed for the
+ last time, e.g. right before the coroutine returns control to its caller
+ for the final time, or along an exceptional unwind path. `handle` is the
+ coroutine handle produced by `coro.intrinsic.begin`, and `unwind`
+ indicates whether this occurrence of `coro.intrinsic.end` lies on the
+ unwind path (`true`) or the normal control-flow path (`false`).
+ }];
+}
+
+// TODO: Replace the `id` operand with MLIR's `token` type once it becomes
----------------
erichkeane wrote:
Here too? (OR, modify the one above?).
https://github.com/llvm/llvm-project/pull/211699
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits