Skip to content

Commit 9f44755

Browse files
authored
Upgrade to LLVM 20.1.0 (#553)
I just published an LLVM 20.1.0 toolchain with some computed gotos patches to hopefully improve performance of CPython. https://github.com/indygreg/toolchain-tools/releases/tag/toolchain-bootstrap%2F20250308 One of the patches changes codegen to fix a regression in LLVM 19. The other enables bolt to work with computed gotos. To take full advantage of this functionality we patch CPython configure to remove some `--skip-funcs` which are no longer required.
1 parent d0ed97f commit 9f44755

7 files changed

+52
-19
lines changed

cpython-unix/build-cpython.sh

+5-1
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,9 @@ if [ -n "${PYTHON_MEETS_MINIMUM_VERSION_3_12}" ]; then
270270
# Additional BOLT optimizations, being upstreamed in
271271
# https://github.com/python/cpython/issues/128514
272272
patch -p1 -i ${ROOT}/patch-configure-bolt-apply-flags-128514.patch
273+
274+
# Tweak --skip-funcs to work with our toolchain.
275+
patch -p1 -i ${ROOT}/patch-configure-bolt-skip-funcs.patch
273276
fi
274277

275278
# The optimization make targets are both phony and non-phony. This leads
@@ -437,10 +440,11 @@ if [ -n "${CPYTHON_OPTIMIZED}" ]; then
437440
if [[ -n "${PYTHON_MEETS_MAXIMUM_VERSION_3_13}" ]]; then
438441
# On 3.13, LLVM 18 is hard-coded into the configure script. Override it to our toolchain
439442
# version.
440-
patch -p1 -i "${ROOT}/patch-jit-llvm-19.patch"
443+
patch -p1 -i "${ROOT}/patch-jit-llvm-version-3.13.patch"
441444
fi
442445

443446
if [[ -n "${PYTHON_MEETS_MINIMUM_VERSION_3_14}" ]]; then
447+
patch -p1 -i "${ROOT}/patch-jit-llvm-version-3.14.patch"
444448
# On 3.14, we also use the tail calling interpreter which was incompatible with the JIT
445449
# until https://github.com/python/cpython/pull/129820 — backport that
446450
patch -p1 -i "${ROOT}/patch-jit-tail-call-compat-314-129820.patch"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
diff --git a/configure.ac b/configure.ac
2+
index 3fcb18922c5..2df614a3063 100644
3+
--- a/configure.ac
4+
+++ b/configure.ac
5+
@@ -2227,10 +2227,8 @@ then
6+
[m4_normalize("
7+
[-update-debug-sections]
8+
9+
- dnl At least LLVM 19.x doesn't support computed gotos in PIC compiled code.
10+
- dnl Exclude functions containing computed gotos.
11+
- dnl TODO this may be fixed in LLVM 20.x via https://github.com/llvm/llvm-project/pull/120267.
12+
- [-skip-funcs=_PyEval_EvalFrameDefault,sre_ucs1_match/1,sre_ucs2_match/1,sre_ucs4_match/1]
13+
+ dnl LLVM on at least 20.1.0 crashes on this symbol. Work around.
14+
+ [-skip-funcs=RC4_options/1]
15+
")]
16+
)
17+
fi

cpython-unix/patch-jit-llvm-19.patch renamed to cpython-unix/patch-jit-llvm-version-3.13.patch

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ diff --git a/Tools/jit/_llvm.py b/Tools/jit/_llvm.py
66
import typing
77

88
-_LLVM_VERSION = 18
9-
+_LLVM_VERSION = 19
9+
+_LLVM_VERSION = 20
1010
_LLVM_VERSION_PATTERN = re.compile(rf"version\s+{_LLVM_VERSION}\.\d+\.\d+\S*\s+")
1111

1212
_P = typing.ParamSpec("_P")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
diff --git a/Tools/jit/_llvm.py b/Tools/jit/_llvm.py
2+
--- a/Tools/jit/_llvm.py
3+
+++ b/Tools/jit/_llvm.py
4+
@@ -8,7 +8,7 @@
5+
import subprocess
6+
import typing
7+
8+
-_LLVM_VERSION = 19
9+
+_LLVM_VERSION = 20
10+
_LLVM_VERSION_PATTERN = re.compile(rf"version\s+{_LLVM_VERSION}\.\d+\.\d+\S*\s+")
11+
12+
_P = typing.ParamSpec("_P")

pythonbuild/downloads.py

+13-13
Original file line numberDiff line numberDiff line change
@@ -184,25 +184,25 @@
184184
"version": "14.0.3+20220508",
185185
},
186186
# Remember to update LLVM_URL in src/release.rs whenever upgrading.
187-
"llvm-19-x86_64-linux": {
188-
"url": "https://github.com/indygreg/toolchain-tools/releases/download/toolchain-bootstrap%2F20241231/llvm-19.1.6+20241231-gnu_only-x86_64-unknown-linux-gnu.tar.zst",
189-
"size": 251277644,
190-
"sha256": "900bbb464d430e960ea97150e073395ae865332ce403e7c1e8f76640cab5e852",
191-
"version": "19.1.6+20241231",
187+
"llvm-20-x86_64-linux": {
188+
"url": "https://github.com/indygreg/toolchain-tools/releases/download/toolchain-bootstrap%2F20250308/llvm-20.1.0+20250308-gnu_only-x86_64-unknown-linux-gnu.tar.zst",
189+
"size": 283261860,
190+
"sha256": "41d3d74e21e064e2e59a4e89feca74d58a5e9e95f73877f3c9ed82ca95607b47",
191+
"version": "20.1.0+20240308",
192192
},
193193
# Remember to update LLVM_URL in src/release.rs whenever upgrading.
194194
"llvm-aarch64-macos": {
195-
"url": "https://github.com/indygreg/toolchain-tools/releases/download/toolchain-bootstrap%2F20241231/llvm-19.1.6+20241231-aarch64-apple-darwin.tar.zst",
196-
"size": 143884729,
197-
"sha256": "c0252c7ebe0b20125fe592a12d43a693fcab0bfa3bec9def6b96b97087e0f765",
198-
"version": "19.1.6+20241231",
195+
"url": "https://github.com/indygreg/toolchain-tools/releases/download/toolchain-bootstrap%2F20250308/llvm-20.1.0+20250308-aarch64-apple-darwin.tar.zst",
196+
"size": 161006322,
197+
"sha256": "9897bfaab16c930258f614250a1ade1a8f32df027181bd54a61d24b5a04e284c",
198+
"version": "20.1.0+20240308",
199199
},
200200
# Remember to update LLVM_URL in src/release.rs whenever upgrading.
201201
"llvm-x86_64-macos": {
202-
"url": "https://github.com/indygreg/toolchain-tools/releases/download/toolchain-bootstrap%2F20241231/llvm-19.1.6+20241231-x86_64-apple-darwin.tar.zst",
203-
"size": 143113277,
204-
"sha256": "e990dea9ff89e4202d358b477a43f2bd128b244926534b7c8bb29feeaada994e",
205-
"version": "19.1.6+20241231",
202+
"url": "https://github.com/indygreg/toolchain-tools/releases/download/toolchain-bootstrap%2F20250308/llvm-20.1.0+20250308-x86_64-apple-darwin.tar.zst",
203+
"size": 160133882,
204+
"sha256": "95cfcb79d752e81735a7a7f7c4cb5a7c16360b6e9a75658a1bd50ce0547d4ad5",
205+
"version": "20.1.0+20240308",
206206
},
207207
"m4": {
208208
"url": "https://ftp.gnu.org/gnu/m4/m4-1.4.19.tar.xz",

pythonbuild/utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ def clang_toolchain(host_platform: str, target_triple: str) -> str:
434434
if "musl" in target_triple:
435435
return "llvm-14-x86_64-linux"
436436
else:
437-
return "llvm-19-x86_64-linux"
437+
return "llvm-20-x86_64-linux"
438438
elif host_platform == "macos":
439439
if platform.mac_ver()[2] == "arm64":
440440
return "llvm-aarch64-macos"

src/release.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -589,14 +589,14 @@ pub fn produce_install_only_stripped(tar_gz_path: &Path, llvm_dir: &Path) -> Res
589589
static LLVM_URL: Lazy<Url> = Lazy::new(|| {
590590
if cfg!(target_os = "macos") {
591591
if std::env::consts::ARCH == "aarch64" {
592-
Url::parse("https://github.com/indygreg/toolchain-tools/releases/download/toolchain-bootstrap%2F20241231/llvm-19.1.6+20241231-aarch64-apple-darwin.tar.zst").unwrap()
592+
Url::parse("https://github.com/indygreg/toolchain-tools/releases/download/toolchain-bootstrap%2F20250308/llvm-20.1.0+20250308-aarch64-apple-darwin.tar.zst").unwrap()
593593
} else if std::env::consts::ARCH == "x86_64" {
594-
Url::parse("https://github.com/indygreg/toolchain-tools/releases/download/toolchain-bootstrap%2F20241231/llvm-19.1.6+20241231-x86_64-apple-darwin.tar.zst").unwrap()
594+
Url::parse("https://github.com/indygreg/toolchain-tools/releases/download/toolchain-bootstrap%2F20250308/llvm-20.1.0+20250308-x86_64-apple-darwin.tar.zst").unwrap()
595595
} else {
596596
panic!("unsupported macOS architecture");
597597
}
598598
} else if cfg!(target_os = "linux") {
599-
Url::parse("https://github.com/indygreg/toolchain-tools/releases/download/toolchain-bootstrap%2F20241231/llvm-19.1.6+20241231-gnu_only-x86_64-unknown-linux-gnu.tar.zst").unwrap()
599+
Url::parse("https://github.com/indygreg/toolchain-tools/releases/download/toolchain-bootstrap%2F20250308/llvm-20.1.0+20250308-gnu_only-x86_64-unknown-linux-gnu.tar.zst").unwrap()
600600
} else {
601601
panic!("unsupported platform");
602602
}

0 commit comments

Comments
 (0)