Add ThinLtoJIT example
authorStefan Gränitz <stefan.graenitz@gmail.com>
Sat, 11 Jan 2020 00:09:42 +0000 (01:09 +0100)
committerStefan Gränitz <stefan.graenitz@gmail.com>
Sat, 1 Feb 2020 19:25:09 +0000 (20:25 +0100)
commit234f3b16918b5721bbc3449d11e4f317142271e7
treee193bb6775b167df1792d761dfa93ff5065d2e71
parent943b5561d6a6fccee7fbaa8842074563f8b66927
Add ThinLtoJIT example

Summary:
Prototype of a JIT compiler that utilizes ThinLTO summaries to compile modules ahead of time. This is an implementation of the concept I presented in my "ThinLTO Summaries in JIT Compilation" talk at the 2018 Developers' Meeting: http://llvm.org/devmtg/2018-10/talk-abstracts.html#lt8

Upfront the JIT first populates the *combined ThinLTO module index*, which provides fast access to the global call-graph and module paths by function. Next, it loads the main function's module and compiles it. All functions in the module will be emitted with prolog instructions that *fire a discovery flag* once execution reaches them. In parallel, the *discovery thread* is busy-watching the existing flags. Once it detects one has fired, it uses the module index to find all functions that are reachable from it within a given number of calls and submits their defining modules to the compilation pipeline.

While execution continues, more flags are fired and further modules added. Ideally the JIT can be tuned in a way, so that in the majority of cases the code on the execution path can be compiled ahead of time. In cases where it doesn't work, the JIT has a *definition generator* in place that loads modules if missing functions are reached.

Reviewers: lhames, dblaikie, jfb, tejohnson, pree-jackie, AlexDenisov, kavon

Subscribers: mgorny, mehdi_amini, inglorion, hiraditya, steven_wu, dexonsmith, arphaman, jfb, merge_guards_bot, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D72486
12 files changed:
llvm/examples/CMakeLists.txt
llvm/examples/ThinLtoJIT/CMakeLists.txt [new file with mode: 0644]
llvm/examples/ThinLtoJIT/ThinLtoDiscoveryThread.cpp [new file with mode: 0644]
llvm/examples/ThinLtoJIT/ThinLtoDiscoveryThread.h [new file with mode: 0644]
llvm/examples/ThinLtoJIT/ThinLtoInstrumentationLayer.cpp [new file with mode: 0644]
llvm/examples/ThinLtoJIT/ThinLtoInstrumentationLayer.h [new file with mode: 0644]
llvm/examples/ThinLtoJIT/ThinLtoJIT.cpp [new file with mode: 0644]
llvm/examples/ThinLtoJIT/ThinLtoJIT.h [new file with mode: 0644]
llvm/examples/ThinLtoJIT/ThinLtoModuleIndex.cpp [new file with mode: 0644]
llvm/examples/ThinLtoJIT/ThinLtoModuleIndex.h [new file with mode: 0644]
llvm/examples/ThinLtoJIT/bench [new file with mode: 0755]
llvm/examples/ThinLtoJIT/main.cpp [new file with mode: 0644]