README.md
1The JIT Compiler
2================
3
4This version of CPython can be built with an experimental just-in-time compiler[^pep-744]. While most everything you already know about building and using CPython is unchanged, you will probably need to install a compatible version of LLVM first.
5
6## Installing LLVM
7
8The JIT compiler does not require end users to install any third-party dependencies, but part of it must be *built* using LLVM[^why-llvm]. You are *not* required to build the rest of CPython using LLVM, or even the same version of LLVM (in fact, this is uncommon).
9
10LLVM version 18 is required. Both `clang` and `llvm-readobj` need to be installed and discoverable (version suffixes, like `clang-18`, are okay). It's highly recommended that you also have `llvm-objdump` available, since this allows the build script to dump human-readable assembly for the generated code.
11
12It's easy to install all of the required tools:
13
14### Linux
15
16Install LLVM 18 on Ubuntu/Debian:
17
18```sh
19wget https://apt.llvm.org/llvm.sh
20chmod +x llvm.sh
21sudo ./llvm.sh 18
22```
23
24Install LLVM 18 on Fedora Linux 40 or newer:
25
26```sh
27sudo dnf install 'clang(major) = 18' 'llvm(major) = 18'
28```
29
30### macOS
31
32Install LLVM 18 with [Homebrew](https://brew.sh):
33
34```sh
35brew install llvm@18
36```
37
38Homebrew won't add any of the tools to your `$PATH`. That's okay; the build script knows how to find them.
39
40### Windows
41
42Install LLVM 18 [by searching for it on LLVM's GitHub releases page](https://github.com/llvm/llvm-project/releases?q=18), clicking on "Assets", downloading the appropriate Windows installer for your platform (likely the file ending with `-win64.exe`), and running it. **When installing, be sure to select the option labeled "Add LLVM to the system PATH".**
43
44Alternatively, you can use [chocolatey](https://chocolatey.org):
45
46```sh
47choco install llvm --version=18.1.6
48```
49
50### Dev Containers
51
52If you are working CPython in a [Codespaces instance](https://devguide.python.org/getting-started/setup-building/#using-codespaces), there's no need to install LLVM as the Fedora 40 base image includes LLVM 18 out of the box.
53
54## Building
55
56For `PCbuild`-based builds, pass the new `--experimental-jit` option to `build.bat`.
57
58For all other builds, pass the new `--enable-experimental-jit` option to `configure`.
59
60Otherwise, just configure and build as you normally would. Cross-compiling "just works", since the JIT is built for the host platform.
61
62The JIT can also be enabled or disabled using the `PYTHON_JIT` environment variable, even on builds where it is enabled or disabled by default. More details about configuring CPython with the JIT and optional values for `--enable-experimental-jit` can be found [here](https://docs.python.org/dev/whatsnew/3.13.html#experimental-jit-compiler).
63
64[^pep-744]: [PEP 744](https://peps.python.org/pep-0744/)
65
66[^why-llvm]: Clang is specifically needed because it's the only C compiler with support for guaranteed tail calls (`musttail`), which are required by CPython's continuation-passing-style approach to JIT compilation. Since LLVM also includes other functionalities we need (namely, object file parsing and disassembly), it's convenient to only support one toolchain at this time.
67