Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 79a12a2

Browse files
committed
Issue #25702: A --with-lto configure option has been added that will
enable link time optimizations at build time during a make profile-opt.
2 parents a9dd804 + d82da9f commit 79a12a2

4 files changed

Lines changed: 87 additions & 2 deletions

File tree

Makefile.pre.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ profile-opt:
504504
$(MAKE) profile-removal
505505

506506
build_all_generate_profile:
507-
$(MAKE) all CFLAGS_NODIST="$(CFLAGS) $(PGO_PROF_GEN_FLAG)" LDFLAGS="$(LDFLAGS) $(PGO_PROF_GEN_FLAG)" LIBS="$(LIBS)"
507+
$(MAKE) all CFLAGS_NODIST="$(CFLAGS) $(PGO_PROF_GEN_FLAG) @LTOFLAGS@" LDFLAGS="$(LDFLAGS) $(PGO_PROF_GEN_FLAG) @LTOFLAGS@" LIBS="$(LIBS)"
508508

509509
run_profile_task:
510510
: # FIXME: can't run for a cross build
@@ -514,7 +514,7 @@ build_all_merge_profile:
514514
$(LLVM_PROF_MERGER)
515515

516516
build_all_use_profile:
517-
$(MAKE) all CFLAGS_NODIST="$(CFLAGS) $(PGO_PROF_USE_FLAG)"
517+
$(MAKE) all CFLAGS_NODIST="$(CFLAGS) $(PGO_PROF_USE_FLAG) @LTOFLAGS@" LDFLAGS="$(LDFLAGS) @LTOFLAGS@"
518518

519519
# Compile and run with gcov
520520
.PHONY=coverage coverage-lcov coverage-report

Misc/NEWS

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -976,6 +976,12 @@ Tests
976976
Build
977977
-----
978978

979+
- Issue #25702: A --with-lto configure option has been added that will
980+
enable link time optimizations at build time during a make profile-opt.
981+
Some compilers and toolchains are known to not produce stable code when
982+
using LTO, be sure to test things thoroughly before relying on it.
983+
It can provide a few % speed up over profile-opt alone.
984+
979985
- Issue #26624: Adds validation of ucrtbase[d].dll version with warning
980986
for old versions.
981987

configure

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,7 @@ LLVM_PROF_FILE
673673
LLVM_PROF_MERGER
674674
PGO_PROF_USE_FLAG
675675
PGO_PROF_GEN_FLAG
676+
LTOFLAGS
676677
ABIFLAGS
677678
LN
678679
MKDIR_P
@@ -807,6 +808,7 @@ with_suffix
807808
enable_shared
808809
enable_profiling
809810
with_pydebug
811+
with_lto
810812
with_hash_algorithm
811813
with_address_sanitizer
812814
with_libs
@@ -1487,6 +1489,8 @@ Optional Packages:
14871489
compiler
14881490
--with-suffix=.exe set executable suffix
14891491
--with-pydebug build with Py_DEBUG defined
1492+
--with-lto Enable Link Time Optimization in PGO builds.
1493+
Disabled by default.
14901494
--with-hash-algorithm=[fnv|siphash24]
14911495
select hash algorithm
14921496
--with-address-sanitizer
@@ -6560,6 +6564,48 @@ $as_echo "no" >&6; }
65606564
fi
65616565

65626566

6567+
# Enable LTO flags
6568+
6569+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for --with-lto" >&5
6570+
$as_echo_n "checking for --with-lto... " >&6; }
6571+
6572+
# Check whether --with-lto was given.
6573+
if test "${with_lto+set}" = set; then :
6574+
withval=$with_lto;
6575+
if test "$withval" != no
6576+
then
6577+
Py_LTO='true'
6578+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
6579+
$as_echo "yes" >&6; };
6580+
else
6581+
Py_LTO='false'
6582+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
6583+
$as_echo "no" >&6; };
6584+
fi
6585+
else
6586+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
6587+
$as_echo "no" >&6; }
6588+
fi
6589+
6590+
if test "$Py_LTO" = 'true' ; then
6591+
case $CC in
6592+
*clang*)
6593+
# Any changes made here should be reflected in the GCC+Darwin case below
6594+
LTOFLAGS="-flto"
6595+
;;
6596+
*gcc*)
6597+
case $ac_sys_system in
6598+
Darwin*)
6599+
LTOFLAGS="-flto"
6600+
;;
6601+
*)
6602+
LTOFLAGS="-flto -fuse-linker-plugin -ffat-lto-objects -flto-partition=none"
6603+
;;
6604+
esac
6605+
;;
6606+
esac
6607+
fi
6608+
65636609
# Enable PGO flags.
65646610

65656611

configure.ac

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,6 +1235,39 @@ else AC_MSG_RESULT(no); Py_DEBUG='false'
12351235
fi],
12361236
[AC_MSG_RESULT(no)])
12371237

1238+
# Enable LTO flags
1239+
AC_SUBST(LTOFLAGS)
1240+
AC_MSG_CHECKING(for --with-lto)
1241+
AC_ARG_WITH(lto, AS_HELP_STRING([--with-lto], [Enable Link Time Optimization in PGO builds. Disabled by default.]),
1242+
[
1243+
if test "$withval" != no
1244+
then
1245+
Py_LTO='true'
1246+
AC_MSG_RESULT(yes);
1247+
else
1248+
Py_LTO='false'
1249+
AC_MSG_RESULT(no);
1250+
fi],
1251+
[AC_MSG_RESULT(no)])
1252+
if test "$Py_LTO" = 'true' ; then
1253+
case $CC in
1254+
*clang*)
1255+
# Any changes made here should be reflected in the GCC+Darwin case below
1256+
LTOFLAGS="-flto"
1257+
;;
1258+
*gcc*)
1259+
case $ac_sys_system in
1260+
Darwin*)
1261+
LTOFLAGS="-flto"
1262+
;;
1263+
*)
1264+
LTOFLAGS="-flto -fuse-linker-plugin -ffat-lto-objects -flto-partition=none"
1265+
;;
1266+
esac
1267+
;;
1268+
esac
1269+
fi
1270+
12381271
# Enable PGO flags.
12391272
AC_SUBST(PGO_PROF_GEN_FLAG)
12401273
AC_SUBST(PGO_PROF_USE_FLAG)

0 commit comments

Comments
 (0)