1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-21 12:02:58 +02:00
Go to file
Gor Nishanov 04cd924e8d [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

llvm-svn: 278242
2016-08-10 16:40:39 +00:00
bindings [OCaml] Add functions for accessing metadata nodes. 2016-06-22 03:30:24 +00:00
cmake Remove LLVM_ENABLE_LIBCXXABI 2016-08-04 10:24:48 +00:00
docs [Coroutines] Part 6: Elide dynamic allocation of a coroutine frame when possible 2016-08-10 16:40:39 +00:00
examples [ExecutionEngine][MCJIT][Orc] Replace RuntimeDyld::SymbolInfo with JITSymbol. 2016-08-01 20:49:11 +00:00
include [Coroutines] Part 6: Elide dynamic allocation of a coroutine frame when possible 2016-08-10 16:40:39 +00:00
lib [Coroutines] Part 6: Elide dynamic allocation of a coroutine frame when possible 2016-08-10 16:40:39 +00:00
projects Remove autoconf support 2016-01-26 21:29:08 +00:00
resources
runtimes [CMake] Add LLVM runtimes directory 2016-06-23 22:07:21 +00:00
test [Coroutines] Part 6: Elide dynamic allocation of a coroutine frame when possible 2016-08-10 16:40:39 +00:00
tools [llvm-cov] Swapped the line and count columns. 2016-08-09 19:53:35 +00:00
unittests [ADT] Change iterator_adaptor_base's default template arguments to forward more underlying typedefs 2016-08-09 20:23:13 +00:00
utils [vim] Update the llvm.vim syntax file 2016-08-09 18:34:19 +00:00
.arcconfig Upgrade all the .arcconfigs to https. 2016-07-14 13:15:37 +00:00
.clang-format
.clang-tidy Don't use misc-unused-parameters check on LLVM. 2016-04-13 08:58:52 +00:00
.gitignore [CMake] Add LLVM runtimes directory 2016-06-23 22:07:21 +00:00
CMakeLists.txt Remove LLVM_ENABLE_LIBCXXABI 2016-08-04 10:24:48 +00:00
CODE_OWNERS.TXT test commit 2016-08-02 19:25:17 +00:00
configure Remove autoconf support 2016-01-26 21:29:08 +00:00
CREDITS.TXT Shamelessly add myself to CREDITS.TXT 2016-08-04 16:28:22 +00:00
LICENSE.TXT Update copyright year to 2016. 2016-03-30 22:41:06 +00:00
llvm.spec.in
LLVMBuild.txt
README.txt Revert rL277454 2016-08-02 13:26:07 +00:00
RELEASE_TESTERS.TXT Adding RELEASE_TESTERS.TXT 2016-07-21 16:46:44 +00:00

Low Level Virtual Machine (LLVM)
================================

This directory and its subdirectories contain source code for LLVM,
a toolkit for the construction of highly optimized compilers,
optimizers, and runtime environments.

LLVM is open source software. You may freely distribute it under the terms of
the license agreement found in LICENSE.txt.

Please see the documentation provided in docs/ for further
assistance with LLVM, and in particular docs/GettingStarted.rst for getting
started with LLVM and docs/README.txt for an overview of LLVM's
documentation setup.

If you are writing a package for LLVM, see docs/Packaging.rst for our
suggestions.