[llvm-dev] [RFC] LLVM Coroutines

Eli Friedman via llvm-dev llvm-dev at lists.llvm.org
Thu Jun 9 16:50:55 PDT 2016


On Thu, Jun 9, 2016 at 2:33 PM, Gor Nishanov <gornishanov at gmail.com> wrote:

> Lowering of coro.suspend number X:
>
> 1) split block at coro.suspend, new block becomes jump point for
> resumption X
> 2) RAUW coro.suspend with i1 true in resume clone i1 false in destroy clone
> 3) replace coro.suspend with br %return.block in 'f', 'ret void' in clones
>
> Scratch the proposed corosuspend instruction. I think the intrinsic will
> work
> just fine!
>

That sounds right.


If you're going down that route, that still leaves the question of the
semantics of the fork intrinsic... thinking about it a bit more, I think
you're going to run into problems with trying to keep around a return block
through optimizations:

[...]
%first.return = call i1 @llvm.experimental.coro.fork()
%cmp = icmp eq i32 %x, 0
br i1 %cmp, label %block1, label %block2

block1:
[...]
br i1 %first.return, label %coro.return, label %coro.start

block2:
[...]
br i1 %first.return, label %coro.return, label %coro.start

coro.return:
%xxx = phi i32 [ %a, %block1 ], [ %b, %block2 ]
call void @f(i32 %xxx)
ret i8* %frame

(Now you can't trivially insert branches to the return block because of the
PHI node.)

-Eli
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160609/520ee160/attachment.html>


More information about the llvm-dev mailing list