[llvm] [Coroutines] Documentation for custom ABIs (PR #111781)
Chuanqi Xu via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 9 20:07:15 PDT 2024
================
@@ -749,6 +750,65 @@ and python iterator `__next__` would look like:
return *(int*)coro.promise(hdl, 4, false);
}
+Custom ABIs and Plugin Libraries
+--------------------------------
+
+Plugin libraries can extend coroutine lowering enabling a wide variety of users
+to utilize the coroutine transformation passes. An existing coroutine lowering
+is extended by: 1. defining custom ABIs that inherit from the existing ABIs,
+2. give a list of generators for the custom ABIs when constructing the
+`CoroSplit`_ pass, and 3. use `coro.begin.custom.abi` in place of `coro.begin`
+with an additional parameter for the index of the generator/ABI to be used for
+the coroutine.
+
+A custom ABI overriding the SwitchABI's materialization looks like:
+
+.. code-block:: c++
+
+ class CustomSwitchABI : public coro::SwitchABI {
+ public:
+ CustomSwitchABI(Function &F, coro::Shape &S)
+ : coro::SwitchABI(F, S, ExtraMaterializable) {}
+ };
+
+Giving a list of custom ABI generators while constructing the `CoroSplit`
+pass looks like:
+
+.. code-block:: c++
+
+ CoroSplitPass::BaseABITy GenCustomABI = [](Function &F, coro::Shape &S) {
+ return new CustomSwitchABI(F, S);
----------------
ChuanqiXu9 wrote:
It looks not so good to return a raw new here. Can we turn it into std::make_unique?
https://github.com/llvm/llvm-project/pull/111781
More information about the llvm-commits
mailing list