1====================================================================
2Building a JIT: Adding Optimizations - An introduction to ORC Layers
3====================================================================
4
5.. contents::
6   :local:
7
8**This tutorial is under active development. It is incomplete and details may
9change frequently.** Nonetheless we invite you to try it out as it stands, and
10we welcome any feedback.
11
12Chapter 2 Introduction
13======================
14
15Welcome to Chapter 2 of the "Building an ORC-based JIT in LLVM" tutorial. This
16chapter shows you how to add IR optimization support to the KaleidoscopeJIT
17class that was introduced in `Chapter 1 <BuildingAJIT1.html>`_ by adding a
18new *ORC Layer* -- IRTransformLayer.
19
20**To be done:**
21
22**(1) Briefly describe FunctionPassManager and the optimizeModule
23method (reference the Kaleidoscope language tutorial chapter 4 for more detail
24about IR optimization - it's covered in detail there, here it just provides a
25motivation for learning about layers).**
26
27**(2) Describe IRTransformLayer, show how it is used to call our optimizeModule
28method.**
29
30**(3) Describe the ORC Layer concept using IRTransformLayer as an example.**
31
32Full Code Listing
33=================
34
35Here is the complete code listing for our running example with an
36IRTransformLayer added to enable optimization. To build this example, use:
37
38.. code-block:: bash
39
40    # Compile
41    clang++ -g toy.cpp `llvm-config --cxxflags --ldflags --system-libs --libs core orc native` -O3 -o toy
42    # Run
43    ./toy
44
45Here is the code:
46
47.. literalinclude:: ../../examples/Kaleidoscope/BuildingAJIT/Chapter2/KaleidoscopeJIT.h
48   :language: c++
49
50`Next: Adding Per-function Lazy Compilation <BuildingAJIT3.html>`_
51