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

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Wed Sep 21 19:23:38 PDT 2016


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 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

================
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.


https://reviews.llvm.org/D24373





More information about the cfe-commits mailing list