https://github.com/ChuanqiXu9 updated https://github.com/llvm/llvm-project/pull/66420
>From 71c5d851d2b14022434fb6533ec7418ee00751c2 Mon Sep 17 00:00:00 2001 From: NoodleSugar <noodle@Noodle-PC.localdomain> Date: Tue, 12 Sep 2023 12:39:13 +0200 Subject: [PATCH] [llvm][documentation] Fix coroutines documentation --- llvm/docs/Coroutines.rst | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/llvm/docs/Coroutines.rst b/llvm/docs/Coroutines.rst index 46dc2dcbee18276..96bc7003b68e984 100644 --- a/llvm/docs/Coroutines.rst +++ b/llvm/docs/Coroutines.rst @@ -372,7 +372,7 @@ execution of the coroutine until a suspend point is reached: store void (%f.frame*)* @f.destroy, void (%f.frame*)** %2 %inc = add nsw i32 %n, 1 - %inc.spill.addr = getelementptr inbounds %f.Frame, %f.Frame* %FramePtr, i32 0, i32 2 + %inc.spill.addr = getelementptr inbounds %f.frame, %f.frame* %frame, i32 0, i32 2 store i32 %inc, i32* %inc.spill.addr call void @print(i32 %n) @@ -387,7 +387,7 @@ Outlined resume part of the coroutine will reside in function `f.resume`: entry: %inc.spill.addr = getelementptr %f.frame, %f.frame* %frame.ptr.resume, i64 0, i32 2 %inc.spill = load i32, i32* %inc.spill.addr, align 4 - %inc = add i32 %n.val, 1 + %inc = add i32 %inc.spill, 1 store i32 %inc, i32* %inc.spill.addr, align 4 tail call void @print(i32 %inc) ret void @@ -497,23 +497,28 @@ 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 - define internal fastcc void @f.Resume(%f.Frame* %FramePtr) { - entry.Resume: - %index.addr = getelementptr inbounds %f.Frame, %f.Frame* %FramePtr, i64 0, i32 2 + define internal fastcc void @f.resume(%f.frame* %FramePtr) { + entry.resume: + %index.addr = getelementptr inbounds %f.frame, %f.frame* %FramePtr, i64 0, i32 2 %index = load i8, i8* %index.addr, align 1 %switch = icmp eq i8 %index, 0 - %n.addr = getelementptr inbounds %f.Frame, %f.Frame* %FramePtr, i64 0, i32 3 + %n.addr = getelementptr inbounds %f.frame, %f.frame* %FramePtr, i64 0, i32 3 %n = load i32, i32* %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: @@ -589,7 +594,7 @@ correct resume point): %save2 = call token @llvm.coro.save(i8* %hdl) call void @async_op2(i8* %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: _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits