llvm-project/llvm/test/Transforms/Coroutines
Gor Nishanov c52006ab09 [coroutines] Add handling for unwind coro.ends
Summary:
The purpose of coro.end intrinsic is to allow frontends to mark the cleanup and
other code that is only relevant during the initial invocation of the coroutine
and should not be present in resume and destroy parts.

In landing pads coro.end is replaced with an appropriate instruction to unwind to
caller. The handling of coro.end differs depending on whether the target is
using landingpad or WinEH exception model.

For landingpad based exception model, it is expected that frontend uses the
`coro.end`_ intrinsic as follows:

```
    ehcleanup:
      %InResumePart = call i1 @llvm.coro.end(i8* null, i1 true)
      br i1 %InResumePart, label %eh.resume, label %cleanup.cont

    cleanup.cont:
      ; rest of the cleanup

    eh.resume:
      %exn = load i8*, i8** %exn.slot, align 8
      %sel = load i32, i32* %ehselector.slot, align 4
      %lpad.val = insertvalue { i8*, i32 } undef, i8* %exn, 0
      %lpad.val29 = insertvalue { i8*, i32 } %lpad.val, i32 %sel, 1
      resume { i8*, i32 } %lpad.val29

```
The `CoroSpit` pass replaces `coro.end` with ``True`` in the resume functions,
thus leading to immediate unwind to the caller, whereas in start function it
is replaced with ``False``, thus allowing to proceed to the rest of the cleanup
code that is only needed during initial invocation of the coroutine.

For Windows Exception handling model, a frontend should attach a funclet bundle
referring to an enclosing cleanuppad as follows:

```
    ehcleanup:
      %tok = cleanuppad within none []
      %unused = call i1 @llvm.coro.end(i8* null, i1 true) [ "funclet"(token %tok) ]
      cleanupret from %tok unwind label %RestOfTheCleanup
```

The `CoroSplit` pass, if the funclet bundle is present, will insert
``cleanupret from %tok unwind to caller`` before
the `coro.end`_ intrinsic and will remove the rest of the block.

Reviewers: majnemer

Reviewed By: majnemer

Subscribers: llvm-commits, mehdi_amini

Differential Revision: https://reviews.llvm.org/D25543

llvm-svn: 297223
2017-03-07 21:00:54 +00:00
..
ArgAddr.ll [coroutines] Add handling for unwind coro.ends 2017-03-07 21:00:54 +00:00
coro-cleanup.ll [Coroutines] Part 15a: Lower coro.subfn.addr in CoroCleanup 2016-09-30 18:41:35 +00:00
coro-early.ll Part 4c: Coroutine Devirtualization: Devirtualize coro.resume and coro.destroy. 2016-08-06 02:16:35 +00:00
coro-elide.ll [Coroutines] Part 9: Add cleanup subfunction. 2016-08-29 14:34:12 +00:00
coro-frame.ll [coroutines] Add handling for unwind coro.ends 2017-03-07 21:00:54 +00:00
coro-heap-elide.ll [Coroutines] Part 9: Add cleanup subfunction. 2016-08-29 14:34:12 +00:00
coro-split-00.ll [coroutines] Add handling for unwind coro.ends 2017-03-07 21:00:54 +00:00
coro-split-01.ll [coroutines] Add handling for unwind coro.ends 2017-03-07 21:00:54 +00:00
coro-split-02.ll [coroutines] Add handling for unwind coro.ends 2017-03-07 21:00:54 +00:00
coro-split-dbg.ll [coroutines] Add handling for unwind coro.ends 2017-03-07 21:00:54 +00:00
coro-split-eh.ll [coroutines] Add handling for unwind coro.ends 2017-03-07 21:00:54 +00:00
ex0.ll [coroutines] Add handling for unwind coro.ends 2017-03-07 21:00:54 +00:00
ex1.ll [coroutines] Add handling for unwind coro.ends 2017-03-07 21:00:54 +00:00
ex2.ll [coroutines] Add handling for unwind coro.ends 2017-03-07 21:00:54 +00:00
ex3.ll [coroutines] Add handling for unwind coro.ends 2017-03-07 21:00:54 +00:00
ex4.ll [coroutines] Add handling for unwind coro.ends 2017-03-07 21:00:54 +00:00
ex5.ll [coroutines] Add handling for unwind coro.ends 2017-03-07 21:00:54 +00:00
no-suspend.ll [coroutines] Add handling for unwind coro.ends 2017-03-07 21:00:54 +00:00
phi-coro-end.ll [coroutines] Add handling for unwind coro.ends 2017-03-07 21:00:54 +00:00
restart-trigger.ll [coroutines] Add handling for unwind coro.ends 2017-03-07 21:00:54 +00:00
smoketest.ll [Coroutines] Part 8: Coroutine Frame Building algorithm 2016-08-24 04:44:35 +00:00