From: Dhruv Chawla <[email protected]>

Switch autoprofiledbootstrap and DejaGnu AutoFDO profile generation from
the external create_gcov/profile_merger tools to in-tree afdo_create and
afdo_merge while retaining the existing CREATE_GCOV and PROFILE_MERGER
variable names.

Add AFDO_GCOV_VERSION so callers can select the generated profile format.
When it is unset, query the stage1 compiler for its supported format.
Resolve relative CREATE_GCOV values against the GCC build directory in
profopt.exp, and compare afdo_tools normally because every stage builds it
from the same sources.

ChangeLog:

        * Makefile.tpl (CREATE_GCOV): Point at afdo_tools/afdo_create.
        (PROFILE_MERGER): Point at afdo_tools/afdo_merge.
        (AFDO_GCOV_VERSION): New variable.
        (EXTRA_HOST_FLAGS): Pass it.
        * Makefile.in: Regenerate.

gcc/ChangeLog:

        * Makefile.in (AFDO_GCOV_VERSION_ARG): New variable.
        (all.fda): Use it.

gcc/c/ChangeLog:

        * Make-lang.in (cc1.fda, create_fdas_for_cc1): Use CREATE_GCOV
        and AFDO_GCOV_VERSION_ARG.

gcc/cp/ChangeLog:

        * Make-lang.in (cc1plus.fda, create_fdas_for_cc1plus): Use
        CREATE_GCOV and AFDO_GCOV_VERSION_ARG.

gcc/lto/ChangeLog:

        * Make-lang.in (lto1.fda, create_fdas_for_lto1): Use CREATE_GCOV
        and AFDO_GCOV_VERSION_ARG.

gcc/testsuite/ChangeLog:

        * lib/profopt.exp (profopt-execute): Honour AFDO_GCOV_VERSION and
        resolve CREATE_GCOV against the GCC build directory.

Signed-off-by: Dhruv Chawla <[email protected]>
Co-authored-by: Kugan Vivekanandarajah <[email protected]>
Co-authored-by: Rahul Shinde <[email protected]>
---
 Makefile.in                   | 11 ++++++++---
 Makefile.tpl                  | 11 ++++++++---
 gcc/Makefile.in               |  6 +++++-
 gcc/c/Make-lang.in            |  6 +++---
 gcc/cp/Make-lang.in           |  6 +++---
 gcc/lto/Make-lang.in          |  6 +++---
 gcc/testsuite/lib/profopt.exp | 17 ++++++++++++++---
 7 files changed, 44 insertions(+), 19 deletions(-)

diff --git a/Makefile.in b/Makefile.in
index c4749792177..1926ccfbd0a 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -515,8 +515,12 @@ PGO_BUILD_USE_FLAGS_TO_PASS = \
 PGO-TRAINING-TARGETS = binutils gas gdb ld sim
 PGO_BUILD_TRAINING = $(addprefix maybe-check-,$(PGO-TRAINING-TARGETS))
 
-CREATE_GCOV = create_gcov
-PROFILE_MERGER = profile_merger
+CREATE_GCOV = ../afdo_tools/afdo_create
+PROFILE_MERGER = ../afdo_tools/afdo_merge
+
+# Profile format version to generate.  Queried from the compiler using
+# --print-autofdo-gcov-version if empty.
+AFDO_GCOV_VERSION =
 
 TFLAGS =
 
@@ -1052,7 +1056,8 @@ EXTRA_HOST_FLAGS = \
        'WINDRES=$(WINDRES)' \
        'WINDMC=$(WINDMC)' \
        'CREATE_GCOV=$(CREATE_GCOV)' \
-       'PROFILE_MERGER=$(PROFILE_MERGER)'
+       'PROFILE_MERGER=$(PROFILE_MERGER)' \
+       'AFDO_GCOV_VERSION=$(AFDO_GCOV_VERSION)'
 
 FLAGS_TO_PASS = $(BASE_FLAGS_TO_PASS) $(EXTRA_HOST_FLAGS)
 
diff --git a/Makefile.tpl b/Makefile.tpl
index 07b434e4343..6d4b0652b10 100644
--- a/Makefile.tpl
+++ b/Makefile.tpl
@@ -518,8 +518,12 @@ PGO_BUILD_USE_FLAGS_TO_PASS = \
 PGO-TRAINING-TARGETS = binutils gas gdb ld sim
 PGO_BUILD_TRAINING = $(addprefix maybe-check-,$(PGO-TRAINING-TARGETS))
 
-CREATE_GCOV = create_gcov
-PROFILE_MERGER = profile_merger
+CREATE_GCOV = ../afdo_tools/afdo_create
+PROFILE_MERGER = ../afdo_tools/afdo_merge
+
+# Profile format version to generate.  Queried from the compiler using
+# --print-autofdo-gcov-version if empty.
+AFDO_GCOV_VERSION =
 
 TFLAGS =
 
@@ -777,7 +781,8 @@ EXTRA_HOST_FLAGS = \
        'WINDRES=$(WINDRES)' \
        'WINDMC=$(WINDMC)' \
        'CREATE_GCOV=$(CREATE_GCOV)' \
-       'PROFILE_MERGER=$(PROFILE_MERGER)'
+       'PROFILE_MERGER=$(PROFILE_MERGER)' \
+       'AFDO_GCOV_VERSION=$(AFDO_GCOV_VERSION)'
 
 FLAGS_TO_PASS = $(BASE_FLAGS_TO_PASS) $(EXTRA_HOST_FLAGS)
 
diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index c718585e607..9d43004613c 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -1962,6 +1962,10 @@ PERF = @PERF@
 # The profiler to be used by autoprofiledbootstrap
 AFDO_PROFILER = @AFDO_PROFILER@
 
+# -gcov_version argument for CREATE_GCOV and PROFILE_MERGER.  Unless the
+# top level pinned AFDO_GCOV_VERSION, ask the compiler being profiled.
+AFDO_GCOV_VERSION_ARG = -gcov_version $(if 
$(AFDO_GCOV_VERSION),$(AFDO_GCOV_VERSION),`../stage1-gcc/xgcc$(exeext) 
--print-autofdo-gcov-version`)
+
 # This lists all host object files, whether they are included in this
 # compilation or not.
 ALL_HOST_OBJS = $(ALL_HOST_FRONTEND_OBJS) $(ALL_HOST_BACKEND_OBJS)
@@ -4876,7 +4880,7 @@ paranoia: paranoia.o real.o $(LIBIBERTY)
        g++ -o $@ paranoia.o real.o $(LIBIBERTY)
 
 all.fda: $(ALL_FDAS)
-       $(PROFILE_MERGER) $(ALL_FDAS) --output_file all.fda -gcov_version 
`../stage1-gcc/xgcc$(exeext) --print-autofdo-gcov-version`
+       $(PROFILE_MERGER) $(ALL_FDAS) --output_file all.fda 
$(AFDO_GCOV_VERSION_ARG)
 
 # These exist for maintenance purposes.
 
diff --git a/gcc/c/Make-lang.in b/gcc/c/Make-lang.in
index ecfa366afe3..1c1d0a115e4 100644
--- a/gcc/c/Make-lang.in
+++ b/gcc/c/Make-lang.in
@@ -93,7 +93,7 @@ components_in_prev = "bfd opcodes binutils fixincludes gas 
gcc gmp mpfr mpc isl
 components_in_prev_target = "libstdc++-v3 libsanitizer libvtv libgcc 
libbacktrace libphobos zlib libgomp libatomic"
 
 cc1.fda: create_fdas_for_cc1
-       $(PROFILE_MERGER) $(shell ls -ha cc1_*.fda) --output_file cc1.fda 
-gcov_version `../stage1-gcc/xgcc$(exeext) --print-autofdo-gcov-version`
+       $(PROFILE_MERGER) $(shell ls -ha cc1_*.fda) --output_file cc1.fda 
$(AFDO_GCOV_VERSION_ARG)
 
 create_fdas_for_cc1: ../stage1-gcc/cc1$(exeext) ../prev-gcc/$(PERF_DATA)
        for component_in_prev in "$(components_in_prev)"; do \
@@ -102,7 +102,7 @@ create_fdas_for_cc1: ../stage1-gcc/cc1$(exeext) 
../prev-gcc/$(PERF_DATA)
          if [ -f $$perf_path ]; then \
            profile_name=cc1_$$component_in_prev.fda; \
            if [ "x`$(PERF) buildid-list -i $$perf_path | grep '/cc1$$' && echo 
yes`" != "x" ]; then \
-             $(CREATE_GCOV) -binary ../stage1-gcc/cc1$(exeext) -gcov 
$$profile_name -profile $$perf_path -profiler $(AFDO_PROFILER) -gcov_version 
`../stage1-gcc/xgcc$(exeext) --print-autofdo-gcov-version` || exit 1; \
+             $(CREATE_GCOV) -binary ../stage1-gcc/cc1$(exeext) -gcov 
$$profile_name -profile $$perf_path -profiler $(AFDO_PROFILER) 
$(AFDO_GCOV_VERSION_ARG) || exit 1; \
            else \
              echo "  warning: $$perf_path is missing cc1!"; \
            fi; \
@@ -115,7 +115,7 @@ create_fdas_for_cc1: ../stage1-gcc/cc1$(exeext) 
../prev-gcc/$(PERF_DATA)
          if [ -f $$perf_path ]; then \
            profile_name=cc1_$$component_in_prev_target.fda; \
            if [ "x`$(PERF) buildid-list -i $$perf_path | grep '/cc1$$' && echo 
yes`" != "x" ]; then \
-             $(CREATE_GCOV) -binary ../prev-gcc/cc1$(exeext) -gcov 
$$profile_name -profile $$perf_path -profiler $(AFDO_PROFILER) -gcov_version 
`../prev-gcc/xgcc$(exeext) --print-autofdo-gcov-version` || exit 1; \
+             $(CREATE_GCOV) -binary ../prev-gcc/cc1$(exeext) -gcov 
$$profile_name -profile $$perf_path -profiler $(AFDO_PROFILER) 
$(AFDO_GCOV_VERSION_ARG) || exit 1; \
            else \
              echo "  warning: $$perf_path is missing cc1!"; \
            fi; \
diff --git a/gcc/cp/Make-lang.in b/gcc/cp/Make-lang.in
index e262854face..e26941c8a26 100644
--- a/gcc/cp/Make-lang.in
+++ b/gcc/cp/Make-lang.in
@@ -210,7 +210,7 @@ components_in_prev = "bfd opcodes binutils fixincludes gas 
gcc gmp mpfr mpc isl
 components_in_prev_target = "libstdc++-v3 libsanitizer libvtv libgcc 
libbacktrace libphobos zlib libgomp libatomic"
 
 cc1plus.fda: create_fdas_for_cc1plus
-       $(PROFILE_MERGER) $(shell ls -ha cc1plus_*.fda) --output_file 
cc1plus.fda -gcov_version `../stage1-gcc/xgcc$(exeext) 
--print-autofdo-gcov-version`
+       $(PROFILE_MERGER) $(shell ls -ha cc1plus_*.fda) --output_file 
cc1plus.fda $(AFDO_GCOV_VERSION_ARG)
 
 create_fdas_for_cc1plus: ../stage1-gcc/cc1plus$(exeext) 
../prev-gcc/$(PERF_DATA)
        for component_in_prev in "$(components_in_prev)"; do \
@@ -219,7 +219,7 @@ create_fdas_for_cc1plus: ../stage1-gcc/cc1plus$(exeext) 
../prev-gcc/$(PERF_DATA)
          if [ -f $$perf_path ]; then \
            profile_name=cc1plus_$$component_in_prev.fda; \
            if [ "x`$(PERF) buildid-list -i $$perf_path | grep '/cc1plus$$' && 
echo yes`" != "x" ]; then \
-             $(CREATE_GCOV) -binary ../stage1-gcc/cc1plus$(exeext) -gcov 
$$profile_name -profile $$perf_path -profiler $(AFDO_PROFILER) -gcov_version 
`../stage1-gcc/xgcc$(exeext) --print-autofdo-gcov-version` || exit 1; \
+             $(CREATE_GCOV) -binary ../stage1-gcc/cc1plus$(exeext) -gcov 
$$profile_name -profile $$perf_path -profiler $(AFDO_PROFILER) 
$(AFDO_GCOV_VERSION_ARG) || exit 1; \
            else \
              echo "  warning: $$perf_path is missing cc1plus!"; \
            fi; \
@@ -232,7 +232,7 @@ create_fdas_for_cc1plus: ../stage1-gcc/cc1plus$(exeext) 
../prev-gcc/$(PERF_DATA)
          if [ -f $$perf_path ]; then \
            profile_name=cc1plus_$$component_in_prev_target.fda; \
            if [ "x`$(PERF) buildid-list -i $$perf_path | grep '/cc1plus$$' && 
echo yes`" != "x" ]; then \
-             $(CREATE_GCOV) -binary ../prev-gcc/cc1plus$(exeext) -gcov 
$$profile_name -profile $$perf_path -profiler $(AFDO_PROFILER) -gcov_version 
`../prev-gcc/xgcc$(exeext) --print-autofdo-gcov-version` || exit 1; \
+             $(CREATE_GCOV) -binary ../prev-gcc/cc1plus$(exeext) -gcov 
$$profile_name -profile $$perf_path -profiler $(AFDO_PROFILER) 
$(AFDO_GCOV_VERSION_ARG) || exit 1; \
            else \
              echo " warning: $$perf_path is missing cc1plus!"; \
            fi; \
diff --git a/gcc/lto/Make-lang.in b/gcc/lto/Make-lang.in
index 2090d3365af..6cb83e39b2c 100644
--- a/gcc/lto/Make-lang.in
+++ b/gcc/lto/Make-lang.in
@@ -106,7 +106,7 @@ components_in_prev = "bfd opcodes binutils fixincludes gas 
gcc gmp mpfr mpc isl
 components_in_prev_target = "libstdc++-v3 libsanitizer libvtv libgcc 
libbacktrace libphobos zlib libgomp libatomic"
 
 lto1.fda: create_fdas_for_lto1
-       $(PROFILE_MERGER) $(shell ls -ha lto1_*.fda) --output_file lto1.fda 
-gcov_version `../stage1-gcc/xgcc$(exeext) --print-autofdo-gcov-version`
+       $(PROFILE_MERGER) $(shell ls -ha lto1_*.fda) --output_file lto1.fda 
$(AFDO_GCOV_VERSION_ARG)
 
 create_fdas_for_lto1: ../stage1-gcc/lto1$(exeext) ../prev-gcc/$(PERF_DATA)
        for component_in_prev in "$(components_in_prev)"; do \
@@ -115,7 +115,7 @@ create_fdas_for_lto1: ../stage1-gcc/lto1$(exeext) 
../prev-gcc/$(PERF_DATA)
          if [ -f $$perf_path ]; then \
            profile_name=lto1_$$component_in_prev.fda; \
            if [ "x`$(PERF) buildid-list -i $$perf_path | grep '/lto1$$' && 
echo yes`" != "x" ]; then \
-             $(CREATE_GCOV) -binary ../stage1-gcc/lto1$(exeext) -gcov 
$$profile_name -profile $$perf_path -profiler $(AFDO_PROFILER) -gcov_version 
`../stage1-gcc/xgcc$(exeext) --print-autofdo-gcov-version` || exit 1; \
+             $(CREATE_GCOV) -binary ../stage1-gcc/lto1$(exeext) -gcov 
$$profile_name -profile $$perf_path -profiler $(AFDO_PROFILER) 
$(AFDO_GCOV_VERSION_ARG) || exit 1; \
            else \
              echo "  warning: $$perf_path is missing lto1!"; \
            fi; \
@@ -128,7 +128,7 @@ create_fdas_for_lto1: ../stage1-gcc/lto1$(exeext) 
../prev-gcc/$(PERF_DATA)
          if [ -f $$perf_path ]; then \
            profile_name=lto1_$$component_in_prev_target.fda; \
            if [ "x`$(PERF) buildid-list -i $$perf_path | grep '/lto1$$' && 
echo yes`" != "x" ]; then \
-             $(CREATE_GCOV) -binary ../prev-gcc/lto1$(exeext) -gcov 
$$profile_name -profile $$perf_path -profiler $(AFDO_PROFILER) -gcov_version 
`../prev-gcc/xgcc$(exeext) --print-autofdo-gcov-version` || exit 1; \
+             $(CREATE_GCOV) -binary ../prev-gcc/lto1$(exeext) -gcov 
$$profile_name -profile $$perf_path -profiler $(AFDO_PROFILER) 
$(AFDO_GCOV_VERSION_ARG) || exit 1; \
            else \
              echo "  warning: $$perf_path is missing lto1!"; \
            fi; \
diff --git a/gcc/testsuite/lib/profopt.exp b/gcc/testsuite/lib/profopt.exp
index cd80d5e9402..0595665ab70 100644
--- a/gcc/testsuite/lib/profopt.exp
+++ b/gcc/testsuite/lib/profopt.exp
@@ -455,22 +455,33 @@ proc profopt-execute { src } {
            if { $run_autofdo == 1 } {
                 set bprefix "afdo."
                set compiler [lindex $GCC_UNDER_TEST 0]
-               set autofdo_version [string trim [lindex [remote_exec target 
"$compiler --print-autofdo-gcov-version"] 1] ]
+               set autofdo_version "[getenv AFDO_GCOV_VERSION]"
+               if { $autofdo_version == "" } {
+                   set autofdo_version [string trim [lindex [remote_exec 
target "$compiler --print-autofdo-gcov-version"] 1] ]
+               }
                set profiler_check [string trim [lindex [remote_exec target 
"perf --no-pager list pmu | grep arm_spe"] 1]]
                if {$profiler_check ne ""} {
                    set profiler "perf_spe"
                } else {
                    set profiler "perf"
                }
+               # $CREATE_GCOV may be relative to the gcc build directory, as
+               # the top level passes it that way; resolve it there first.
                set create_gcov "[getenv CREATE_GCOV]"
                if { $create_gcov == "" } {
-                   set create_gcov "create_gcov"
+                   set create_gcov "../afdo_tools/afdo_create"
+               }
+               set gccdir [file dirname $compiler]
+               set create_gcov_abs \
+                   [file normalize [file join $gccdir $create_gcov]]
+               if { [file executable $create_gcov_abs] } {
+                   set create_gcov $create_gcov_abs
                }
                set cmd "$create_gcov --binary $execname1 
--profile=$tmpdir/$base.perf.data --profiler=$profiler 
--gcov_version=$autofdo_version --gcov=$tmpdir/$bprefix$base.$ext"
                verbose "Running $cmd"
                set id [remote_spawn "" $cmd]
                if { $id < 0 } {
-                   unsupported "$testcase -fauto-profile: cannot run 
create_gcov"
+                   unsupported "$testcase -fauto-profile: cannot run 
$create_gcov"
                    unset testname_with_flags
                    set status "fail"
                    cleanup-after-saved-dg-test
-- 
2.34.1

Reply via email to