AutoFDO: Add --print-autofdo-gcov-version

This option prints the current version of GCOV that is being used by the
AutoFDO infrastructure. This avoids the need to bump the number across
multiple files in the build system for future increments to it.

Bootstrapped and regtested on aarch64-linux-gnu.

Signed-off-by: Dhruv Chawla <dhruvc@nvidia.com>

gcc/ChangeLog:

	* Makefile.in (all.fda): Add `--print-autofdo-gcov-version` to
	profile_merger invocation.
	* auto-profile.cc (AUTO_PROFILE_VERSION): Move from here ...
	* auto-profile.h (AUTO_PROFILE_VERSION): ... to here.
	* common.opt: Add -print-autofdo-gcov-version and
	--print-autofdo-gcov-version.
	* doc/invoke.texi: Document the options.
	* gcc.cc: Add include for auto-profile.h.
	(driver_handle_option): Add OPT_print_autofdo_gcov_version.
	(driver::maybe_print_and_exit): Handle the option.

gcc/c/ChangeLog:

	* Make-lang.in (cc1.fda): Add `--print-autofdo-gcov-version` to
	profile_merger invocation.
	(create_fdas_for_cc1): Add `--print-autofdo-gcov-version` to
	create_gcov invocations.

gcc/cp/ChangeLog:

	* Make-lang.in (cc1plus.fda): Add `--print-autofdo-gcov-version` to
	profile_merger invocation.
	(create_fdas_for_cc1plus): Add `--print-autofdo-gcov-version` to
	create_gcov invocations.

gcc/lto/ChangeLog:

	* Make-lang.in (lto1.fda): Add `--print-autofdo-gcov-version` to
	profile_merger invocation.
	(create_fdas_for_lto1): Add `--print-autofdo-gcov-version` to
	create_gcov invocations.

gcc/testsuite/ChangeLog:

	* lib/profopt.exp: Invoke $GCC_UNDER_TEST with
	`--print-autofdo-gcov-version` before running create_gcov to get
	the GCOV version.
This commit is contained in:
Dhruv Chawla
2026-01-12 04:07:03 -08:00
parent bb0515578b
commit 17880c0f39
10 changed files with 37 additions and 12 deletions

View File

@@ -4819,7 +4819,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 3
$(PROFILE_MERGER) $(ALL_FDAS) --output_file all.fda -gcov_version `../stage1-gcc/xgcc$(exeext) --print-autofdo-gcov-version`
# These exist for maintenance purposes.

View File

@@ -122,7 +122,6 @@ along with GCC; see the file COPYING3. If not see
*/
#define DEFAULT_AUTO_PROFILE_FILE "fbdata.afdo"
#define AUTO_PROFILE_VERSION 3
/* profile counts determined by AFDO smaller than afdo_hot_bb_threshold are
considered cols. */

View File

@@ -21,6 +21,8 @@ along with GCC; see the file COPYING3. If not see
#ifndef AUTO_PROFILE_H
#define AUTO_PROFILE_H
#define AUTO_PROFILE_VERSION 3
/* Read, process, finalize AutoFDO data structures. */
extern void read_autofdo_file (void);
extern void end_auto_profile (void);

View File

@@ -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 3
$(PROFILE_MERGER) $(shell ls -ha cc1_*.fda) --output_file cc1.fda -gcov_version `../stage1-gcc/xgcc$(exeext) --print-autofdo-gcov-version`
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)
echo $$perf_path; \
if [ -f $$perf_path ]; then \
profile_name=cc1_$$component_in_prev.fda; \
$(CREATE_GCOV) -binary ../stage1-gcc/cc1$(exeext) -gcov $$profile_name -profile $$perf_path -gcov_version 3 || exit 1; \
$(CREATE_GCOV) -binary ../stage1-gcc/cc1$(exeext) -gcov $$profile_name -profile $$perf_path -gcov_version `../stage1-gcc/xgcc$(exeext) --print-autofdo-gcov-version` || exit 1; \
fi; \
done;
@@ -112,7 +112,7 @@ create_fdas_for_cc1: ../stage1-gcc/cc1$(exeext) ../prev-gcc/$(PERF_DATA)
echo $$perf_path; \
if [ -f $$perf_path ]; then \
profile_name=cc1_$$component_in_prev_target.fda; \
$(CREATE_GCOV) -binary ../prev-gcc/cc1$(exeext) -gcov $$profile_name -profile $$perf_path -gcov_version 3 || exit 1; \
$(CREATE_GCOV) -binary ../prev-gcc/cc1$(exeext) -gcov $$profile_name -profile $$perf_path -gcov_version `../prev-gcc/xgcc$(exeext) --print-autofdo-gcov-version` || exit 1; \
fi; \
done;

View File

@@ -349,6 +349,9 @@ Driver JoinedOrMissing Alias(B)
-preprocess
Driver Alias(E)
-print-autofdo-gcov-version
Driver Alias(print-autofdo-gcov-version)
-print-file-name
Driver Separate Alias(print-file-name=)
@@ -3902,6 +3905,9 @@ Driver
pipe
Driver Var(use_pipes)
print-autofdo-gcov-version
Driver Var(print_autofdo_gcov_version)
print-file-name=
Driver JoinedOrMissing Var(print_file_name)

View File

@@ -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 3
$(PROFILE_MERGER) $(shell ls -ha cc1plus_*.fda) --output_file cc1plus.fda -gcov_version `../stage1-gcc/xgcc$(exeext) --print-autofdo-gcov-version`
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)
echo $$perf_path; \
if [ -f $$perf_path ]; then \
profile_name=cc1plus_$$component_in_prev.fda; \
$(CREATE_GCOV) -binary ../stage1-gcc/cc1plus$(exeext) -gcov $$profile_name -profile $$perf_path -gcov_version 3 || exit 1; \
$(CREATE_GCOV) -binary ../stage1-gcc/cc1plus$(exeext) -gcov $$profile_name -profile $$perf_path -gcov_version `../stage1-gcc/xgcc$(exeext) --print-autofdo-gcov-version` || exit 1; \
fi; \
done;
@@ -229,7 +229,7 @@ create_fdas_for_cc1plus: ../stage1-gcc/cc1plus$(exeext) ../prev-gcc/$(PERF_DATA)
echo $$perf_path; \
if [ -f $$perf_path ]; then \
profile_name=cc1plus_$$component_in_prev_target.fda; \
$(CREATE_GCOV) -binary ../prev-gcc/cc1plus$(exeext) -gcov $$profile_name -profile $$perf_path -gcov_version 3 || exit 1; \
$(CREATE_GCOV) -binary ../prev-gcc/cc1plus$(exeext) -gcov $$profile_name -profile $$perf_path -gcov_version `../prev-gcc/xgcc$(exeext) --print-autofdo-gcov-version` || exit 1; \
fi; \
done;

View File

@@ -864,6 +864,7 @@ Objective-C and Objective-C++ Dialects}.
-fsel-sched-verbose -fsel-sched-dump-cfg -fsel-sched-pipelining-verbose
-fstats -fstack-usage -ftime-report -ftime-report-details
-fvar-tracking-assignments-toggle -gtoggle
-print-autofdo-gcov-version
-print-file-name=@var{library} -print-libgcc-file-name
-print-multi-directory -print-multi-lib -print-multi-os-directory
-print-multiarch
@@ -872,6 +873,7 @@ Objective-C and Objective-C++ Dialects}.
-save-temps -save-temps=cwd -save-temps=obj
-specs=@var{file} -time@r{[}=@var{file}@r{]}
--dump=@var{letters}
--print-autofdo-gcov-version
--print-file-name=@var{library} --print-libgcc-file-file-name
--print-multi-directory --print-multi-lib --print-multi-os-directory
--print-multiarch --print-prog-name=@var{program}
@@ -21028,6 +21030,11 @@ For example, with @option{-fdbg-cnt=dce:2-4:10-11,tail_call:10},
eleventh invocation.
For @code{dbg_cnt(tail_call)} true is returned for first 10 invocations.
@opindex print-autofdo-gcov-version
@item -print-autofdo-gcov-version
@itemx --print-autofdo-gcov-version
Print the current version of GCOV being used by the AutoFDO infrastructure.
@opindex print-file-name
@item -print-file-name=@var{library}
@itemx --print-file-name=@var{library}

View File

@@ -54,6 +54,7 @@ compilation is specified by a string called a "spec". */
#include "common/common-target.h"
#include "gcc-urlifier.h"
#include "opts-diagnostic.h"
#include "auto-profile.h" /* for AUTO_PROFILE_VERSION. */
#ifndef MATH_LIBRARY
#define MATH_LIBRARY "m"
@@ -4297,6 +4298,7 @@ driver_handle_option (struct gcc_options *opts,
case OPT__no_sysroot_suffix:
case OPT_pass_exit_codes:
case OPT_print_search_dirs:
case OPT_print_autofdo_gcov_version:
case OPT_print_file_name_:
case OPT_print_prog_name_:
case OPT_print_multi_lib:
@@ -8830,6 +8832,12 @@ driver::maybe_print_and_exit () const
return (0);
}
if (print_autofdo_gcov_version)
{
printf ("%d\n", AUTO_PROFILE_VERSION);
return (0);
}
if (print_file_name)
{
printf ("%s\n", find_file (print_file_name));

View File

@@ -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 3
$(PROFILE_MERGER) $(shell ls -ha lto1_*.fda) --output_file lto1.fda -gcov_version `../stage1-gcc/xgcc$(exeext) --print-autofdo-gcov-version`
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)
echo $$perf_path; \
if [ -f $$perf_path ]; then \
profile_name=lto1_$$component_in_prev.fda; \
$(CREATE_GCOV) -binary ../stage1-gcc/lto1$(exeext) -gcov $$profile_name -profile $$perf_path -gcov_version 3 || exit 1; \
$(CREATE_GCOV) -binary ../stage1-gcc/lto1$(exeext) -gcov $$profile_name -profile $$perf_path -gcov_version `../stage1-gcc/xgcc$(exeext) --print-autofdo-gcov-version` || exit 1; \
fi; \
done;
@@ -125,7 +125,7 @@ create_fdas_for_lto1: ../stage1-gcc/lto1$(exeext) ../prev-gcc/$(PERF_DATA)
echo $$perf_path; \
if [ -f $$perf_path ]; then \
profile_name=lto1_$$component_in_prev_target.fda; \
$(CREATE_GCOV) -binary ../prev-gcc/lto1$(exeext) -gcov $$profile_name -profile $$perf_path -gcov_version 3 || exit 1; \
$(CREATE_GCOV) -binary ../prev-gcc/lto1$(exeext) -gcov $$profile_name -profile $$perf_path -gcov_version `../prev-gcc/xgcc$(exeext) --print-autofdo-gcov-version` || exit 1; \
fi; \
done;

View File

@@ -313,6 +313,7 @@ proc profopt-execute { src } {
global verbose
global testname_with_flags
global additional_sources_used
global GCC_UNDER_TEST
if ![info exists profile_option] {
error "No profile option specified for first compile."
@@ -453,7 +454,9 @@ proc profopt-execute { src } {
# convert profile
if { $run_autofdo == 1 } {
set bprefix "afdo."
set cmd "create_gcov --binary $execname1 --profile=$tmpdir/$base.perf.data --gcov_version=3 --gcov=$tmpdir/$bprefix$base.$ext"
set compiler [lindex $GCC_UNDER_TEST 0]
set autofdo_version [string trim [lindex [remote_exec target "$compiler --print-autofdo-gcov-version"] 1] ]
set cmd "create_gcov --binary $execname1 --profile=$tmpdir/$base.perf.data --gcov_version=$autofdo_version --gcov=$tmpdir/$bprefix$base.$ext"
verbose "Running $cmd"
set id [remote_spawn "" $cmd]
if { $id < 0 } {