cpython/Tools/jit
Diego Russo 966260841b
GH-119726: Use LDR for AArch64 trampolines (GH-121001)
2024-07-01 15:52:33 -07:00
..
README.md gh-120433: Mention ``chocolatey`` for installing llvm on Windows as an alternative option (#120434) 2024-06-17 15:52:07 +00:00
_llvm.py GH-120602: Support LLVM_VERSION_SUFFIX for JIT builds (GH-120604) 2024-06-19 17:48:00 -07:00
_schema.py GH-113464: Display a warning when building the JIT (GH-118481) 2024-05-01 21:35:49 +00:00
_stencils.py GH-119726: Use LDR for AArch64 trampolines (GH-121001) 2024-07-01 15:52:33 -07:00
_targets.py GH-118943: Fix a race condition when generating jit_stencils.h (GH-118957) 2024-05-16 12:11:42 -04:00
_writer.py GH-113464: Generate a more efficient JIT (GH-118512) 2024-05-03 16:41:07 -07:00
build.py GH-113464: Display a warning when building the JIT (GH-118481) 2024-05-01 21:35:49 +00:00
ignore-tests-emulated-linux.txt Ignore some failing tests in emulated JIT CI (GH-120375) 2024-06-18 18:24:29 -07:00
mypy.ini
template.c GH-116017: Get rid of _COLD_EXITs (GH-120960) 2024-07-01 13:17:40 -07:00
trampoline.c gh-117139: Convert the evaluation stack to stack refs (#118450) 2024-06-27 03:10:43 +08: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

Install LLVM 18 on Fedora Linux 40 or newer:

sudo dnf install 'clang(major) = 18' 'llvm(major) = 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".

Alternatively, you can use chocolatey:

choco install llvm --version=18.1.6

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