diff -r da483bda6efc Makefile.pre.in --- a/Makefile.pre.in Mon Aug 24 16:17:13 2015 -0400 +++ b/Makefile.pre.in Wed Aug 26 19:11:31 2015 +0300 @@ -42,6 +42,10 @@ HGVERSION= @HGVERSION@ HGTAG= @HGTAG@ HGBRANCH= @HGBRANCH@ +PGO_PROF_GEN_FLAG=@PGO_PROF_GEN_FLAG@ +PGO_PROF_USE_FLAG=@PGO_PROF_USE_FLAG@ +LLVM_PROF_MERGER=@LLVM_PROF_MERGER@ +LLVM_PROF_FILE=@LLVM_PROF_FILE@ GNULD= @GNULD@ @@ -204,8 +208,8 @@ TCLTK_LIBS= @TCLTK_LIBS@ # The task to run while instrument when building the profile-opt target -PROFILE_TASK= $(srcdir)/Tools/pybench/pybench.py -n 2 --with-gc --with-syscheck -#PROFILE_TASK= $(srcdir)/Lib/test/regrtest.py +PROFILE_TASK_X86=-m test.regrtest +PROFILE_TASK_OLD=$(srcdir)/Tools/pybench/pybench.py -n 2 --with-gc --with-syscheck # === Definitions added by makesetup === @@ -422,25 +426,38 @@ # Compile a binary with gcc profile guided optimization. profile-opt: + @if [ `uname -m | grep 86` == '' ];then \ + @echo "Profile generation was tested only on x86 architectures" ;\ + fi @echo "Building with support for profile generation:" $(MAKE) clean + $(MAKE) profile-removal $(MAKE) build_all_generate_profile @echo "Running benchmark to generate profile data:" $(MAKE) profile-removal $(MAKE) run_profile_task + $(MAKE) build_all_merge_profile @echo "Rebuilding with profile guided optimizations:" $(MAKE) clean $(MAKE) build_all_use_profile + $(MAKE) profile-removal build_all_generate_profile: - $(MAKE) all CFLAGS="$(CFLAGS) -fprofile-generate" LIBS="$(LIBS) -lgcov" + $(MAKE) all CFLAGS="$(CFLAGS) $(PGO_PROF_GEN_FLAG)" LDFLAGS="$(LDFLAGS) $(PGO_PROF_GEN_FLAG)" LIBS="$(LIBS)" run_profile_task: : # FIXME: can't run for a cross build - ./$(BUILDPYTHON) $(PROFILE_TASK) + @if [ `uname -m | grep 86` == '' ];then \ + $(LLVM_PROF_FILE) ./$(BUILDPYTHON) $(PROFILE_TASK_OLD) || true ;\ + else \ + $(LLVM_PROF_FILE) ./$(BUILDPYTHON) $(PROFILE_TASK_X86) || true ;\ + fi + +build_all_merge_profile: + $(LLVM_PROF_MERGER) build_all_use_profile: - $(MAKE) all CFLAGS="$(CFLAGS) -fprofile-use" + $(MAKE) all CFLAGS="$(CFLAGS) $(PGO_PROF_USE_FLAG)" coverage: @echo "Building with support for coverage checking:" @@ -1330,9 +1347,11 @@ find build -name 'fficonfig.h' -exec rm -f {} ';' || true find build -name 'fficonfig.py' -exec rm -f {} ';' || true -rm -f Lib/lib2to3/*Grammar*.pickle + -rm -rf build profile-removal: find . -name '*.gc??' -exec rm -f {} ';' + find . -name '*.profclang?' -exec rm -f {} ';' clobber: clean profile-removal -rm -f $(BUILDPYTHON) $(PGEN) $(LIBRARY) $(LDLIBRARY) $(DLLLIBRARY) \ diff -r da483bda6efc configure.ac --- a/configure.ac Mon Aug 24 16:17:13 2015 -0400 +++ b/configure.ac Wed Aug 26 19:11:31 2015 +0300 @@ -1352,6 +1352,38 @@ CFLAGS=$save_CFLAGS fi + +# enable PGO flags +AC_SUBST(PGO_PROF_GEN_FLAG) +AC_SUBST(PGO_PROF_USE_FLAG) +AC_SUBST(LLVM_PROF_MERGER) +AC_SUBST(LLVM_PROF_FILE) +case $CC in + *clang*) + PGO_PROF_GEN_FLAG="-fprofile-instr-generate" + PGO_PROF_USE_FLAG="-fprofile-instr-use=code.profclangd" + LLVM_PROF_MERGER="llvm-profdata merge -output=code.profclangd *.profclangr" + LLVM_PROF_FILE="LLVM_PROFILE_FILE=\"code-%p.profclangr\"" + ;; + *gcc*) + case $ac_sys_system in + Darwin*) + PGO_PROF_GEN_FLAG="-fprofile-instr-generate" + PGO_PROF_USE_FLAG="-fprofile-instr-use=code.profclangd" + LLVM_PROF_MERGER="llvm-profdata merge -output=code.profclangd *.profclangr" + LLVM_PROF_FILE="LLVM_PROFILE_FILE=\"code-%p.profclangr\"" + ;; + *) + PGO_PROF_GEN_FLAG="-fprofile-generate" + PGO_PROF_USE_FLAG="-fprofile-use -fprofile-correction" + LLVM_PROF_MERGER="true" + LLVM_PROF_FILE="" + ;; + esac + ;; +esac + + # On some compilers, pthreads are available without further options # (e.g. MacOS X). On some of these systems, the compiler will not # complain if unaccepted options are passed (e.g. gcc on Mac OS X).