xref: /aosp_15_r20/external/llvm/docs/tutorial/BuildingAJIT5.rst (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker=============================================================================
2*9880d681SAndroid Build Coastguard WorkerBuilding a JIT: Remote-JITing -- Process Isolation and Laziness at a Distance
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 5 Introduction
13*9880d681SAndroid Build Coastguard Worker======================
14*9880d681SAndroid Build Coastguard Worker
15*9880d681SAndroid Build Coastguard WorkerWelcome to Chapter 5 of the "Building an ORC-based JIT in LLVM" tutorial. This
16*9880d681SAndroid Build Coastguard Workerchapter introduces the ORC RemoteJIT Client/Server APIs and shows how to use
17*9880d681SAndroid Build Coastguard Workerthem to build a JIT stack that will execute its code via a communications
18*9880d681SAndroid Build Coastguard Workerchannel with a different process. This can be a separate process on the same
19*9880d681SAndroid Build Coastguard Workermachine, a process on a different machine, or even a process on a different
20*9880d681SAndroid Build Coastguard Workerplatform/architecture. The code builds on top of the lazy-AST-compiling JIT
21*9880d681SAndroid Build Coastguard Workerstack from `Chapter 4 <BuildingAJIT3.html>`_.
22*9880d681SAndroid Build Coastguard Worker
23*9880d681SAndroid Build Coastguard Worker**To be done -- this is going to be a long one:**
24*9880d681SAndroid Build Coastguard Worker
25*9880d681SAndroid Build Coastguard Worker**(1) Introduce channels, RPC, RemoteJIT Client and Server APIs**
26*9880d681SAndroid Build Coastguard Worker
27*9880d681SAndroid Build Coastguard Worker**(2) Describe the client code in greater detail. Discuss modifications of the
28*9880d681SAndroid Build Coastguard WorkerKaleidoscopeJIT class, and the REPL itself.**
29*9880d681SAndroid Build Coastguard Worker
30*9880d681SAndroid Build Coastguard Worker**(3) Describe the server code.**
31*9880d681SAndroid Build Coastguard Worker
32*9880d681SAndroid Build Coastguard Worker**(4) Describe how to run the demo.**
33*9880d681SAndroid Build Coastguard Worker
34*9880d681SAndroid Build Coastguard WorkerFull Code Listing
35*9880d681SAndroid Build Coastguard Worker=================
36*9880d681SAndroid Build Coastguard Worker
37*9880d681SAndroid Build Coastguard WorkerHere is the complete code listing for our running example that JITs lazily from
38*9880d681SAndroid Build Coastguard WorkerKaleidoscope ASTS. To build this example, use:
39*9880d681SAndroid Build Coastguard Worker
40*9880d681SAndroid Build Coastguard Worker.. code-block:: bash
41*9880d681SAndroid Build Coastguard Worker
42*9880d681SAndroid Build Coastguard Worker    # Compile
43*9880d681SAndroid Build Coastguard Worker    clang++ -g toy.cpp `llvm-config --cxxflags --ldflags --system-libs --libs core orc native` -O3 -o toy
44*9880d681SAndroid Build Coastguard Worker    # Run
45*9880d681SAndroid Build Coastguard Worker    ./toy
46*9880d681SAndroid Build Coastguard Worker
47*9880d681SAndroid Build Coastguard WorkerHere is the code for the modified KaleidoscopeJIT:
48*9880d681SAndroid Build Coastguard Worker
49*9880d681SAndroid Build Coastguard Worker.. literalinclude:: ../../examples/Kaleidoscope/BuildingAJIT/Chapter5/KaleidoscopeJIT.h
50*9880d681SAndroid Build Coastguard Worker   :language: c++
51*9880d681SAndroid Build Coastguard Worker
52*9880d681SAndroid Build Coastguard WorkerAnd the code for the JIT server:
53*9880d681SAndroid Build Coastguard Worker
54*9880d681SAndroid Build Coastguard Worker.. literalinclude:: ../../examples/Kaleidoscope/BuildingAJIT/Chapter5/Server/server.cpp
55*9880d681SAndroid Build Coastguard Worker   :language: c++
56