]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-89536: Use ThinLTO policy if possible (gh-96766)
authorDong-hee Na <donghee.na@python.org>
Fri, 16 Sep 2022 10:40:05 +0000 (19:40 +0900)
committerGitHub <noreply@github.com>
Fri, 16 Sep 2022 10:40:05 +0000 (19:40 +0900)
Doc/using/configure.rst
Doc/whatsnew/3.12.rst
Misc/NEWS.d/next/Build/2022-09-12-18-34-51.gh-issue-85936.tX4VCU.rst [new file with mode: 0644]
configure
configure.ac

index cd5540320c4f855a442fc3ec0f6e1b83acd1aae9..ec57c880ee7ad02da73dc86e15a671ac35153241 100644 (file)
@@ -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
index 90355a73f080049070789e26e985f24ae8782be7..7c7a196fcc1ca37423740a66456bf193432bc969 100644 (file)
@@ -453,6 +453,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
 =============
diff --git a/Misc/NEWS.d/next/Build/2022-09-12-18-34-51.gh-issue-85936.tX4VCU.rst b/Misc/NEWS.d/next/Build/2022-09-12-18-34-51.gh-issue-85936.tX4VCU.rst
new file mode 100644 (file)
index 0000000..302b863
--- /dev/null
@@ -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.
index b2024bab2fb065949fd355f497e828f4cec35109..08ec2161cba086f114a86cfe6879223e1ec2c389 100755 (executable)
--- a/configure
+++ b/configure
@@ -7837,8 +7837,49 @@ $as_echo "$as_me: llvm-ar found via xcrun: ${LLVM_AR}" >&6;}
           # 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.
+            { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether C compiler accepts -flto=thin" >&5
+$as_echo_n "checking whether C compiler accepts -flto=thin... " >&6; }
+if ${ax_cv_check_cflags___flto_thin+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+
+  ax_check_save_flags=$CFLAGS
+  CFLAGS="$CFLAGS  -flto=thin"
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  ax_cv_check_cflags___flto_thin=yes
+else
+  ax_cv_check_cflags___flto_thin=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+  CFLAGS=$ax_check_save_flags
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ax_cv_check_cflags___flto_thin" >&5
+$as_echo "$ax_cv_check_cflags___flto_thin" >&6; }
+if test "x$ax_cv_check_cflags___flto_thin" = xyes; then :
+
+              LTOFLAGS="-flto=thin -Wl,-export_dynamic -Wl,-object_path_lto,\"\$@\".lto"
+              LTOCFLAGS="-flto=thin"
+
+else
+
+              LTOFLAGS="-flto -Wl,-export_dynamic -Wl,-object_path_lto,\"\$@\".lto"
+              LTOCFLAGS="-flto"
+
+
+fi
+
           else
             LTOFLAGS="-flto=${Py_LTO_POLICY} -Wl,-export_dynamic -Wl,-object_path_lto,\"\$@\".lto"
             LTOCFLAGS="-flto=${Py_LTO_POLICY}"
@@ -7847,7 +7888,42 @@ $as_echo "$as_me: llvm-ar found via xcrun: ${LLVM_AR}" >&6;}
         *)
           if test $Py_LTO_POLICY = default
           then
-            LTOFLAGS="-flto"
+            # Check that ThinLTO is accepted
+            { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether C compiler accepts -flto=thin" >&5
+$as_echo_n "checking whether C compiler accepts -flto=thin... " >&6; }
+if ${ax_cv_check_cflags___flto_thin+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+
+  ax_check_save_flags=$CFLAGS
+  CFLAGS="$CFLAGS  -flto=thin"
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  ax_cv_check_cflags___flto_thin=yes
+else
+  ax_cv_check_cflags___flto_thin=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+  CFLAGS=$ax_check_save_flags
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ax_cv_check_cflags___flto_thin" >&5
+$as_echo "$ax_cv_check_cflags___flto_thin" >&6; }
+if test "x$ax_cv_check_cflags___flto_thin" = xyes; then :
+  LTOFLAGS="-flto=thin"
+else
+  LTOFLAGS="-flto"
+fi
+
           else
             LTOFLAGS="-flto=${Py_LTO_POLICY}"
           fi
index a61adcc817e82f5b43b79a80545f50102e63f65b..7d2e83cac8197e776b84b1a7e96a0c8be55e9fb4 100644 (file)
@@ -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}"
@@ -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