summaryrefslogtreecommitdiff
path: root/test/CodeGenCoroutines
AgeCommit message (Collapse)Author
2017-11-11[coroutines] Promote cleanup.dest.slot allocas to registers to avoid storing ↵Gor Nishanov
it in the coroutine frame Summary: We don't want to store cleanup dest slot saved into the coroutine frame (as some of the cleanup code may access them after coroutine frame destroyed). This is an alternative to https://reviews.llvm.org/D37093 It is possible to do this for all functions, but, cursory check showed that in -O0, we get slightly longer function (by 1-3 instructions), thus, we are only limiting cleanup.dest.slot elimination to coroutines. Reviewers: rjmccall, hfinkel, eric_niebler Reviewed By: eric_niebler Subscribers: EricWF, cfe-commits Differential Revision: https://reviews.llvm.org/D39768 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@317981 91177308-0d34-0410-b5e6-96231b3b80d8
2017-08-25[coroutines] Support coroutine-handle returning await-suspend (i.e symmetric ↵Gor Nishanov
control transfer) Summary: If await_suspend returns a coroutine_handle, as in the example below: ``` coroutine_handle<> await_suspend(coroutine_handle<> h) { coro.promise().waiter = h; return coro; } ``` suspensionExpression processing will resume the coroutine pointed at by that handle. Related LLVM change rL311751 makes resume calls of this kind `musttail` at any optimization level. This enables unlimited symmetric control transfer from coroutine to coroutine without blowing up the stack. Reviewers: GorNishanov Reviewed By: GorNishanov Subscribers: rsmith, EricWF, cfe-commits Differential Revision: https://reviews.llvm.org/D37131 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@311762 91177308-0d34-0410-b5e6-96231b3b80d8
2017-07-31[coroutines] Evaluate the operand of void `co_return` expressions.Eric Fiselier
Summary: Previously Clang incorrectly ignored the expression of a void `co_return`. This patch addresses that bug. I'm not quite sure if I got the code-gen right, but this patch is at least a start. Reviewers: rsmith, GorNishanov Reviewed By: rsmith, GorNishanov Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D36070 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@309545 91177308-0d34-0410-b5e6-96231b3b80d8
2017-06-15[coroutines] Allow co_await and co_yield expressions that return an lvalue ↵Eric Fiselier
to compile Summary: The title says it all. Reviewers: GorNishanov, rsmith Reviewed By: GorNishanov Subscribers: rjmccall, cfe-commits Differential Revision: https://reviews.llvm.org/D34194 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@305496 91177308-0d34-0410-b5e6-96231b3b80d8
2017-06-03[coroutines] Fix rebuilding of dependent coroutine parametersEric Fiselier
Summary: We were not handling correctly rebuilding of parameter and were not creating copies for them. Now we will always rebuild parameter moves in TreeTransform's TransformCoroutineBodyStmt. Reviewers: rsmith, GorNishanov Reviewed By: rsmith Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D33797 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@304620 91177308-0d34-0410-b5e6-96231b3b80d8
2017-06-01CGCleanup: (NFC) add another test for r304335 - Don't try to spill static ↵Gor Nishanov
allocas Summary: Coroutine related test that used to trigger broken IR prior to r304335. ``` %x = alloca i32, align 4 store i32* %x, i32** %tmp.exprcleanup, align 4 ; <===== HERE %ref.tmp3 = alloca %struct.A, align 1 %agg.tmp5 = alloca %"struct.std::experimental::coroutines_v1::coroutine_handle.0", align 4 %tmp.exprcleanup = alloca i32*, align 4 %allocapt = bitcast i32 undef to i32 store i32 %0, i32* %.addr, align 4 ``` Fixed with r304335 Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D33750 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@304380 91177308-0d34-0410-b5e6-96231b3b80d8
2017-05-24[coroutines] Add support for coroutines with non-scalar parametersGor Nishanov
Summary: Simple types like int are handled by LLVM Coroutines just fine. But for non-scalar parameters we need to create copies of those parameters in the coroutine frame and make all uses of those parameters to refer to parameter copies. Reviewers: rsmith, EricWF, GorNishanov Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D33507 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@303803 91177308-0d34-0410-b5e6-96231b3b80d8
2017-05-24[coroutines] Make generic lambda coroutines workGor Nishanov
Summary: 1. Coroutine cannot be constexpr (added a check in SemaLambda.cpp not to mark coroutine as constexpr) 2. TransformCoroutineBodyStmt should transform ResultDecl and ReturnStmt Reviewers: rsmith, GorNishanov Reviewed By: GorNishanov Subscribers: EricWF, cfe-commits Differential Revision: https://reviews.llvm.org/D33498 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@303764 91177308-0d34-0410-b5e6-96231b3b80d8
2017-05-24[coroutines] [NFC] Add tests for return_void, unhandled_exception and ↵Gor Nishanov
promise dtor Summary: * Test that coroutine promise destructor is called. * Test that we call return_void on fallthrough * Test that we call unhandled exception in a try catch surrounding the body Reviewers: EricWF, GorNishanov Reviewed By: GorNishanov Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D33479 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@303748 91177308-0d34-0410-b5e6-96231b3b80d8
2017-05-24[coroutines] Implement correct GRO lifetimeGor Nishanov
Summary: Sema creates a declaration for gro variable as: auto $gro = $promise.get_return_object(); However, gro variable has to outlive coroutine frame and coroutine promise, but, it can only be initialized after the coroutine promise was created, thus, we split its emission in two parts: EmitGroAlloca emits an alloca and sets up the cleanups. Later when the coroutine promise is available we initialize the gro and set the flag that the cleanup is now active. Duplicate of: https://reviews.llvm.org/D31670 (which arc patch refuses to apply for some reason) Reviewers: GorNishanov, rsmith Reviewed By: GorNishanov Subscribers: EricWF, cfe-commits Differential Revision: https://reviews.llvm.org/D33477 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@303716 91177308-0d34-0410-b5e6-96231b3b80d8
2017-05-23[coroutines] Skip over passthrough operator co_awaitGor Nishanov
https://reviews.llvm.org/D31627 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@303605 91177308-0d34-0410-b5e6-96231b3b80d8
2017-05-23[coroutines] Add emission of initial and final suspendsGor Nishanov
https://reviews.llvm.org/D31608 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@303603 91177308-0d34-0410-b5e6-96231b3b80d8
2017-05-23[coroutines] Add support for deallocation elisionGor Nishanov
Wrap deallocation code with: if (auto *mem = coro.free()) Deallocate When backend decides to elide allocations it will replace coro.free with nullptr to suppress deallocation code. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@303599 91177308-0d34-0410-b5e6-96231b3b80d8
2017-05-23[coroutines] Replace all coro.frame builtins with an SSA value of coro.beginGor Nishanov
SemaCoroutine forms expressions referring to the coroutine frame of the enclosing coroutine using coro.frame builtin. During codegen, we emit llvm.coro.begin intrinsic that returns the address of the coroutine frame. When coro.frame is emitted, we replace it with SSA value of coro.begin. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@303598 91177308-0d34-0410-b5e6-96231b3b80d8
2017-05-23[coroutines] Add support for allocation elisionGor Nishanov
Summary: We wrap allocation code so that backend can elide it if necessary. llvm.coro.alloc intrinsic returns true, when allocation is needed and false otherwise. ``` %NeedAlloc = call i1 @llvm.coro.alloc(token %2) br i1 %NeedAlloc, label %AllocBB, label %InitBB AllocBB: %5 = call i64 @llvm.coro.size.i64() %call = call i8* @_Znwm(i64 %5) ; operator new br label %InitBB InitBB: %Phi = phi i8* [ null, %0 ], [ %call, %4 ] call i8* @llvm.coro.begin(token %2, i8* %Phi) ``` Reviewers: majnemer, EricWF Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D31584 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@303596 91177308-0d34-0410-b5e6-96231b3b80d8
2017-05-22[coroutines] Fix coro-eh-cleanup.cpp testGor Nishanov
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@303584 91177308-0d34-0410-b5e6-96231b3b80d8
2017-05-22[coroutines] Wrap the body of the coroutine in try-catchGor Nishanov
Summary: If unhandled_exception member function is present in the coroutine promise, wrap the body of the coroutine in: ``` try { body } catch(...) { promise.unhandled_exception(); } ``` Reviewers: EricWF, rnk, rsmith Reviewed By: rsmith Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D31692 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@303583 91177308-0d34-0410-b5e6-96231b3b80d8
2017-05-22[coroutines] Build GRO declaration and return GRO statementGor Nishanov
Summary: 1. build declaration of the gro local variable that keeps the result of get_return_object. 2. build return statement returning the gro variable 3. emit them during CodeGen 4. sema and CodeGen tests updated Reviewers: EricWF, rsmith Reviewed By: rsmith Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D31646 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@303573 91177308-0d34-0410-b5e6-96231b3b80d8
2017-04-18[coroutines] Fix building of new/delete expressions when ↵Eric Fiselier
get_return_object_on_allocation_failure() is present. Summary: This patch implements [dcl.fct.def.coroutine]p8: > The unqualified-id get_return_object_on_allocation_failure is looked up in the scope of > class P by class member access lookup (3.4.5). If a declaration is found, ..., and if a > global allocation function is selected, the ::operator new(size_t, nothrow_t) form shall be used. > [...] > The allocation function used in this case must have a non-throwing noexcept-specification. Reviewers: GorNishanov, rsmith, majnemer, aaron.ballman Reviewed By: GorNishanov Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D31562 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@300524 91177308-0d34-0410-b5e6-96231b3b80d8
2017-04-17Rename coroutine warning when unhandled_exception() is missingEric Fiselier
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@300513 91177308-0d34-0410-b5e6-96231b3b80d8
2017-04-17Revert r300504 - [coroutines] Fix rebuilding of implicit and dependent ↵Eric Fiselier
coroutine statements. I have no idea what's happening here. The tests that fail on all of the bots pass on my machine. Further investigation needed. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@300511 91177308-0d34-0410-b5e6-96231b3b80d8
2017-04-17[coroutines] Fix rebuilding of implicit and dependent coroutine statements.Eric Fiselier
Summary: Certain implicitly generated coroutine statements, such as the calls to 'return_value()' or `return_void()` or `get_return_object_on_allocation_failure()`, cannot be built until the promise type is no longer dependent. This means they are not built until after the coroutine body statement has been transformed. This patch fixes an issue where these statements would never be built for coroutine templates. It also fixes a small issue where diagnostics about `get_return_object_on_allocation_failure()` were incorrectly suppressed. Reviewers: rsmith, majnemer, GorNishanov, aaron.ballman Reviewed By: GorNishanov Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D31487 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@300504 91177308-0d34-0410-b5e6-96231b3b80d8
2017-04-16Revert r300420 - [coroutines] Fix building of new/delete expressions when ↵Eric Fiselier
get_return_object_on_allocation_failure() is present git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@300421 91177308-0d34-0410-b5e6-96231b3b80d8
2017-04-16[coroutines] Fix building of new/delete expressions when ↵Eric Fiselier
get_return_object_on_allocation_failure() is present. Summary: This patch implements [dcl.fct.def.coroutine]p8: > The unqualified-id get_return_object_on_allocation_failure is looked up in the scope of > class P by class member access lookup (3.4.5). If a declaration is found, ..., and if a > global allocation function is selected, the ::operator new(size_t, nothrow_t) form shall be used. > [...] > The allocation function used in this case must have a non-throwing noexcept-specification. Reviewers: GorNishanov, rsmith, majnemer, aaron.ballman Reviewed By: GorNishanov Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D31562 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@300420 91177308-0d34-0410-b5e6-96231b3b80d8
2017-04-05[coroutines] Add coro.end handlingGor Nishanov
Summary: For WinEH, We add a funclet bundle to a coro.end call, so that CoroSplit in LLVM can replace it with cleanup ret and cut the rest out. For landing pad, we add a branch to resume block if coro.end returns true. LLVM Part: https://reviews.llvm.org/D25445 Reviewers: majnemer Reviewed By: majnemer Subscribers: EricWF, cfe-commits, rsmith, mehdi_amini Differential Revision: https://reviews.llvm.org/D25444 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@299510 91177308-0d34-0410-b5e6-96231b3b80d8
2017-04-01[coroutines] Add cleanup for compiler injected objects/allocations in ↵Gor Nishanov
coroutine body Summary: * Use pushCleanup to emit freeing coroutine memory on normal and EH exits. * Surround emitted code with CodeGenFunction::RunCleanupsScope. Reviewers: rsmith, rnk, EricWF Reviewed By: rnk Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D31460 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@299281 91177308-0d34-0410-b5e6-96231b3b80d8
2017-03-27[coroutines] Handle get_return_object_on_allocation_failureGor Nishanov
Summary: If promise_type has get_return_object_on_allocation_failure defined, check if an allocation function returns nullptr, and if so, return the result of get_return_object_on_allocation_failure(). Reviewers: rsmith, EricWF Reviewed By: EricWF Subscribers: mehdi_amini, cfe-commits Differential Revision: https://reviews.llvm.org/D31399 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@298891 91177308-0d34-0410-b5e6-96231b3b80d8
2017-03-26[coroutines] Add codegen for await and yield expressionsGor Nishanov
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 ] git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@298784 91177308-0d34-0410-b5e6-96231b3b80d8
2017-03-09[coroutines] Build and pass coroutine_handle to await_suspendGor Nishanov
Summary: This patch adds passing a coroutine_handle object to await_suspend calls. It builds the coroutine_handle using coroutine_handle<PromiseType>::from_address(__builtin_coro_frame()). (a revision of https://reviews.llvm.org/D26316 that for some reason refuses to apply via arc patch) Reviewers: GorNishanov Subscribers: mehdi_amini, cfe-commits, EricWF Differential Revision: https://reviews.llvm.org/D30769 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@297356 91177308-0d34-0410-b5e6-96231b3b80d8
2017-03-07[coroutines] update coro_end builtin to match llvmGor Nishanov
Summary: llvm.coro.end intrinsic now returns bool. Updating clang to match it. Reviewers: GorNishanov, rsmith Reviewed By: rsmith Subscribers: mehdi_amini, cfe-commits, EricWF Differential Revision: https://reviews.llvm.org/D30711 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@297224 91177308-0d34-0410-b5e6-96231b3b80d8
2017-03-06[coroutines] Add co_return statement emissionGor Nishanov
Summary: Added co_return statement emission. Tweaked coro-alloc.cpp test to use co_return to trigger coroutine processing instead of co_await, since this change starts emitting the body of the coroutine and await expression handling has not been upstreamed yet. Reviewers: rsmith, majnemer, EricWF, aaron.ballman Reviewed By: rsmith Subscribers: majnemer, llvm-commits, mehdi_amini Differential Revision: https://reviews.llvm.org/D29979 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@297076 91177308-0d34-0410-b5e6-96231b3b80d8
2016-10-27[coroutines] Add allocation and deallocation substatements.Gor Nishanov
Summary: SemaCoroutine: Add allocation / deallocation substatements. CGCoroutine/Test: Emit allocation and deallocation + test. Reviewers: rsmith Subscribers: ABataev, EricWF, llvm-commits, mehdi_amini Differential Revision: https://reviews.llvm.org/D25879 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@285306 91177308-0d34-0410-b5e6-96231b3b80d8
2016-10-03[coroutines] Adding builtins for coroutine intrinsics and backendutil support.Gor Nishanov
Summary: With this commit simple coroutines can be created in plain C using coroutine builtins. Reviewers: rnk, EricWF, rsmith Subscribers: modocache, mgorny, mehdi_amini, beanz, cfe-commits Differential Revision: https://reviews.llvm.org/D24373 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@283155 91177308-0d34-0410-b5e6-96231b3b80d8
2016-10-02[coroutines] Rename driver flag -fcoroutines to -fcoroutines-tsGor Nishanov
Summary: Also makes -fcoroutines_ts to be both a Driver and CC1 flag. Patch mostly by EricWF. Reviewers: rnk, cfe-commits, rsmith, EricWF Subscribers: mehdi_amini Differential Revision: https://reviews.llvm.org/D25130 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@283064 91177308-0d34-0410-b5e6-96231b3b80d8
2016-09-28[Coroutines] Add proper mangling for operator co_await for MicrosoftABIGor Nishanov
Reviewers: rnk, rsmith Subscribers: mehdi_amini, cfe-commits Differential Revision: https://reviews.llvm.org/D25045 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@282645 91177308-0d34-0410-b5e6-96231b3b80d8