Skip to content

gh-89536: Use ThinLTO policy if possible #96766

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

Merged
merged 2 commits into from
Sep 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Doc/using/configure.rst
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,9 @@ also be used to improve performance.
.. versionadded:: 3.11
To use ThinLTO feature, use ``--with-lto=thin`` on Clang.

.. versionchanged:: 3.12
Use ThinLTO as the default optimization policy on Clang if the compiler accepts the flag.

.. cmdoption:: --enable-bolt

Enable usage of the `BOLT post-link binary optimizer
Expand Down
4 changes: 4 additions & 0 deletions Doc/whatsnew/3.12.rst
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,10 @@ Build Changes
``va_start()`` is no longer called with a single parameter.
(Contributed by Kumar Aditya in :gh:`93207`.)

* CPython now uses the ThinLTO option as the default link time optimization policy
if the Clang compiler accepts the flag.
(Contributed by Dong-hee Na in :gh:`89536`.)


C API Changes
=============
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CPython now uses the ThinLTO option as the default policy if the Clang
compiler accepts the flag. Patch by Dong-hee Na.
82 changes: 79 additions & 3 deletions configure

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 11 additions & 3 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -1863,8 +1863,15 @@ if test "$Py_LTO" = 'true' ; then
# Any changes made here should be reflected in the GCC+Darwin case below
if test $Py_LTO_POLICY = default
then
LTOFLAGS="-flto -Wl,-export_dynamic -Wl,-object_path_lto,\"\$@\".lto"
LTOCFLAGS="-flto"
# Check that ThinLTO is accepted.
AX_CHECK_COMPILE_FLAG([-flto=thin],[
LTOFLAGS="-flto=thin -Wl,-export_dynamic -Wl,-object_path_lto,\"\$@\".lto"
LTOCFLAGS="-flto=thin"
],[
LTOFLAGS="-flto -Wl,-export_dynamic -Wl,-object_path_lto,\"\$@\".lto"
LTOCFLAGS="-flto"
]
)
else
LTOFLAGS="-flto=${Py_LTO_POLICY} -Wl,-export_dynamic -Wl,-object_path_lto,\"\$@\".lto"
LTOCFLAGS="-flto=${Py_LTO_POLICY}"
Expand All @@ -1873,7 +1880,8 @@ if test "$Py_LTO" = 'true' ; then
*)
if test $Py_LTO_POLICY = default
then
LTOFLAGS="-flto"
# Check that ThinLTO is accepted
AX_CHECK_COMPILE_FLAG([-flto=thin],[LTOFLAGS="-flto=thin"],[LTOFLAGS="-flto"])
else
LTOFLAGS="-flto=${Py_LTO_POLICY}"
fi
Expand Down