Skip to content

[llvm][documentation] Fix coroutines documentation #66420

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions llvm/docs/Coroutines.rst
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ Outlined resume part of the coroutine will reside in function `f.resume`:
entry:
%inc.spill.addr = getelementptr %f.frame, ptr %frame.ptr.resume, i64 0, i32 2
%inc.spill = load i32, ptr %inc.spill.addr, align 4
%inc = add i32 %n.val, 1
%inc = add i32 %inc.spill, 1
store i32 %inc, ptr %inc.spill.addr, align 4
tail call void @print(i32 %inc)
ret void
Expand Down Expand Up @@ -494,8 +494,13 @@ as the code in the previous section):
i8 1, label %cleanup]

In this case, the coroutine frame would include a suspend index that will
indicate at which suspend point the coroutine needs to resume. The resume
function will use an index to jump to an appropriate basic block and will look
indicate at which suspend point the coroutine needs to resume.

.. code-block:: llvm

%f.frame = type { ptr, ptr, i32, i32 }

The resume function will use an index to jump to an appropriate basic block and will look
as follows:

.. code-block:: llvm
Expand All @@ -507,10 +512,11 @@ as follows:
%switch = icmp eq i8 %index, 0
%n.addr = getelementptr inbounds %f.Frame, ptr %FramePtr, i64 0, i32 3
%n = load i32, ptr %n.addr, align 4

br i1 %switch, label %loop.resume, label %loop

loop.resume:
%sub = xor i32 %n, -1
%sub = sub nsw i32 0, %n
call void @print(i32 %sub)
br label %suspend
loop:
Expand Down Expand Up @@ -586,7 +592,7 @@ correct resume point):
%save2 = call token @llvm.coro.save(ptr %hdl)
call void @async_op2(ptr %hdl)
%suspend2 = call i1 @llvm.coro.suspend(token %save2, i1 false)
switch i8 %suspend1, label %suspend [i8 0, label %resume2
switch i8 %suspend2, label %suspend [i8 0, label %resume2
i8 1, label %cleanup]

.. _coroutine promise:
Expand Down