[PATCH] D22659: [coroutines] Part 2 of N: Adding Coroutine Intrinsics

Gor Nishanov via llvm-commits llvm-commits at lists.llvm.org
Sun Jul 24 23:13:23 PDT 2016


GorNishanov added inline comments.

================
Comment at: include/llvm/IR/Intrinsics.td:606-607
@@ +605,4 @@
+def int_coro_alloc : Intrinsic<[llvm_ptr_ty], [], [IntrNoMem]>;
+def int_coro_begin : Intrinsic<[llvm_ptr_ty], [llvm_ptr_ty, llvm_i32_ty,
+                                llvm_ptr_ty, llvm_ptr_ty], []>;
+
----------------
majnemer wrote:
> GorNishanov wrote:
> > majnemer wrote:
> > > What happens if there are two calls to llvm.coro.begin in a function?
> > **TLDR: **
> >   coro.begin(*,*,*, null) - must have exactly one, broken IR otherwise
> >   coro.begin(*,*,*, not-null) - can have as many or as little as inliner wants
> > 
> > **Longer explanation:**
> > 
> > The last argument of coro.begin is null when coming out of the frontend. Later, CoroSplit pass sets it to a pointer to a constant array containing pointers to outlined parts of the coroutine. Let's call a coro.begin with null "pre-slit coro.begin", and the one with a pointer to const array, "post-split coro.begin".
> > 
> > Coming out of the frontend, a coroutine has exactly one coro.begin. (Verifier can check for that). Later inliner can inline calls to other coroutines and it may bring more coro.begins into a function, but, those, will be always post-split, since CoroSplit pass runs together with the Inliner in the same CGPassManager.
> > 
> > CoroSplit pass only cares about pre-split coro.begin and there is exactly one. Other coro.begins are there for the benefit of CoroElide pass that devirtualizes and elides heap allocations where possible.
> > 
> > All intrinsics that stay in the coroutine after CoroSplit pass (coro.alloc and coro.free) are linked to coro.begin, so CoroElide pass knows which coroutine they belong to.
> Can't earlier transforms clone a block containing a `coro.begin` call?
I just found a very useful attribute. NoDuplicate.
CoroEarly can mark the coro.begin CallSite as NoDuplicate.
CoroSplit will remove that attribute, so PostSplit coro.begins could be duplicated after split.

Alternatively, we can break coro.begin into two distinct intrinsics:

coro.begin (with NoDuplicate always, and only three parameters, no last parameters)
coro.begin.postsplit (without NoDuplicate attribute and without Promise parameter)


https://reviews.llvm.org/D22659





More information about the llvm-commits mailing list