Skip to content

Commit c1f1c16

Browse files
committed
unix: enable BOLT optimizations on Linux x86-64
BOLT appears to only work on Linux. And it only supports x86-64 and aarch64. And since we don't have PGO builds for aarch64, that means we can only ship it on x86-64. (We can't even enable support in the build system since we don't have a sufficiently modern Clang to use on aarch64.) In order to get this to work, I had to force DWARF version 4 to avoid BOLT crashing. This is related to #155. I plan to file an upstream issue on the LLVM crash.
1 parent ff3734d commit c1f1c16

File tree

4 files changed

+24
-0
lines changed

4 files changed

+24
-0
lines changed

cpython-unix/build-cpython.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,9 @@ fi
333333

334334
if [ -n "${CPYTHON_OPTIMIZED}" ]; then
335335
CONFIGURE_FLAGS="${CONFIGURE_FLAGS} --enable-optimizations"
336+
if [[ -n "${PYTHON_MEETS_MINIMUM_VERSION_3_12}" && -n "${BOLT_CAPABLE}" ]]; then
337+
CONFIGURE_FLAGS="${CONFIGURE_FLAGS} --enable-bolt"
338+
fi
336339
fi
337340

338341
if [ -n "${CPYTHON_LTO}" ]; then

cpython-unix/build.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ def add_target_env(env, build_platform, target_triple, build_env):
9393
env["HOST_CXX"] = settings["host_cxx"]
9494
env["CC"] = settings["target_cc"]
9595

96+
if settings.get("bolt_capable"):
97+
env["BOLT_CAPABLE"] = "1"
98+
9699
env["PYBUILD_PLATFORM"] = build_platform
97100
env["TOOLS_PATH"] = build_env.tools_path
98101

cpython-unix/targets.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@
4545
#
4646
# openssl_target
4747
# Name of OpenSSL platform build target.
48+
#
49+
# bolt_capable
50+
# Whether the target is capable of performing BOLT optimizations.
4851

4952
---
5053

@@ -720,6 +723,8 @@ x86_64-unknown-linux-gnu:
720723
target_cc: clang
721724
target_cflags:
722725
- '-fvisibility=hidden'
726+
# Needed to prevent BOLT from crashing.
727+
- '-fdebug-default-version=4'
723728
needs:
724729
- autoconf
725730
- bdb
@@ -745,6 +750,7 @@ x86_64-unknown-linux-gnu:
745750
- xz
746751
- zlib
747752
openssl_target: linux-x86_64
753+
bolt_capable: true
748754

749755
x86_64_v2-unknown-linux-gnu:
750756
host_platforms:
@@ -762,6 +768,8 @@ x86_64_v2-unknown-linux-gnu:
762768
target_cflags:
763769
- '-march=x86-64-v2'
764770
- '-fvisibility=hidden'
771+
# Needed to prevent BOLT from crashing.
772+
- '-fdebug-default-version=4'
765773
needs:
766774
- autoconf
767775
- bdb
@@ -787,6 +795,7 @@ x86_64_v2-unknown-linux-gnu:
787795
- xz
788796
- zlib
789797
openssl_target: linux-x86_64
798+
bolt_capable: true
790799

791800
x86_64_v3-unknown-linux-gnu:
792801
host_platforms:
@@ -804,6 +813,8 @@ x86_64_v3-unknown-linux-gnu:
804813
target_cflags:
805814
- '-march=x86-64-v3'
806815
- '-fvisibility=hidden'
816+
# Needed to prevent BOLT from crashing.
817+
- '-fdebug-default-version=4'
807818
needs:
808819
- autoconf
809820
- bdb
@@ -829,6 +840,7 @@ x86_64_v3-unknown-linux-gnu:
829840
- xz
830841
- zlib
831842
openssl_target: linux-x86_64
843+
bolt_capable: true
832844

833845
x86_64_v4-unknown-linux-gnu:
834846
host_platforms:
@@ -846,6 +858,8 @@ x86_64_v4-unknown-linux-gnu:
846858
target_cflags:
847859
- '-march=x86-64-v4'
848860
- '-fvisibility=hidden'
861+
# Needed to prevent BOLT from crashing.
862+
- '-fdebug-default-version=4'
849863
needs:
850864
- autoconf
851865
- bdb
@@ -871,6 +885,7 @@ x86_64_v4-unknown-linux-gnu:
871885
- xz
872886
- zlib
873887
openssl_target: linux-x86_64
888+
bolt_capable: true
874889

875890
x86_64-unknown-linux-musl:
876891
host_platforms:

docs/running.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,9 @@ Common configurations include:
138138
``pgo``
139139
Profile guided optimization.
140140

141+
Starting with CPython 3.12, BOLT is also applied alongside traditional
142+
PGO on platforms supporting BOLT. (Currently just Linux x86-64.)
143+
141144
``lto``
142145
Link-time optimization.
143146

0 commit comments

Comments
 (0)