]> granicus.if.org Git - clang/commit
[coroutines] Add codegen for await and yield expressions
authorGor Nishanov <GorNishanov@gmail.com>
Sun, 26 Mar 2017 02:18:05 +0000 (02:18 +0000)
committerGor Nishanov <GorNishanov@gmail.com>
Sun, 26 Mar 2017 02:18:05 +0000 (02:18 +0000)
commitbcaf7f2abe47b0dab055f1a0ec011ed9c2a3d3ea
tree0d3acff8c14a1ce3f99c8fbbd53934b2684ceb8f
parentff19b51066a4384368e28ef5df06f9bd94d3adec
[coroutines] Add codegen for await and yield expressions

Details:

Emit suspend expression which roughly looks like:

auto && x = CommonExpr();
if (!x.await_ready()) {
   llvm_coro_save();
   x.await_suspend(...);     (*)
   llvm_coro_suspend(); (**)
}
x.await_resume();
where the result of the entire expression is the result of x.await_resume()

(*) If x.await_suspend return type is bool, it allows to veto a suspend:
if (x.await_suspend(...))
   llvm_coro_suspend();
(**) llvm_coro_suspend() encodes three possible continuations as a switch instruction:

%where-to = call i8 @llvm.coro.suspend(...)
switch i8 %where-to, label %coro.ret [ ; jump to epilogue to suspend
  i8 0, label %yield.ready   ; go here when resumed
  i8 1, label %yield.cleanup ; go here when destroyed
]

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@298784 91177308-0d34-0410-b5e6-96231b3b80d8
lib/CodeGen/CGCoroutine.cpp
lib/CodeGen/CGExprAgg.cpp
lib/CodeGen/CGExprComplex.cpp
lib/CodeGen/CGExprScalar.cpp
lib/CodeGen/CodeGenFunction.h
test/CodeGenCoroutines/coro-await.cpp [new file with mode: 0644]