xref: /aosp_15_r20/external/llvm/docs/tutorial/BuildingAJIT3.rst (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker=============================================
2*9880d681SAndroid Build Coastguard WorkerBuilding a JIT: Per-function Lazy Compilation
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 3 Introduction
13*9880d681SAndroid Build Coastguard Worker======================
14*9880d681SAndroid Build Coastguard Worker
15*9880d681SAndroid Build Coastguard WorkerWelcome to Chapter 3 of the "Building an ORC-based JIT in LLVM" tutorial. This
16*9880d681SAndroid Build Coastguard Workerchapter discusses lazy JITing and shows you how to enable it by adding an ORC
17*9880d681SAndroid Build Coastguard WorkerCompileOnDemand layer the JIT from `Chapter 2 <BuildingAJIT2.html>`_.
18*9880d681SAndroid Build Coastguard Worker
19*9880d681SAndroid Build Coastguard Worker**To be done:**
20*9880d681SAndroid Build Coastguard Worker
21*9880d681SAndroid Build Coastguard Worker**(1) Describe lazy function-at-a-time JITing and how it differs from the kind
22*9880d681SAndroid Build Coastguard Workerof eager module-at-a-time JITing that we've been doing so far.**
23*9880d681SAndroid Build Coastguard Worker
24*9880d681SAndroid Build Coastguard Worker**(2) Discuss CompileCallbackManagers and IndirectStubManagers.**
25*9880d681SAndroid Build Coastguard Worker
26*9880d681SAndroid Build Coastguard Worker**(3) Describe CompileOnDemandLayer (automates these components and builds stubs
27*9880d681SAndroid Build Coastguard Workerand lazy compilation callbacks for IR) and how to add it to the JIT.**
28*9880d681SAndroid Build Coastguard Worker
29*9880d681SAndroid Build Coastguard WorkerFull Code Listing
30*9880d681SAndroid Build Coastguard Worker=================
31*9880d681SAndroid Build Coastguard Worker
32*9880d681SAndroid Build Coastguard WorkerHere is the complete code listing for our running example with a CompileOnDemand
33*9880d681SAndroid Build Coastguard Workerlayer added to enable lazy function-at-a-time compilation. To build this example, use:
34*9880d681SAndroid Build Coastguard Worker
35*9880d681SAndroid Build Coastguard Worker.. code-block:: bash
36*9880d681SAndroid Build Coastguard Worker
37*9880d681SAndroid Build Coastguard Worker    # Compile
38*9880d681SAndroid Build Coastguard Worker    clang++ -g toy.cpp `llvm-config --cxxflags --ldflags --system-libs --libs core orc native` -O3 -o toy
39*9880d681SAndroid Build Coastguard Worker    # Run
40*9880d681SAndroid Build Coastguard Worker    ./toy
41*9880d681SAndroid Build Coastguard Worker
42*9880d681SAndroid Build Coastguard WorkerHere is the code:
43*9880d681SAndroid Build Coastguard Worker
44*9880d681SAndroid Build Coastguard Worker.. literalinclude:: ../../examples/Kaleidoscope/BuildingAJIT/Chapter3/KaleidoscopeJIT.h
45*9880d681SAndroid Build Coastguard Worker   :language: c++
46*9880d681SAndroid Build Coastguard Worker
47*9880d681SAndroid Build Coastguard Worker`Next: Extreme Laziness -- Using Compile Callbacks to JIT directly from ASTs <BuildingAJIT4.html>`_
48