[PATCH] D24373: [Coroutines] Adding builtins for coroutine intrinsics and backendutil support.

Gor Nishanov via cfe-commits cfe-commits at lists.llvm.org
Tue Sep 27 16:48:12 PDT 2016


GorNishanov marked an inline comment as done.

================
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")
----------------
rsmith wrote:
> 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 llvm.coro.id 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 @llvm.coro.id 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 `llvm.coro.id` 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 `llvm.coro.id` 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 `llvm.coro.id` call
I added clarification to the documentation that all but four builtins are for internal compiler use and for the use as development tools for the coroutine feature, so, possibly we should not worry too much about people misusing them.

Alternatively, I can get rid of most of the coroutine builtins, apart from the ones that are intended to be used to implement coroutine standard library facilities.

At the moment, I think, we should prioritize getting C++ Coroutines online. We can polish C coroutine story later.

================
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"
----------------
rsmith wrote:
> 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.
I added two tests to check that builtins are lowered to coro intrinsics correctly. I would like to keep a small number of "-O2" tests as a sanity end-to-end testing. 


https://reviews.llvm.org/D24373





More information about the cfe-commits mailing list