<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Wed, Jun 8, 2016 at 10:57 PM, Gor Nishanov via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi all:<br>
<br>
Below is a proposal to add experimental coroutine support to LLVM. Though this<br>
proposal is motivated primarily by the desire to support C++ Coroutines [1],<br>
the llvm representation is language neutral and can be used to support<br>
coroutines in other languages as well.<br></blockquote><div><br></div><div>I looked over the proposal... a few comments:<br><br></div><div>1. This adds a lot of intrinsics, and they have weird semantics.  This is bad in general; the more weirdness you add to the IR, the more you'll struggle to make the optimizer actually understand what you're doing.  And magic pattern matching *will* break.  You've already pointed out the issue with branches.  (It's actually worse than you think: there isn't any guarantee there will even be a branch when you've thrown the optimizer at it.)  The save intrinsic says "Its return value should be consumed by exactly one `coro.suspend` intrinsic.", but it might have zero uses by the time your lowering pass runs.  You could end up with code getting inserted before llvm.experimental.coro.fork.<br>2. If you need some sort of unusual control flow construct, make it a proper terminator instruction; don't try to glue your intrinsic to a normal branch instruction.  A new kind of terminator instruction might be appropriate.  Or maybe you can make "invoke" work for you.<br></div><div>3. Maybe you could reduce the amount of magic involved by splitting the initialization into a separate function?  So the initialization is always just something like "f(int x) { frame = init(); f_inner(x, frame); return frame; }", and you don't have to deal with the weirdness of fork().<br></div><div><br></div><div>-Eli<br></div></div></div></div>