cpython/Tools/jit
Guido van Rossum 7d83f7bcc4
gh-118335: Configure Tier 2 interpreter at build time (#118339)
The code for Tier 2 is now only compiled when configured
with `--enable-experimental-jit[=yes|interpreter]`.

We drop support for `PYTHON_UOPS` and -`Xuops`,
but you can disable the interpreter or JIT
at runtime by setting `PYTHON_JIT=0`.
You can also build it without enabling it by default
using `--enable-experimental-jit=yes-off`;
enable with `PYTHON_JIT=1`.

On Windows, the `build.bat` script supports
`--experimental-jit`, `--experimental-jit-off`,
`--experimental-interpreter`.

In the C code, `_Py_JIT` is defined as before
when the JIT is enabled; the new variable
`_Py_TIER2` is defined when the JIT *or* the
interpreter is enabled. It is actually a bitmask:
1: JIT; 2: default-off; 4: interpreter.
2024-04-30 18:26:34 -07:00
..
README.md gh-118335: Configure Tier 2 interpreter at build time (#118339) 2024-04-30 18:26:34 -07:00
_llvm.py GH-118306: Update JIT to use LLVM 18 (GH-118307) 2024-04-29 21:09:16 +00:00
_schema.py GH-118306: Update JIT to use LLVM 18 (GH-118307) 2024-04-29 21:09:16 +00:00
_stencils.py GH-118306: Update JIT to use LLVM 18 (GH-118307) 2024-04-29 21:09:16 +00:00
_targets.py GH-118306: Update JIT to use LLVM 18 (GH-118307) 2024-04-29 21:09:16 +00:00
_writer.py GH-117512: Allow 64-bit JIT operands on 32-bit platforms (GH-117527) 2024-04-06 08:26:43 -07:00
build.py
mypy.ini
template.c GH-118095: Add dynamic exit support and FOR_ITER_GEN support to tier 2 (GH-118279) 2024-04-26 18:08:50 +01:00

README.md

The JIT Compiler

This version of CPython can be built with an experimental just-in-time compiler. 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.

Installing LLVM

The JIT compiler does not require end users to install any third-party dependencies, but part of it must be built using LLVM1. You are not required to build the rest of CPython using LLVM, or even the same version of LLVM (in fact, this is uncommon).

LLVM 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.

It's easy to install all of the required tools:

Linux

Install LLVM 18 on Ubuntu/Debian:

wget https://apt.llvm.org/llvm.sh
chmod +x llvm.sh
sudo ./llvm.sh 18

macOS

Install LLVM 18 with Homebrew:

brew install llvm@18

Homebrew won't add any of the tools to your $PATH. That's okay; the build script knows how to find them.

Windows

Install LLVM 18 by searching for it on LLVM's GitHub releases page, 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".

Dev Containers

If you are working CPython in a Codespaces instance, there's no need to install LLVM as the Fedora 40 base image includes LLVM 18 out of the box.

Building

For PCbuild-based builds, pass the new --experimental-jit option to build.bat.

For all other builds, pass the new --enable-experimental-jit option to configure.

Otherwise, just configure and build as you normally would. Cross-compiling "just works", since the JIT is built for the host platform.


  1. 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. ↩︎