@@ -43,6 +43,11 @@ LDVERSION= @LDVERSION@
4343HGVERSION= @HGVERSION@
4444HGTAG= @HGTAG@
4545HGBRANCH= @HGBRANCH@
46+ PGO_PROF_GEN_FLAG=@PGO_PROF_GEN_FLAG@
47+ PGO_PROF_USE_FLAG=@PGO_PROF_USE_FLAG@
48+ LLVM_PROF_MERGER=@LLVM_PROF_MERGER@
49+ LLVM_PROF_FILE=@LLVM_PROF_FILE@
50+ LLVM_PROF_ERR=@LLVM_PROF_ERR@
4651
4752GNULD= @GNULD@
4853
@@ -226,8 +231,7 @@ TCLTK_INCLUDES= @TCLTK_INCLUDES@
226231TCLTK_LIBS= @TCLTK_LIBS@
227232
228233# The task to run while instrument when building the profile-opt target
229- PROFILE_TASK= $(srcdir)/Tools/pybench/pybench.py -n 2 --with-gc --with-syscheck
230- #PROFILE_TASK= $(srcdir)/Lib/test/regrtest.py
234+ PROFILE_TASK=-m test.regrtest >/dev/null 2>&1
231235
232236# report files for gcov / lcov coverage report
233237COVERAGE_INFO= $(abs_builddir)/coverage.info
@@ -477,27 +481,38 @@ LIBRARY_OBJS= \
477481all: build_all
478482build_all: $(BUILDPYTHON) oldsharedmods sharedmods gdbhooks Programs/_testembed python-config
479483
480- # Compile a binary with gcc profile guided optimization.
484+ # Compile a binary with profile guided optimization.
481485profile-opt:
486+ @if [ $(LLVM_PROF_ERR) == yes ]; then \
487+ echo "Error: Cannot perform PGO build because llvm-profdata was not found in PATH" ;\
488+ echo "Please add it to PATH and run ./configure again" ;\
489+ exit 1;\
490+ fi
482491 @echo "Building with support for profile generation:"
483492 $(MAKE) clean
493+ $(MAKE) profile-removal
484494 $(MAKE) build_all_generate_profile
485- @echo "Running benchmark to generate profile data:"
486495 $(MAKE) profile-removal
496+ @echo "Running code to generate profile data (this can take a while):"
487497 $(MAKE) run_profile_task
498+ $(MAKE) build_all_merge_profile
488499 @echo "Rebuilding with profile guided optimizations:"
489500 $(MAKE) clean
490501 $(MAKE) build_all_use_profile
502+ $(MAKE) profile-removal
491503
492504build_all_generate_profile:
493- $(MAKE) all CFLAGS_NODIST="$(CFLAGS) -fprofile-generate " LDFLAGS="-fprofile-generate " LIBS="$(LIBS) -lgcov "
505+ $(MAKE) all CFLAGS_NODIST="$(CFLAGS) $(PGO_PROF_GEN_FLAG) " LDFLAGS="$(LDFLAGS) $(PGO_PROF_GEN_FLAG) " LIBS="$(LIBS)"
494506
495507run_profile_task:
496508 : # FIXME: can't run for a cross build
497- $(RUNSHARED) ./$(BUILDPYTHON) $(PROFILE_TASK)
509+ $(LLVM_PROF_FILE) $(RUNSHARED) ./$(BUILDPYTHON) $(PROFILE_TASK) || true
510+
511+ build_all_merge_profile:
512+ $(LLVM_PROF_MERGER)
498513
499514build_all_use_profile:
500- $(MAKE) all CFLAGS_NODIST="$(CFLAGS) -fprofile-use -fprofile-correction "
515+ $(MAKE) all CFLAGS_NODIST="$(CFLAGS) $(PGO_PROF_USE_FLAG) "
501516
502517# Compile and run with gcov
503518.PHONY=coverage coverage-lcov coverage-report
@@ -1568,9 +1583,11 @@ clean: pycremoval
15681583 -rm -f pybuilddir.txt
15691584 -rm -f Lib/lib2to3/*Grammar*.pickle
15701585 -rm -f Programs/_testembed Programs/_freeze_importlib
1586+ -rm -rf build
15711587
15721588profile-removal:
15731589 find . -name '*.gc??' -exec rm -f {} ';'
1590+ find . -name '*.profclang?' -exec rm -f {} ';'
15741591 rm -f $(COVERAGE_INFO)
15751592 rm -rf $(COVERAGE_REPORT)
15761593
0 commit comments