From 94252cf33ea1a7f9309e47ceb8ae76b4ad31ad0f Mon Sep 17 00:00:00 2001 From: Savannah Ostrowski Date: Sat, 14 Sep 2024 12:22:49 -0700 Subject: [PATCH 01/10] Update to LLVM 19 --- .github/workflows/jit.yml | 2 +- Tools/jit/_llvm.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/jit.yml b/.github/workflows/jit.yml index 5e3ac9e9e0fada..3dd83e33b43e86 100644 --- a/.github/workflows/jit.yml +++ b/.github/workflows/jit.yml @@ -61,7 +61,7 @@ jobs: - true - false llvm: - - 18 + - 19 include: - target: i686-pc-windows-msvc/msvc architecture: Win32 diff --git a/Tools/jit/_llvm.py b/Tools/jit/_llvm.py index 606f280a14d974..925b56ac669aa0 100644 --- a/Tools/jit/_llvm.py +++ b/Tools/jit/_llvm.py @@ -8,7 +8,7 @@ import subprocess import typing -_LLVM_VERSION = 18 +_LLVM_VERSION = 19 _LLVM_VERSION_PATTERN = re.compile(rf"version\s+{_LLVM_VERSION}\.\d+\.\d+\S*\s+") _P = typing.ParamSpec("_P") From f8dc236394fa53daef165ea320cc0a54f5d60afc Mon Sep 17 00:00:00 2001 From: Savannah Ostrowski Date: Sat, 14 Sep 2024 13:05:55 -0700 Subject: [PATCH 02/10] update syntax in disabled gil ci --- .github/workflows/jit.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/jit.yml b/.github/workflows/jit.yml index 3dd83e33b43e86..9646a9ce9b9003 100644 --- a/.github/workflows/jit.yml +++ b/.github/workflows/jit.yml @@ -174,8 +174,8 @@ jobs: python-version: '3.11' - name: Build with JIT enabled and GIL disabled run: | - sudo bash -c "$(wget -O - https://apt.llvm.org/llvm.sh)" ./llvm.sh 18 - export PATH="$(llvm-config-18 --bindir):$PATH" + sudo bash -c "$(wget -O - https://apt.llvm.org/llvm.sh)" ./llvm.sh ${{ matrix.llvm }} + export PATH="$(llvm-config-${{ matrix.llvm }} --bindir):$PATH" ./configure --enable-experimental-jit --with-pydebug --disable-gil make all --jobs 4 - name: Run tests From 80a3b408131691fb0f273db38af3f3f3c7da59f3 Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Sat, 14 Sep 2024 20:09:41 +0000 Subject: [PATCH 03/10] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20b?= =?UTF-8?q?lurb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../2024-09-14-20-09-39.gh-issue-123714.o1mbe4.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Core_and_Builtins/2024-09-14-20-09-39.gh-issue-123714.o1mbe4.rst diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2024-09-14-20-09-39.gh-issue-123714.o1mbe4.rst b/Misc/NEWS.d/next/Core_and_Builtins/2024-09-14-20-09-39.gh-issue-123714.o1mbe4.rst new file mode 100644 index 00000000000000..03a2ef63238073 --- /dev/null +++ b/Misc/NEWS.d/next/Core_and_Builtins/2024-09-14-20-09-39.gh-issue-123714.o1mbe4.rst @@ -0,0 +1 @@ +Update JIT compilation to use LLVM 19 From 7a1133e2a935cd06520df0860806b7df85e44dce Mon Sep 17 00:00:00 2001 From: Savannah Ostrowski Date: Tue, 24 Sep 2024 21:20:26 -0700 Subject: [PATCH 04/10] Update readme --- Tools/jit/README.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Tools/jit/README.md b/Tools/jit/README.md index bc6f793b296f12..b6bb8479298bd4 100644 --- a/Tools/jit/README.md +++ b/Tools/jit/README.md @@ -7,7 +7,7 @@ This version of CPython can be built with an experimental just-in-time compiler[ The 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). -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. +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: @@ -18,10 +18,10 @@ Install LLVM 18 on Ubuntu/Debian: ```sh wget https://apt.llvm.org/llvm.sh chmod +x llvm.sh -sudo ./llvm.sh 18 +sudo ./llvm.sh 19 ``` -Install LLVM 18 on Fedora Linux 40 or newer: +Install LLVM 19 on Fedora Linux 40 or newer: ```sh sudo dnf install 'clang(major) = 18' 'llvm(major) = 18' @@ -29,22 +29,22 @@ sudo dnf install 'clang(major) = 18' 'llvm(major) = 18' ### macOS -Install LLVM 18 with [Homebrew](https://brew.sh): +Install LLVM 19 with [Homebrew](https://brew.sh): ```sh -brew install llvm@18 +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 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".** +Install LLVM 19 [by searching for it on LLVM's GitHub releases page](https://github.com/llvm/llvm-project/releases?q=19), 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](https://chocolatey.org): ```sh -choco install llvm --version=18.1.6 +choco install llvm --version=19.1.0 ``` ### Dev Containers From d8e38db2ea2ce63321f84970c6fb6ece85bcf9bc Mon Sep 17 00:00:00 2001 From: Savannah Ostrowski Date: Tue, 24 Sep 2024 21:27:58 -0700 Subject: [PATCH 05/10] fix free-threaded by pseudo-pinning version --- .github/workflows/jit.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/jit.yml b/.github/workflows/jit.yml index 06279c40d336e5..7717ecf33b67b2 100644 --- a/.github/workflows/jit.yml +++ b/.github/workflows/jit.yml @@ -165,6 +165,10 @@ jobs: name: Free-Threaded (Debug) needs: interpreter runs-on: ubuntu-latest + strategy: + matrix: + llvm: + - 19 steps: - uses: actions/checkout@v4 - uses: actions/setup-python@v5 From b8ae2183dc4d24aff8a6f38c8618b37da2cf20d8 Mon Sep 17 00:00:00 2001 From: Savannah Ostrowski Date: Thu, 26 Sep 2024 11:40:42 -0700 Subject: [PATCH 06/10] Add check to see that registers match in stencil generation --- Tools/jit/_stencils.py | 9 ++++++++- Tools/jit/_writer.py | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Tools/jit/_stencils.py b/Tools/jit/_stencils.py index 1c6a9edb39840d..f60498188f63d2 100644 --- a/Tools/jit/_stencils.py +++ b/Tools/jit/_stencils.py @@ -132,8 +132,14 @@ class Hole: def __post_init__(self) -> None: self.func = _PATCH_FUNCS[self.kind] - def fold(self, other: typing.Self) -> typing.Self | None: + def fold(self, other: typing.Self, body: bytes) -> typing.Self | None: """Combine two holes into a single hole, if possible.""" + instruction_a = int.from_bytes(body[self.offset : self.offset + 4], byteorder=sys.byteorder) + instruction_b = int.from_bytes(body[other.offset : other.offset + 4], byteorder=sys.byteorder) + reg_a = instruction_a & 0b11111 + reg_b1 = instruction_b & 0b11111 + reg_b2 = (instruction_b >> 5) & 0b11111 + if ( self.offset + 4 == other.offset and self.value == other.value @@ -141,6 +147,7 @@ def fold(self, other: typing.Self) -> typing.Self | None: and self.addend == other.addend and self.func == "patch_aarch64_21rx" and other.func == "patch_aarch64_12x" + and reg_a == reg_b1 == reg_b2 ): # These can *only* be properly relaxed when they appear together and # patch the same value: diff --git a/Tools/jit/_writer.py b/Tools/jit/_writer.py index 9d11094f85c7ff..a45f0a15cf03f8 100644 --- a/Tools/jit/_writer.py +++ b/Tools/jit/_writer.py @@ -50,7 +50,7 @@ def _dump_stencil(opname: str, group: _stencils.StencilGroup) -> typing.Iterator if skip: skip = False continue - if pair and (folded := hole.fold(pair)): + if pair and (folded := hole.fold(pair, stencil.body)): skip = True hole = folded yield f" {hole.as_c(part)}" From 4368d5fbc192df2b9e6cdb700b1a9487c1446665 Mon Sep 17 00:00:00 2001 From: Savannah Ostrowski Date: Thu, 26 Sep 2024 11:42:50 -0700 Subject: [PATCH 07/10] Appease linters --- Tools/jit/_stencils.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Tools/jit/_stencils.py b/Tools/jit/_stencils.py index f60498188f63d2..0ba9935b2e3fd0 100644 --- a/Tools/jit/_stencils.py +++ b/Tools/jit/_stencils.py @@ -134,8 +134,12 @@ def __post_init__(self) -> None: def fold(self, other: typing.Self, body: bytes) -> typing.Self | None: """Combine two holes into a single hole, if possible.""" - instruction_a = int.from_bytes(body[self.offset : self.offset + 4], byteorder=sys.byteorder) - instruction_b = int.from_bytes(body[other.offset : other.offset + 4], byteorder=sys.byteorder) + instruction_a = int.from_bytes( + body[self.offset : self.offset + 4], byteorder=sys.byteorder + ) + instruction_b = int.from_bytes( + body[other.offset : other.offset + 4], byteorder=sys.byteorder + ) reg_a = instruction_a & 0b11111 reg_b1 = instruction_b & 0b11111 reg_b2 = (instruction_b >> 5) & 0b11111 From 12fc5cd2df0ed1a46d28363e154f82dd1f59593b Mon Sep 17 00:00:00 2001 From: Savannah Ostrowski Date: Thu, 26 Sep 2024 11:52:28 -0700 Subject: [PATCH 08/10] Remove devcontainer instructions from readme --- Tools/jit/README.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/Tools/jit/README.md b/Tools/jit/README.md index b6bb8479298bd4..f2070ff06c58b7 100644 --- a/Tools/jit/README.md +++ b/Tools/jit/README.md @@ -47,9 +47,6 @@ Alternatively, you can use [chocolatey](https://chocolatey.org): choco install llvm --version=19.1.0 ``` -### Dev Containers - -If 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. ## Building From 7f9fe5abc17161f82d434b7dcc83e3071eb672c9 Mon Sep 17 00:00:00 2001 From: Savannah Ostrowski Date: Thu, 26 Sep 2024 14:48:23 -0700 Subject: [PATCH 09/10] Update README --- Tools/jit/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Tools/jit/README.md b/Tools/jit/README.md index f2070ff06c58b7..801c64e4059ccc 100644 --- a/Tools/jit/README.md +++ b/Tools/jit/README.md @@ -13,7 +13,7 @@ It's easy to install all of the required tools: ### Linux -Install LLVM 18 on Ubuntu/Debian: +Install LLVM 19 on Ubuntu/Debian: ```sh wget https://apt.llvm.org/llvm.sh @@ -24,7 +24,7 @@ sudo ./llvm.sh 19 Install LLVM 19 on Fedora Linux 40 or newer: ```sh -sudo dnf install 'clang(major) = 18' 'llvm(major) = 18' +sudo dnf install 'clang(major) = 19' 'llvm(major) = 19' ``` ### macOS From 719b924f410f17cd116b7c094b708db863ea3c2c Mon Sep 17 00:00:00 2001 From: Savannah Ostrowski Date: Mon, 14 Oct 2024 21:22:43 -0700 Subject: [PATCH 10/10] Add sys import --- Tools/jit/_stencils.py | 1 + 1 file changed, 1 insertion(+) diff --git a/Tools/jit/_stencils.py b/Tools/jit/_stencils.py index 7d4fc0861d2ee4..def08176d277b6 100644 --- a/Tools/jit/_stencils.py +++ b/Tools/jit/_stencils.py @@ -2,6 +2,7 @@ import dataclasses import enum +import sys import typing import _schema