when its identity cannot be determined statically at compile time. For our
example, the coroutine frame will be:
-.. code-block:: llvm
+.. code-block:: text
%f.frame = type { void (%f.frame*)*, void (%f.frame*)*, i32 }
Matching LLVM code would look like (with the rest of the code remaining the same
as the code in the previous section):
-.. code-block:: llvm
+.. code-block:: text
loop:
%n.addr = phi i32 [ %n, %entry ], [ %inc, %loop.resume ]
a coroutine handle as a parameter and resume the coroutine once async
operation is finished.
-.. code-block:: llvm
+.. code-block:: text
void g() {
for (;;)
should be stored in the coroutine frame, so that it can be resumed at the
correct resume point):
-.. code-block:: llvm
+.. code-block:: text
if.true:
%save1 = call token @llvm.coro.save(i8* %hdl)
The following coroutine designates a 32 bit integer `promise` and uses it to
store the current value produced by a coroutine.
-.. code-block:: llvm
+.. code-block:: text
define i8* @f(i32 %n) {
entry:
Example (normal suspend point):
"""""""""""""""""""""""""""""""
-.. code-block:: llvm
+.. code-block:: text
%0 = call i8 @llvm.coro.suspend(token none, i1 false)
switch i8 %0, label %suspend [i8 0, label %resume
Example (final suspend point):
""""""""""""""""""""""""""""""
-.. code-block:: llvm
+.. code-block:: text
while.end:
%s.final = call i8 @llvm.coro.suspend(token none, i1 true)
a different thread possibly prior to `async_op` call returning control back
to the coroutine:
-.. code-block:: llvm
+.. code-block:: text
%save1 = call token @llvm.coro.save(i8* %hdl)
call void async_op1(i8* %hdl)
A frontend can create parameter copies for `a` and `b` as follows:
-.. code-block:: C++
+.. code-block:: text
task<int> f(A a', A b') {
a = alloca A;