0
0
mirror of https://github.com/python/cpython.git synced 2024-11-24 00:38:00 +01:00
cpython/Tools/jit
Ken Jin 6293d00e72
gh-120619: Strength reduce function guards, support 2-operand uop forms (GH-124846)
Co-authored-by: Brandt Bucher <brandtbucher@gmail.com>
2024-11-09 11:35:33 +08:00
..
_llvm.py GH-125498: Update JIT builds to use LLVM 19 and preserve_none (GH-125499) 2024-10-30 12:03:31 -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-120619: Strength reduce function guards, support 2-operand uop forms (GH-124846) 2024-11-09 11:35:33 +08:00
_targets.py GH-125911: Rename big trampoline to "shim" (GH-126339) 2024-11-05 15:26:46 -08:00
_writer.py GH-125911: Rename big trampoline to "shim" (GH-126339) 2024-11-05 15:26:46 -08: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 gh-126366: Fix crash if __iter__ raises an exception during yield from (#126369) 2024-11-05 15:26:36 +05:30
jit.h GH-125498: Update JIT builds to use LLVM 19 and preserve_none (GH-125499) 2024-10-30 12:03:31 -07:00
mypy.ini
README.md GH-125498: Update JIT builds to use LLVM 19 and preserve_none (GH-125499) 2024-10-30 12:03:31 -07:00
shim.c GH-125911: Rename big trampoline to "shim" (GH-126339) 2024-11-05 15:26:46 -08:00
template.c gh-120619: Strength reduce function guards, support 2-operand uop forms (GH-124846) 2024-11-09 11:35:33 +08:00

The JIT Compiler

This version of CPython can be built with an experimental just-in-time compiler1. 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 LLVM2. 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 19 is required. Both clang and llvm-readobj need to be installed and discoverable (version suffixes, like clang-19, 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 19 on Ubuntu/Debian:

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

Install LLVM 19 on Fedora Linux 40 or newer:

sudo dnf install 'clang(major) = 19' 'llvm(major) = 19'

macOS

Install LLVM 19 with Homebrew:

brew install llvm@19

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 19 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=19.1.0

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.

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


  1. PEP 744 ↩︎

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