Skip to content

Commit 7a472a0

Browse files
NoodleSugarNoodleSugarChuanqiXu9
authored
[llvm][documentation] Fix coroutines documentation (#66420)
Co-authored-by: NoodleSugar <[email protected]> Co-authored-by: Chuanqi Xu <[email protected]>
1 parent b2cd9db commit 7a472a0

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

llvm/docs/Coroutines.rst

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ Outlined resume part of the coroutine will reside in function `f.resume`:
385385
entry:
386386
%inc.spill.addr = getelementptr %f.frame, ptr %frame.ptr.resume, i64 0, i32 2
387387
%inc.spill = load i32, ptr %inc.spill.addr, align 4
388-
%inc = add i32 %n.val, 1
388+
%inc = add i32 %inc.spill, 1
389389
store i32 %inc, ptr %inc.spill.addr, align 4
390390
tail call void @print(i32 %inc)
391391
ret void
@@ -494,8 +494,13 @@ as the code in the previous section):
494494
i8 1, label %cleanup]
495495
496496
In this case, the coroutine frame would include a suspend index that will
497-
indicate at which suspend point the coroutine needs to resume. The resume
498-
function will use an index to jump to an appropriate basic block and will look
497+
indicate at which suspend point the coroutine needs to resume.
498+
499+
.. code-block:: llvm
500+
501+
%f.frame = type { ptr, ptr, i32, i32 }
502+
503+
The resume function will use an index to jump to an appropriate basic block and will look
499504
as follows:
500505

501506
.. code-block:: llvm
@@ -507,10 +512,11 @@ as follows:
507512
%switch = icmp eq i8 %index, 0
508513
%n.addr = getelementptr inbounds %f.Frame, ptr %FramePtr, i64 0, i32 3
509514
%n = load i32, ptr %n.addr, align 4
515+
510516
br i1 %switch, label %loop.resume, label %loop
511517
512518
loop.resume:
513-
%sub = xor i32 %n, -1
519+
%sub = sub nsw i32 0, %n
514520
call void @print(i32 %sub)
515521
br label %suspend
516522
loop:
@@ -586,7 +592,7 @@ correct resume point):
586592
%save2 = call token @llvm.coro.save(ptr %hdl)
587593
call void @async_op2(ptr %hdl)
588594
%suspend2 = call i1 @llvm.coro.suspend(token %save2, i1 false)
589-
switch i8 %suspend1, label %suspend [i8 0, label %resume2
595+
switch i8 %suspend2, label %suspend [i8 0, label %resume2
590596
i8 1, label %cleanup]
591597
592598
.. _coroutine promise:

0 commit comments

Comments
 (0)