# Author: Alecsandru Patrascu diff -r e3dea2e4f93d Makefile.pre.in --- a/Makefile.pre.in Mon Nov 23 08:50:20 2015 +0200 +++ b/Makefile.pre.in Mon Nov 23 15:54:52 2015 +0200 @@ -47,6 +47,7 @@ LLVM_PROF_MERGER=@LLVM_PROF_MERGER@ LLVM_PROF_FILE=@LLVM_PROF_FILE@ LLVM_PROF_ERR=@LLVM_PROF_ERR@ +LTOFLAGS=@LTOFLAGS@ GNULD= @GNULD@ @@ -73,12 +74,12 @@ # Compiler options OPT= @OPT@ BASECFLAGS= @BASECFLAGS@ -CFLAGS= $(BASECFLAGS) @CFLAGS@ $(OPT) $(EXTRA_CFLAGS) +CFLAGS= $(BASECFLAGS) @CFLAGS@ $(OPT) $(LTOFLAGS) $(EXTRA_CFLAGS) # Both CPPFLAGS and LDFLAGS need to contain the shell's value for setup.py to # be able to build extension modules using the directories specified in the # environment variables CPPFLAGS= -I. -IInclude -I$(srcdir)/Include @CPPFLAGS@ -LDFLAGS= @LDFLAGS@ +LDFLAGS= @LDFLAGS@ $(LTOFLAGS) LDLAST= @LDLAST@ SGI_ABI= @SGI_ABI@ CCSHARED= @CCSHARED@ @@ -445,7 +446,7 @@ $(MAKE) profile-removal build_all_generate_profile: - $(MAKE) all CFLAGS="$(CFLAGS) $(PGO_PROF_GEN_FLAG)" LDFLAGS="$(LDFLAGS) $(PGO_PROF_GEN_FLAG)" LIBS="$(LIBS)" + $(MAKE) all CFLAGS="$(CFLAGS) $(PGO_PROF_GEN_FLAG) $(LTOFLAGS)" LDFLAGS="$(LDFLAGS) $(PGO_PROF_GEN_FLAG) $(LTOFLAGS)" LIBS="$(LIBS)" run_profile_task: : # FIXME: can't run for a cross build @@ -455,7 +456,7 @@ $(LLVM_PROF_MERGER) build_all_use_profile: - $(MAKE) all CFLAGS="$(CFLAGS) $(PGO_PROF_USE_FLAG)" + $(MAKE) all CFLAGS="$(CFLAGS) $(PGO_PROF_USE_FLAG) $(LTOFLAGS)" LDFLAGS="$(LDFLAGS) $(LTOFLAGS)" coverage: @echo "Building with support for coverage checking:" diff -r e3dea2e4f93d configure --- a/configure Mon Nov 23 08:50:20 2015 +0200 +++ b/configure Mon Nov 23 15:54:52 2015 +0200 @@ -667,6 +667,7 @@ LLVM_PROF_MERGER PGO_PROF_USE_FLAG PGO_PROF_GEN_FLAG +LTOFLAGS UNIVERSAL_ARCH_FLAGS BASECFLAGS OPT @@ -794,6 +795,7 @@ enable_shared enable_profiling with_pydebug +with_lto enable_toolbox_glue with_libs with_system_expat @@ -1474,6 +1476,7 @@ compiler --with-suffix=.exe set executable suffix --with-pydebug build with Py_DEBUG defined + --with-lto Enable Link Time Optimizations. Disabled by default. --with-libs='lib1 ...' link against additional libs --with-system-expat build pyexpat module using an installed expat library @@ -6333,6 +6336,39 @@ fi +# Enable LTO flags +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for --with-lto" >&5 +$as_echo_n "checking for --with-lto... " >&6; } +# Check whether --with-lto was given. +if test "${with_lto+set}" = set; then : + withval=$with_lto; +if test "$withval" != no +then + case $CC in + *clang*) + # Any changes made here should be reflected in the GCC+Darwin case below + LTOFLAGS="-flto" + ;; + *gcc*) + case $ac_sys_system in + Darwin*) + LTOFLAGS="-flto" + ;; + *) + LTOFLAGS="-flto -fuse-linker-plugin -ffat-lto-objects -flto-partition=none" + ;; + esac + ;; + esac + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; }; +fi +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + # Enable PGO flags. # Extract the first word of "llvm-profdata", so it can be a program name with args. set dummy llvm-profdata; ac_word=$2 diff -r e3dea2e4f93d configure.ac --- a/configure.ac Mon Nov 23 08:50:20 2015 +0200 +++ b/configure.ac Mon Nov 23 15:54:52 2015 +0200 @@ -1353,6 +1353,34 @@ fi +# Enable LTO flags +AC_SUBST(LTOFLAGS) +AC_MSG_CHECKING(for --with-lto) +AC_ARG_WITH(lto, AS_HELP_STRING([--with-lto], [Enable Link Time Optimizations. Disabled by default.]), +[ +if test "$withval" != no +then + case $CC in + *clang*) + # Any changes made here should be reflected in the GCC+Darwin case below + LTOFLAGS="-flto" + ;; + *gcc*) + case $ac_sys_system in + Darwin*) + LTOFLAGS="-flto" + ;; + *) + LTOFLAGS="-flto -fuse-linker-plugin -ffat-lto-objects -flto-partition=none" + ;; + esac + ;; + esac + AC_MSG_RESULT(yes); +fi], +[AC_MSG_RESULT(no)]) + + # Enable PGO flags. AC_SUBST(PGO_PROF_GEN_FLAG) AC_SUBST(PGO_PROF_USE_FLAG)