1*9880d681SAndroid Build Coastguard Worker=========================================================================== 2*9880d681SAndroid Build Coastguard WorkerBuilding a JIT: Extreme Laziness - Using Compile Callbacks to JIT from ASTs 3*9880d681SAndroid Build Coastguard Worker=========================================================================== 4*9880d681SAndroid Build Coastguard Worker 5*9880d681SAndroid Build Coastguard Worker.. contents:: 6*9880d681SAndroid Build Coastguard Worker :local: 7*9880d681SAndroid Build Coastguard Worker 8*9880d681SAndroid Build Coastguard Worker**This tutorial is under active development. It is incomplete and details may 9*9880d681SAndroid Build Coastguard Workerchange frequently.** Nonetheless we invite you to try it out as it stands, and 10*9880d681SAndroid Build Coastguard Workerwe welcome any feedback. 11*9880d681SAndroid Build Coastguard Worker 12*9880d681SAndroid Build Coastguard WorkerChapter 4 Introduction 13*9880d681SAndroid Build Coastguard Worker====================== 14*9880d681SAndroid Build Coastguard Worker 15*9880d681SAndroid Build Coastguard WorkerWelcome to Chapter 4 of the "Building an ORC-based JIT in LLVM" tutorial. This 16*9880d681SAndroid Build Coastguard Workerchapter introduces the Compile Callbacks and Indirect Stubs APIs and shows how 17*9880d681SAndroid Build Coastguard Workerthey can be used to replace the CompileOnDemand layer from 18*9880d681SAndroid Build Coastguard Worker`Chapter 3 <BuildingAJIT3.html>`_ with a custom lazy-JITing scheme that JITs 19*9880d681SAndroid Build Coastguard Workerdirectly from Kaleidoscope ASTs. 20*9880d681SAndroid Build Coastguard Worker 21*9880d681SAndroid Build Coastguard Worker**To be done:** 22*9880d681SAndroid Build Coastguard Worker 23*9880d681SAndroid Build Coastguard Worker**(1) Describe the drawbacks of JITing from IR (have to compile to IR first, 24*9880d681SAndroid Build Coastguard Workerwhich reduces the benefits of laziness).** 25*9880d681SAndroid Build Coastguard Worker 26*9880d681SAndroid Build Coastguard Worker**(2) Describe CompileCallbackManagers and IndirectStubManagers in detail.** 27*9880d681SAndroid Build Coastguard Worker 28*9880d681SAndroid Build Coastguard Worker**(3) Run through the implementation of addFunctionAST.** 29*9880d681SAndroid Build Coastguard Worker 30*9880d681SAndroid Build Coastguard WorkerFull Code Listing 31*9880d681SAndroid Build Coastguard Worker================= 32*9880d681SAndroid Build Coastguard Worker 33*9880d681SAndroid Build Coastguard WorkerHere is the complete code listing for our running example that JITs lazily from 34*9880d681SAndroid Build Coastguard WorkerKaleidoscope ASTS. To build this example, use: 35*9880d681SAndroid Build Coastguard Worker 36*9880d681SAndroid Build Coastguard Worker.. code-block:: bash 37*9880d681SAndroid Build Coastguard Worker 38*9880d681SAndroid Build Coastguard Worker # Compile 39*9880d681SAndroid Build Coastguard Worker clang++ -g toy.cpp `llvm-config --cxxflags --ldflags --system-libs --libs core orc native` -O3 -o toy 40*9880d681SAndroid Build Coastguard Worker # Run 41*9880d681SAndroid Build Coastguard Worker ./toy 42*9880d681SAndroid Build Coastguard Worker 43*9880d681SAndroid Build Coastguard WorkerHere is the code: 44*9880d681SAndroid Build Coastguard Worker 45*9880d681SAndroid Build Coastguard Worker.. literalinclude:: ../../examples/Kaleidoscope/BuildingAJIT/Chapter4/KaleidoscopeJIT.h 46*9880d681SAndroid Build Coastguard Worker :language: c++ 47*9880d681SAndroid Build Coastguard Worker 48*9880d681SAndroid Build Coastguard Worker`Next: Remote-JITing -- Process-isolation and laziness-at-a-distance <BuildingAJIT5.html>`_ 49