1*ad92f16cSLang Hames======================================================================= 2*ad92f16cSLang HamesBuilding a JIT: Extreme Laziness - Using LazyReexports to JIT from ASTs 3*ad92f16cSLang Hames======================================================================= 488cec7f7SLang Hames 588cec7f7SLang Hames.. contents:: 688cec7f7SLang Hames :local: 788cec7f7SLang Hames 888cec7f7SLang Hames**This tutorial is under active development. It is incomplete and details may 988cec7f7SLang Hameschange frequently.** Nonetheless we invite you to try it out as it stands, and 1088cec7f7SLang Hameswe welcome any feedback. 1188cec7f7SLang Hames 1288cec7f7SLang HamesChapter 4 Introduction 1388cec7f7SLang Hames====================== 1488cec7f7SLang Hames 1588cec7f7SLang HamesWelcome to Chapter 4 of the "Building an ORC-based JIT in LLVM" tutorial. This 16*ad92f16cSLang Hameschapter introduces custom MaterializationUnits and Layers, and the lazy 17*ad92f16cSLang Hamesreexports API. Together these will be used to replace the CompileOnDemandLayer 18*ad92f16cSLang Hamesfrom `Chapter 3 <BuildingAJIT3.html>`_ with a custom lazy-JITing scheme that JITs 1988cec7f7SLang Hamesdirectly from Kaleidoscope ASTs. 2088cec7f7SLang Hames 2188cec7f7SLang Hames**To be done:** 2288cec7f7SLang Hames 2388cec7f7SLang Hames**(1) Describe the drawbacks of JITing from IR (have to compile to IR first, 2488cec7f7SLang Hameswhich reduces the benefits of laziness).** 2588cec7f7SLang Hames 2688cec7f7SLang Hames**(2) Describe CompileCallbackManagers and IndirectStubManagers in detail.** 2788cec7f7SLang Hames 2888cec7f7SLang Hames**(3) Run through the implementation of addFunctionAST.** 2988cec7f7SLang Hames 3088cec7f7SLang HamesFull Code Listing 3188cec7f7SLang Hames================= 3288cec7f7SLang Hames 3388cec7f7SLang HamesHere is the complete code listing for our running example that JITs lazily from 3488cec7f7SLang HamesKaleidoscope ASTS. To build this example, use: 3588cec7f7SLang Hames 3688cec7f7SLang Hames.. code-block:: bash 3788cec7f7SLang Hames 3888cec7f7SLang Hames # Compile 394b93d23aSDon Hinton clang++ -g toy.cpp `llvm-config --cxxflags --ldflags --system-libs --libs core orcjit native` -O3 -o toy 4088cec7f7SLang Hames # Run 4188cec7f7SLang Hames ./toy 4288cec7f7SLang Hames 4388cec7f7SLang HamesHere is the code: 4488cec7f7SLang Hames 4588cec7f7SLang Hames.. literalinclude:: ../../examples/Kaleidoscope/BuildingAJIT/Chapter4/KaleidoscopeJIT.h 4688cec7f7SLang Hames :language: c++ 4788cec7f7SLang Hames 4888cec7f7SLang Hames`Next: Remote-JITing -- Process-isolation and laziness-at-a-distance <BuildingAJIT5.html>`_ 49