[PATCH] D72486: Add ThinLtoJIT example

Stefan Gränitz via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 9 15:39:48 PST 2020


sgraenitz created this revision.
sgraenitz added reviewers: lhames, dblaikie.
Herald added subscribers: jfb, arphaman, dexonsmith, steven_wu, hiraditya, inglorion, mehdi_amini, mgorny.
Herald added a reviewer: jfb.
Herald added a project: LLVM.

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 two 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 the code on the execution path can always 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.

The example that was discussed in the presentation has a good size for debugging. Here's how to build it:

  # Build LLVM
  $ cd build-release
  $ cmake -GNinja -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_PROJECTS=clang -DLLVM_TARGETS_TO_BUILD=host /path/to/llvm-project/llvm
  $ ninja clang llvm-dis lli SpeculativeJIT ThinLtoJIT
  
  # Get the example code
  $ git clone https://github.com/weliveindetail/tinyexpr
  
  # Unrepresentative minimal runtime comparison
  $ /path/to/llvm-project/llvm/examples/ThinLtoJIT/bench
  Usage: bench <path to llvm binaries> <path to c-sources> <main source file> [<override sysroot>]
  
  $ /path/to/llvm-project/llvm/examples/ThinLtoJIT/bench $(pwd)/bin $(pwd)/tinyexpr example.c

Note that on macOS you may want to pass a sysroot override like `/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk`.

I would like to gather some feedback. Do you think it's fine to have this as another JIT example? I am happy to maintain it and to continue working on it.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D72486

Files:
  llvm/examples/CMakeLists.txt
  llvm/examples/ThinLtoJIT/.gitignore
  llvm/examples/ThinLtoJIT/CMakeLists.txt
  llvm/examples/ThinLtoJIT/ThinLtoDiscoveryThread.cpp
  llvm/examples/ThinLtoJIT/ThinLtoDiscoveryThread.h
  llvm/examples/ThinLtoJIT/ThinLtoInstrumentationLayer.cpp
  llvm/examples/ThinLtoJIT/ThinLtoInstrumentationLayer.h
  llvm/examples/ThinLtoJIT/ThinLtoJIT.cpp
  llvm/examples/ThinLtoJIT/ThinLtoJIT.h
  llvm/examples/ThinLtoJIT/ThinLtoModuleIndex.cpp
  llvm/examples/ThinLtoJIT/ThinLtoModuleIndex.h
  llvm/examples/ThinLtoJIT/bench
  llvm/examples/ThinLtoJIT/main.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D72486.237220.patch
Type: text/x-patch
Size: 40915 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200109/ff381061/attachment.bin>


More information about the llvm-commits mailing list