[Arc] Add coroutine ops#10522
Conversation
Extend the Arc dialect with a set of `arc.coroutine.*` operations and types. These model suspendable coroutines similar to async/await fns in Rust. The compiler is expected to split the function at yield points, determine what local state needs to be persisted to the next re-entry, and then allow the coroutine to be polled using the persisted state and an indication of where to resume execution. The coroutine operations will later allow us to lower `llhd.process` and `llhd.coroutine` operations to `arc.coroutine.*`, and extend Arcilator to support concurrently executing these coroutines as a first step towards proper process support. This PR only adds operations, tests, and some rationale to the Arc dialect documentation.
|
|
||
| Both constructs are rewritten into a canonical outlined form: an `arc.coroutine.define` definition plus one or more call sites that re-enter it. | ||
| For a process, the call site is an `arc.coroutine.instance` placed in the enclosing `hw.module`. | ||
| For a coroutine, each `llhd.call_coroutine` becomes an `arc.coroutine.call` inside its parent coroutine's body. |
There was a problem hiding this comment.
Not blocking but could you use consistent naming for call_coroutine/coroutine.call in a follow-up?
There was a problem hiding this comment.
Yeah good idea 👍 I should probably tweak the LLHD dialect to match this.
|
I'm struggling to wrap my head around where and how the "persistent state"/"local state" (those refer to the same thing, right?) of the coroutine is specified. The language in
How are (region) arguments different from other SSA values? If an argument is used after a suspension point, isn't it then automatically part of the local state? How would we then access the new arguments passed in on re-entry? |
|
|
||
| // CHECK-LABEL: func.func @CoroutineCallWithResults | ||
| func.func @CoroutineCallWithResults( | ||
| %arg0: !arc.coroutine_state<@CoroutineWithResults>, |
There was a problem hiding this comment.
What's the rational to create separate SSA values for state/pc?
Extend the Arc dialect with a set of
arc.coroutine.*operations and types. These model suspendable coroutines similar to async/await fns in Rust. The compiler is expected to split the function at yield points, determine what local state needs to be persisted to the next re-entry, and then allow the coroutine to be polled using the persisted state and an indication of where to resume execution.The coroutine operations will later allow us to lower
llhd.processandllhd.coroutineoperations toarc.coroutine.*, and extend Arcilator to support concurrently executing these coroutines as a first step towards proper process support.This PR only adds operations, tests, and some rationale to the Arc dialect documentation.
Assisted-by: Claude Opus 4.7