Add Async Function to the Async Dialect
authoryijiagu <yijiagu@google.com>
Wed, 2 Nov 2022 18:27:26 +0000 (11:27 -0700)
committerEugene Zhulenev <ezhulenev@google.com>
Wed, 2 Nov 2022 18:34:08 +0000 (11:34 -0700)
commit145d2a50b86fabe220284ca4a28b67cb8d26f1f1
tree0ef966682c5ef9ba8aac0bf42cf6cf0deb9e59e6
parent65b130e32cad56e5f11d6d172eb90437e1cedbf6
Add Async Function to the Async Dialect

Add Async Function to the Async Dialect

Today `async.execute` operation semantics requires attached region to be executed in a thread managed by the runtime, and always returns an `!async.token` result. We need to model async functions that are not necessarily executed in a runtime-managed threads, but eventually lowered to llvm coroutines.

Example:

```
async.func @foo(%arg0: !async.value<f32>) -> !async.token {
  %0 = async.await %arg0: !async.value<f32>
  "do_something_with_f32"(%0)
  return
}
```

If `arg0` is available this function will be executed in the caller thread. If it's not available it will be suspended and resumed later later on a thread managed by the async runtime. Currently this is not representable with `async.execute` operations.

The longer term goal is to make async dialect more like https://github.com/lewissbaker/cppcoro to be able to represent structured host concurrency in MLIR.

(1) Add async.func, async.call, and async.return operations in Async Dialect

Reviewed By: ezhulenev, rriddle

Differential Revision: https://reviews.llvm.org/D137189
mlir/include/mlir/Dialect/Async/IR/Async.h
mlir/include/mlir/Dialect/Async/IR/AsyncOps.td
mlir/lib/Dialect/Async/IR/Async.cpp
mlir/test/Dialect/Async/ops.mlir
mlir/test/Dialect/Async/verify.mlir
utils/bazel/llvm-project-overlay/mlir/BUILD.bazel