Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 35.2k
gh-101282: Apply BOLT optimisations to libpython for shared builds#104709
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -672,21 +672,55 @@ profile-opt: profile-run-stamp | ||
| -rm -f profile-clean-stamp | ||
| $(MAKE) @DEF_MAKE_RULE@ CFLAGS_NODIST="$(CFLAGS_NODIST) $(PGO_PROF_USE_FLAG)" LDFLAGS_NODIST="$(LDFLAGS_NODIST)" | ||
| .PHONY: bolt-opt | ||
| bolt-opt: @PREBOLT_RULE@ | ||
| # List of binaries that BOLT runs on. | ||
| BOLT_BINARIES := @BOLT_BINARIES@ | ||
| BOLT_INSTRUMENT_FLAGS := @BOLT_INSTRUMENT_FLAGS@ | ||
| BOLT_APPLY_FLAGS := @BOLT_APPLY_FLAGS@ | ||
| .PHONY: clean-bolt | ||
| clean-bolt: | ||
| # Profile data. | ||
| rm -f *.fdata | ||
| @if $(READELF) -p .note.bolt_info $(BUILDPYTHON) | grep BOLT > /dev/null; then\ | ||
| echo "skip: $(BUILDPYTHON) is already BOLTed."; \ | ||
| else \ | ||
| @LLVM_BOLT@ ./$(BUILDPYTHON) -instrument -instrumentation-file-append-pid -instrumentation-file=$(abspath $(BUILDPYTHON).bolt) -o $(BUILDPYTHON).bolt_inst; \ | ||
| ./$(BUILDPYTHON).bolt_inst $(PROFILE_TASK) || true; \ | ||
| @MERGE_FDATA@ $(BUILDPYTHON).*.fdata > $(BUILDPYTHON).fdata; \ | ||
| @LLVM_BOLT@ ./$(BUILDPYTHON) -o $(BUILDPYTHON).bolt -data=$(BUILDPYTHON).fdata -update-debug-sections -reorder-blocks=ext-tsp -reorder-functions=hfsort+ -split-functions -icf=1 -inline-all -split-eh -reorder-functions-use-hot-size -peepholes=none -jump-tables=aggressive -inline-ap -indirect-call-promotion=all -dyno-stats -use-gnu-stack -frame-opt=hot; \ | ||
| rm -f *.fdata; \ | ||
| rm -f $(BUILDPYTHON).bolt_inst; \ | ||
| mv $(BUILDPYTHON).bolt $(BUILDPYTHON); \ | ||
| fi | ||
| # Pristine binaries before BOLT optimization. | ||
| rm -f *.prebolt | ||
| # BOLT instrumented binaries. | ||
| rm -f *.bolt_inst | ||
| profile-bolt-stamp: $(BUILDPYTHON) | ||
| # Ensure a pristine, pre-BOLT copy of the binary and no profile data from last run. | ||
| for bin in $(BOLT_BINARIES); do \ | ||
| prebolt="$${bin}.prebolt"; \ | ||
| if [ -e "$${prebolt}" ]; then \ | ||
| echo "Restoring pre-BOLT binary $${prebolt}"; \ | ||
| mv "$${bin}.prebolt" "$${bin}"; \ | ||
| fi; \ | ||
| cp "$${bin}" "$${prebolt}"; \ | ||
| rm -f $${bin}.bolt.*.fdata $${bin}.fdata; \ | ||
| done | ||
| # Instrument each binary. | ||
| for bin in $(BOLT_BINARIES); do \ | ||
| @LLVM_BOLT@ "$${bin}" -instrument -instrumentation-file-append-pid -instrumentation-file=$(abspath $${bin}.bolt) -o $${bin}.bolt_inst $(BOLT_INSTRUMENT_FLAGS); \ | ||
erlend-aasland marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| mv "$${bin}.bolt_inst" "$${bin}"; \ | ||
| done | ||
| # Run instrumented binaries to collect data. | ||
| $(RUNSHARED) ./$(BUILDPYTHON) $(PROFILE_TASK) || true | ||
| # Merge all the data files together. | ||
| for bin in $(BOLT_BINARIES); do \ | ||
| @MERGE_FDATA@ $${bin}.*.fdata > "$${bin}.fdata"; \ | ||
erlend-aasland marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| rm -f $${bin}.*.fdata; \ | ||
| done | ||
| # Run bolt against the merged data to produce an optimized binary. | ||
| for bin in $(BOLT_BINARIES); do \ | ||
| @LLVM_BOLT@ "$${bin}.prebolt" -o "$${bin}.bolt" -data="$${bin}.fdata" $(BOLT_APPLY_FLAGS); \ | ||
| mv "$${bin}.bolt" "$${bin}"; \ | ||
| done | ||
| touch $@ | ||
| .PHONY: bolt-opt | ||
| bolt-opt: | ||
| $(MAKE) @PREBOLT_RULE@ | ||
| $(MAKE) profile-bolt-stamp | ||
| # Compile and run with gcov | ||
| .PHONY: coverage | ||
| @@ -2623,10 +2657,11 @@ profile-removal: | ||
| rm -f $(COVERAGE_INFO) | ||
| rm -rf $(COVERAGE_REPORT) | ||
| rm -f profile-run-stamp | ||
| rm -f profile-bolt-stamp | ||
| .PHONY: clean | ||
| clean: clean-retain-profile | ||
| @if test @DEF_MAKE_ALL_RULE@ = profile-opt; then \ | ||
| clean: clean-retain-profile clean-bolt | ||
| @if test @DEF_MAKE_ALL_RULE@ = profile-opt -o @DEF_MAKE_ALL_RULE@ = bolt-opt; then \ | ||
| rm -f profile-gen-stamp profile-clean-stamp; \ | ||
| $(MAKE) profile-removal; \ | ||
| fi | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| BOLT optimization is now applied to the libpython shared library if building | ||
| a shared library. BOLT instrumentation and application settings can now be | ||
| influenced via the ``BOLT_INSTRUMENT_FLAGS`` and ``BOLT_APPLY_FLAGS`` | ||
| configure variables. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -2028,13 +2028,6 @@ if test "$Py_BOLT" = 'true' ; then | ||
| DEF_MAKE_ALL_RULE="bolt-opt" | ||
| DEF_MAKE_RULE="build_all" | ||
| AC_SUBST(READELF) | ||
| AC_CHECK_TOOLS(READELF, [readelf], "notfound") | ||
| if test "$READELF" == "notfound" | ||
| then | ||
| AC_MSG_ERROR([readelf is required for a --enable-bolt build but could not be found.]) | ||
| fi | ||
| # -fno-reorder-blocks-and-partition is required for bolt to work. | ||
| # Possibly GCC only. | ||
| AX_CHECK_COMPILE_FLAG([-fno-reorder-blocks-and-partition],[ | ||
| @@ -2067,6 +2060,54 @@ if test "$Py_BOLT" = 'true' ; then | ||
| fi | ||
| fi | ||
| dnl Enable BOLT of libpython if built. | ||
| AC_SUBST(BOLT_BINARIES) | ||
| BOLT_BINARIES='$(BUILDPYTHON)' | ||
| AS_VAR_IF([enable_shared], [yes], [ | ||
| BOLT_BINARIES="${BOLT_BINARIES} \$(INSTSONAME)" | ||
| ]) | ||
| AC_ARG_VAR( | ||
| [BOLT_INSTRUMENT_FLAGS], | ||
| [Arguments to llvm-bolt when instrumenting binaries] | ||
| ) | ||
| AC_MSG_CHECKING([BOLT_INSTRUMENT_FLAGS]) | ||
| if test -z "${BOLT_INSTRUMENT_FLAGS}" | ||
| then | ||
| BOLT_INSTRUMENT_FLAGS= | ||
| fi | ||
| AC_MSG_RESULT([$BOLT_INSTRUMENT_FLAGS]) | ||
| AC_ARG_VAR( | ||
| [BOLT_APPLY_FLAGS], | ||
| [Arguments to llvm-bolt when creating a BOLT optimized binary] | ||
| ) | ||
| AC_MSG_CHECKING([BOLT_APPLY_FLAGS]) | ||
| if test -z "${BOLT_APPLY_FLAGS}" | ||
| then | ||
| AS_VAR_SET( | ||
| [BOLT_APPLY_FLAGS], | ||
| [m4_join([ ], | ||
| [-update-debug-sections], | ||
| [-reorder-blocks=ext-tsp], | ||
| [-reorder-functions=hfsort+], | ||
| [-split-functions], | ||
| [-icf=1], | ||
| [-inline-all], | ||
| [-split-eh], | ||
| [-reorder-functions-use-hot-size], | ||
| [-peepholes=none], | ||
| [-jump-tables=aggressive], | ||
| [-inline-ap], | ||
| [-indirect-call-promotion=all], | ||
| [-dyno-stats], | ||
| [-use-gnu-stack], | ||
| [-frame-opt=hot] | ||
erlend-aasland marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| )] | ||
| ) | ||
| fi | ||
| AC_MSG_RESULT([$BOLT_APPLY_FLAGS]) | ||
| # XXX Shouldn't the code above that fiddles with BASECFLAGS and OPT be | ||
| # merged with this chunk of code? | ||
Uh oh!
There was an error while loading. Please reload this page.