Skip to content

Commit

Permalink
unix: enable BOLT optimizations on Linux x86-64
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
indygreg committed Oct 2, 2023
1 parent ff3734d commit c1f1c16
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
3 changes: 3 additions & 0 deletions cpython-unix/build-cpython.sh
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,9 @@ fi

if [ -n "${CPYTHON_OPTIMIZED}" ]; then
CONFIGURE_FLAGS="${CONFIGURE_FLAGS} --enable-optimizations"
if [[ -n "${PYTHON_MEETS_MINIMUM_VERSION_3_12}" && -n "${BOLT_CAPABLE}" ]]; then
CONFIGURE_FLAGS="${CONFIGURE_FLAGS} --enable-bolt"
fi
fi

if [ -n "${CPYTHON_LTO}" ]; then
Expand Down
3 changes: 3 additions & 0 deletions cpython-unix/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ def add_target_env(env, build_platform, target_triple, build_env):
env["HOST_CXX"] = settings["host_cxx"]
env["CC"] = settings["target_cc"]

if settings.get("bolt_capable"):
env["BOLT_CAPABLE"] = "1"

env["PYBUILD_PLATFORM"] = build_platform
env["TOOLS_PATH"] = build_env.tools_path

Expand Down
15 changes: 15 additions & 0 deletions cpython-unix/targets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@
#
# openssl_target
# Name of OpenSSL platform build target.
#
# bolt_capable
# Whether the target is capable of performing BOLT optimizations.

---

Expand Down Expand Up @@ -720,6 +723,8 @@ x86_64-unknown-linux-gnu:
target_cc: clang
target_cflags:
- '-fvisibility=hidden'
# Needed to prevent BOLT from crashing.
- '-fdebug-default-version=4'
needs:
- autoconf
- bdb
Expand All @@ -745,6 +750,7 @@ x86_64-unknown-linux-gnu:
- xz
- zlib
openssl_target: linux-x86_64
bolt_capable: true

x86_64_v2-unknown-linux-gnu:
host_platforms:
Expand All @@ -762,6 +768,8 @@ x86_64_v2-unknown-linux-gnu:
target_cflags:
- '-march=x86-64-v2'
- '-fvisibility=hidden'
# Needed to prevent BOLT from crashing.
- '-fdebug-default-version=4'
needs:
- autoconf
- bdb
Expand All @@ -787,6 +795,7 @@ x86_64_v2-unknown-linux-gnu:
- xz
- zlib
openssl_target: linux-x86_64
bolt_capable: true

x86_64_v3-unknown-linux-gnu:
host_platforms:
Expand All @@ -804,6 +813,8 @@ x86_64_v3-unknown-linux-gnu:
target_cflags:
- '-march=x86-64-v3'
- '-fvisibility=hidden'
# Needed to prevent BOLT from crashing.
- '-fdebug-default-version=4'
needs:
- autoconf
- bdb
Expand All @@ -829,6 +840,7 @@ x86_64_v3-unknown-linux-gnu:
- xz
- zlib
openssl_target: linux-x86_64
bolt_capable: true

x86_64_v4-unknown-linux-gnu:
host_platforms:
Expand All @@ -846,6 +858,8 @@ x86_64_v4-unknown-linux-gnu:
target_cflags:
- '-march=x86-64-v4'
- '-fvisibility=hidden'
# Needed to prevent BOLT from crashing.
- '-fdebug-default-version=4'
needs:
- autoconf
- bdb
Expand All @@ -871,6 +885,7 @@ x86_64_v4-unknown-linux-gnu:
- xz
- zlib
openssl_target: linux-x86_64
bolt_capable: true

x86_64-unknown-linux-musl:
host_platforms:
Expand Down
3 changes: 3 additions & 0 deletions docs/running.rst
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ Common configurations include:
``pgo``
Profile guided optimization.

Starting with CPython 3.12, BOLT is also applied alongside traditional
PGO on platforms supporting BOLT. (Currently just Linux x86-64.)

``lto``
Link-time optimization.

Expand Down

0 comments on commit c1f1c16

Please sign in to comment.