rsmith added inline comments.

Comment at: include/clang/Basic/Builtins.def:1293
@@ +1292,3 @@
+BUILTIN(__builtin_coro_id, "v*Iiv*v*v*", "n")
+BUILTIN(__builtin_coro_alloc, "bv*", "n")
I don't really like having builtins which will result in errors from the 
middle-end in some cases; there are a bunch of side-conditions on 
that aren't being enforced here. In particular, this call must be present in 
any function that also calls coro.alloc and friends, and must dominate those 
other calls.

Modeling the 'token' value as a `void*` also seems problematic. If the user 
uses that value for anything other than the argument to a builtin that wants 
the token, bad things are going to happen.

(From dinner discussion:) one possible way to deal with this would be to 
generate the call to implicitly in the entry block, in a function 
that uses the other builtins. The challenge then is communicating the promise 
object to the intrinsic, which is problematic if we allow an arbitrary pointer 
value to be passed in.

However, we're only interested in supporting a stack variable as the promise 
object, so here's one possible approach:

- add an attribute that can be applied to a local variable to mark it as the 
promise object for the current function
- remove the `__builtin_coro_id` builtin, and instead implicitly generate the 
`` intrinsic call in the entry block when we need its token or see 
a promise object
- when we emit a local variable with the promise-object attribute, update the 
`` call to pass its alloca as the promise object
- remove the 'token' parameter from `__builtin_coro_alloc` etc, and instead 
implicitly provide it from the result of the implicit `` call

Comment at: test/Coroutines/coro.c:1
@@ +1,2 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fcoroutines -emit-llvm %s 
-o - -O3 | FileCheck %s
+#include "Inputs/coro.h"
Please just check the IR generated by the frontend is correct for each of the 
intrinsics rather than using an end-to-end test that depends on the LLVM IR 
optimizations. You can use `-disable-llvm-optzns` to see the IR coming out of 
clang before the mandatory coroutine passes monkey with it.

cfe-commits mailing list

Reply via email to