With this commit simple coroutines can be created in plain C using coroutine builtins.
Details
- Reviewers
EricWF rnk rsmith - Commits
- rG97e3b6d895ba: [coroutines] Adding builtins for coroutine intrinsics and backendutil support.
rC283155: [coroutines] Adding builtins for coroutine intrinsics and backendutil support.
rL283155: [coroutines] Adding builtins for coroutine intrinsics and backendutil support.
Diff Detail
Event Timeline
include/clang/Basic/Builtins.def | ||
---|---|---|
1343 | 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:
| |
test/Coroutines/coro.c | ||
1 ↗ | (On Diff #70780) | 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. |
- Added documentation for builtins
- Added a couple of tests with -disable-llvm-passes to check that builtins are emitted correctly
include/clang/Basic/Builtins.def | ||
---|---|---|
1343 | 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. | |
test/Coroutines/coro.c | ||
1 ↗ | (On Diff #70780) | 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. |
docs/LanguageExtensions.rst | ||
---|---|---|
1886 | Return type here is void*, not void. | |
1916 | Remove both "the"s here. | |
test/CodeGenCoroutines/O2-coro.c | ||
1 ↗ | (On Diff #73213) | Please do not test the output of LLVM optimization in a clang unit test. It seems fine to just remove this test, you have the relevant coverage elsewhere. |
test/CodeGenCoroutines/coro-builtins.c | ||
6 | Use a pattern here rather than hardcoding %0; it's not reasonable to assume that this will always be the first instruction in the function. Please also pass actual arguments here so we can test they're passed to the correct parameter. |
- O2 test removed
- Update LanguageExtensions.rst with suggested edits
- coro-builtins.c test now passes useful arguments and pattern matches that proper arguments are passed in emitted intrinsics.
Closed by commit r283155 - [coroutines] Adding builtins for coroutine intrinsics and backendutil support.
For some reason phabricator did not close it automatically.
Return type here is void*, not void.