Commit Graph

13 Commits

Author SHA1 Message Date
Aaron Ballman
da4a9a639e Changing a code block to text because Sphinx does not like it on the builder (http://lab.llvm.org:8011/builders/llvm-sphinx-docs/builds/12517/steps/docs-llvm-html/logs/stdio)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@280247 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-31 14:37:20 +00:00
Aaron Ballman
1012af3602 Changing a code block to text because Sphinx does not like it on the builder (http://lab.llvm.org:8011/builders/llvm-sphinx-docs/builds/12516/steps/docs-llvm-html/logs/stdio)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@280238 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-31 13:29:23 +00:00
Gor Nishanov
bce16c69f0 [Coroutines] Part 9: Add cleanup subfunction.
Summary:
[Coroutines] Part 9: Add cleanup subfunction.

This patch completes coroutine heap allocation elision. Now, the heap elision example from docs\Coroutines.rst compiles and produces expected result (see test/Transform/Coroutines/ex3.ll)

Intrinsic Changes:
* coro.free gets a token parameter tying it to coro.id to allow reliably discovering all coro.frees associated with a particular coroutine.
* coro.id gets an extra parameter that points back to a coroutine function. This allows to check whether a coro.id describes the enclosing function or it belongs to a different function that was later inlined.

CoroSplit now creates three subfunctions:
# f$resume - resume logic
# f$destroy - cleanup logic, followed by a deallocation code
# f$cleanup - just the cleanup code

CoroElide pass during devirtualization replaces coro.destroy with either f$destroy or f$cleanup depending whether heap elision is performed or not.

Other fixes, improvements:
* Fixed buglet in Shape::buildFrame that was not creating coro.save properly if coroutine has more than one suspend point.

* Switched to using variable width suspend index field (no longer limited to 32 bit index field can be as little as i1 or as large as i<whatever-size_t-is>)

Reviewers: majnemer

Subscribers: llvm-commits, mehdi_amini

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@279971 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-29 14:34:12 +00:00
Gor Nishanov
b6ae34d909 [Coroutines]: Part6b: Add coro.id intrinsic.
Summary:
1. Make coroutine representation more robust against optimization that may duplicate instruction by introducing coro.id intrinsics that returns a token that will get fed into coro.alloc and coro.begin. Due to coro.id returning a token, it won't get duplicated and can be used as reliable indicator of coroutine identify when a particular coroutine call gets inlined.
2. Move last three arguments of coro.begin into coro.id as they will be shared if coro.begin will get duplicated.
3. doc + test + code updated to support the new intrinsic.

Reviewers: mehdi_amini, majnemer

Subscribers: mehdi_amini, llvm-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@278481 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-12 05:45:49 +00:00
Gor Nishanov
bd0032e1a2 [Coroutines] Part 6: Elide dynamic allocation of a coroutine frame when possible
Summary:
A particular coroutine usage pattern, where a coroutine is created, manipulated and
destroyed by the same calling function, is common for coroutines implementing
RAII idiom and is suitable for allocation elision optimization which avoid
dynamic allocation by storing the coroutine frame as a static `alloca` in its
caller.

coro.free and coro.alloc intrinsics are used to indicate which code needs to be suppressed
when dynamic allocation elision happens:
```
entry:
  %elide = call i8* @llvm.coro.alloc()
  %need.dyn.alloc = icmp ne i8* %elide, null
  br i1 %need.dyn.alloc, label %coro.begin, label %dyn.alloc
dyn.alloc:
  %alloc = call i8* @CustomAlloc(i32 4)
  br label %coro.begin
coro.begin:
  %phi = phi i8* [ %elide, %entry ], [ %alloc, %dyn.alloc ]
  %hdl = call i8* @llvm.coro.begin(i8* %phi, i32 0, i8* null,
                          i8* bitcast ([2 x void (%f.frame*)*]* @f.resumers to i8*))
```
and
```
  %mem = call i8* @llvm.coro.free(i8* %hdl)
  %need.dyn.free = icmp ne i8* %mem, null
  br i1 %need.dyn.free, label %dyn.free, label %if.end
dyn.free:
  call void @CustomFree(i8* %mem)
  br label %if.end
if.end:
  ...
```

If heap allocation elision is performed, we replace coro.alloc with a static alloca on the caller frame and coro.free with null constant.

Also, we need to make sure that if there are any tail calls referencing the coroutine frame, we need to remote tail call attribute, since now coroutine frame lives on the stack.

Documentation and overview is here: http://llvm.org/docs/Coroutines.html.

Upstreaming sequence (rough plan)
1.Add documentation. (https://reviews.llvm.org/D22603)
2.Add coroutine intrinsics. (https://reviews.llvm.org/D22659)
3.Add empty coroutine passes. (https://reviews.llvm.org/D22847)
4.Add coroutine devirtualization + tests.
ab) Lower coro.resume and coro.destroy (https://reviews.llvm.org/D22998)
c) Do devirtualization (https://reviews.llvm.org/D23229)
5.Add CGSCC restart trigger + tests. (https://reviews.llvm.org/D23234)
6.Add coroutine heap elision + tests.  <= we are here
7.Add the rest of the logic (split into more patches)

Reviewers: mehdi_amini, majnemer

Subscribers: mehdi_amini, llvm-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@278242 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-10 16:40:39 +00:00
Gor Nishanov
ebdd31d1d6 testing commit access
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@277816 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-05 13:17:06 +00:00
David Majnemer
880190560d [coroutines] Part 3 of N: Adding Boilerplate for Coroutine Passes
This adds boilerplate code for all coroutine passes,
the passes are no-ops for now.
Also, a small test has been added to verify that passes execute in
the expected order or not at all if coroutine support is disabled.

Patch by Gor Nishanov!

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@277033 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-28 21:04:31 +00:00
Mehdi Amini
c53e16cc30 Fix Coroutines doc example
SSA was broken.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@276843 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-27 06:03:47 +00:00
David Majnemer
af5d051e3e [coroutines] Part 2 of N: Adding Coroutine Intrinsics
This is the second patch in the coroutine series. It adds coroutine
intrinsics and updates intrinsic cost in TargetTransformInfoImpl.h.

Patch by Gor Nishanov!

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@276839 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-27 05:12:35 +00:00
Sanjoy Das
315f732fa1 Fix docs/Coroutines.rst syntax highlighting on Linux
Summary:
s/code-block:: C++/code-block:: c++ in docs/Coroutines.rst .

Patch by Gor Nishanov!  Edited by Sanjoy to fix a missing s/C/c/.

Reviewers: sanjoy, rengolin

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@276806 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-26 21:03:41 +00:00
Aaron Ballman
5b9e6bf56f Change some more llvm highlighting instances to be text instead. It seems that Pygment does not handle "token" or "none" yet, and this caused the documentation bot to go red.
Patch by Gor Nishanov.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@276532 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-23 20:11:21 +00:00
Aaron Ballman
570a51e9e7 Switching the highlighting from llvm to none in an attempt to appease the build bot (http://lab.llvm.org:8011/builders/llvm-sphinx-docs/builds/11984/steps/docs-llvm-html/logs/stdio).
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@276531 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-23 18:53:35 +00:00
David Majnemer
e48bbc4e36 [coroutines] Part 1 of N: Documentation
This is the first patch in the coroutine series.
It contains the documentation for the coroutine intrinsics and their usage.

Patch by Gor Nishanov!

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@276513 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-23 04:05:08 +00:00