HomePhabricator

[coroutines] Add codegen for await and yield expressions

Description

[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

]

Details

Committed
GorNishanovMar 25 2017, 7:18 PM
Parents
rL298783: [X86] Pull out repeated ScalarValueSizeInBits code. NFCI.
Branches
Unknown
Tags
Unknown