Skip to content

Commit 2ff9048

Browse files
authored
Configure BOLT behavior through BOLT_{COMMON,APPLY}_FLAGS (#1178)
Configure BOLT behavior using the `BOLT_COMMON_FLAGS` and `BOLT_APPLY_FLAGS` environment variables. The existing BOLT behavior is preserved. Previously patches were used to modify the default values defined in configure.ac This approach allows complete control over the BOLT behavior and makes the configuration easier to test, debug and update in the future. Would make the existing patches unnecessary. closes #877 closes #878 closes #879
1 parent 89de021 commit 2ff9048

6 files changed

Lines changed: 27 additions & 171 deletions

cpython-unix/build-cpython.sh

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -226,31 +226,6 @@ if [ -n "${PYTHON_MEETS_MINIMUM_VERSION_3_11}" ]; then
226226
patch -p1 -i "${ROOT}/patch-pwd-remove-conditional.patch"
227227
fi
228228

229-
if [ -n "${PYTHON_MEETS_MINIMUM_VERSION_3_12}" ]; then
230-
# Additional BOLT optimizations, being upstreamed in
231-
# https://github.com/python/cpython/issues/128514
232-
patch -p1 -i "${ROOT}/patch-configure-bolt-apply-flags-128514.patch"
233-
234-
# Disable unsafe identical code folding. Objects/typeobject.c
235-
# update_one_slot requires that wrap_binaryfunc != wrap_binaryfunc_l,
236-
# despite the functions being identical.
237-
# https://github.com/python/cpython/pull/134642
238-
patch -p1 -i "${ROOT}/patch-configure-bolt-icf-safe.patch"
239-
240-
# Tweak --skip-funcs to work with our toolchain.
241-
if [ -n "${PYTHON_MEETS_MINIMUM_VERSION_3_15}" ]; then
242-
patch -p1 -i "${ROOT}/patch-configure-bolt-skip-funcs-3.15.patch"
243-
else
244-
patch -p1 -i "${ROOT}/patch-configure-bolt-skip-funcs.patch"
245-
fi
246-
247-
# Remove -use-gnu-stack from the BOLT optimization flags as it incorrectly
248-
# removes the PT_GNU_STACK segment. This patch can be removed when this bug
249-
# is fixed in LLVM.
250-
# https://github.com/llvm/llvm-project/issues/174191
251-
patch -p1 -i "${ROOT}/patch-configure-bolt-remove-use-gnu-stack.patch"
252-
fi
253-
254229
# The optimization make targets are both phony and non-phony. This leads
255230
# to PGO targets getting reevaluated after a build when you use multiple
256231
# make invocations. e.g. `make install` like we do below. Fix that.
@@ -498,6 +473,31 @@ if [ -n "${CPYTHON_OPTIMIZED}" ]; then
498473
CONFIGURE_FLAGS="${CONFIGURE_FLAGS} --enable-optimizations"
499474
if [[ -n "${PYTHON_MEETS_MINIMUM_VERSION_3_12}" && -n "${BOLT_CAPABLE}" ]]; then
500475
CONFIGURE_FLAGS="${CONFIGURE_FLAGS} --enable-bolt"
476+
477+
# CPython allows overriding the default BOLT flags via configure
478+
# environment variables. Use our toolchain-specific skip list, add
479+
# additional optimizations, use safe identical code folding, and omit
480+
# -use-gnu-stack because it incorrectly removes the PT_GNU_STACK
481+
# segment.
482+
# https://github.com/python/cpython/issues/128514
483+
# https://github.com/python/cpython/pull/134642
484+
# https://github.com/llvm/llvm-project/issues/174191
485+
BOLT_COMMON_FLAGS="-update-debug-sections -skip-funcs=RC4_options/1"
486+
BOLT_APPLY_FLAGS="${BOLT_COMMON_FLAGS} \
487+
-reorder-blocks=ext-tsp \
488+
-reorder-functions=cdsort \
489+
-split-functions \
490+
-split-strategy=cdsplit \
491+
-icf=safe \
492+
-inline-all \
493+
-split-eh \
494+
-reorder-functions-use-hot-size \
495+
-peepholes=none \
496+
-jump-tables=aggressive \
497+
-inline-ap \
498+
-indirect-call-promotion=all \
499+
-dyno-stats \
500+
-frame-opt=hot"
501501
fi
502502

503503
# Allow users to enable the experimental JIT on 3.13+
@@ -774,7 +774,8 @@ if [[ -n "${PYTHON_MEETS_MINIMUM_VERSION_3_14}" && "${TARGET_TRIPLE}" == x86_64*
774774
CFLAGS_JIT="${CFLAGS_JIT//-fPIC/}"
775775
fi
776776

777-
CFLAGS=$CFLAGS CPPFLAGS=$CFLAGS CFLAGS_JIT=$CFLAGS_JIT LDFLAGS=$LDFLAGS \
777+
BOLT_COMMON_FLAGS="${BOLT_COMMON_FLAGS:-}" BOLT_APPLY_FLAGS="${BOLT_APPLY_FLAGS:-}" \
778+
CFLAGS=$CFLAGS CPPFLAGS=$CFLAGS CFLAGS_JIT=$CFLAGS_JIT LDFLAGS=$LDFLAGS \
778779
./configure ${CONFIGURE_FLAGS}
779780

780781
# Supplement produced Makefile with our modifications.

cpython-unix/patch-configure-bolt-apply-flags-128514.patch

Lines changed: 0 additions & 14 deletions
This file was deleted.

cpython-unix/patch-configure-bolt-icf-safe.patch

Lines changed: 0 additions & 84 deletions
This file was deleted.

cpython-unix/patch-configure-bolt-remove-use-gnu-stack.patch

Lines changed: 0 additions & 12 deletions
This file was deleted.

cpython-unix/patch-configure-bolt-skip-funcs-3.15.patch

Lines changed: 0 additions & 18 deletions
This file was deleted.

cpython-unix/patch-configure-bolt-skip-funcs.patch

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)