From f77e2fbf8297c293d23bf60e0b04d4d56b6ddc24 Mon Sep 17 00:00:00 2001 From: Jan Hubicka Date: Wed, 1 Oct 2025 17:06:41 +0200 Subject: [PATCH] make autprofiledbootstrap with LTO meaningful currently autoprofiled bootstrap produces auto-profiles for cc1 and cc1plus binaries. Those are used to build respective frontend files. For backend cc1plus.fda is used. This does not work well with LTO bootstrap where cc1plus backend is untrained since it is used only for parsing and ealry opts. As a result all binaries gets most of the backend optimized for size rather then speed. This patch adds lto1.fda and then combines all of cc1, cc1plus and lto1 into all.fda that is used compiling common modules. This is more or less equivalent to what -fprofile-use effectively uses modulo that with -fprofile-use we know number of runs of evety object file and scale accordingly at LTO time. gcc/ChangeLog: * Makefile.in (ALL_FDAS): New variable. (ALL_HOST_BACKEND_OBJ): Use all.fda instead of cc1plus.fda (all.fda): New target gcc/c/ChangeLog: * Make-lang.in: Add c_FDAS (create_fdas_for_cc1): Be sure that build fails if create_gcov fails. gcc/cp/ChangeLog: * Make-lang.in: Add c++_FDAS (create_fdas_for_cc1plus): Be sure that build fails if create_gcov fails. gcc/lto/ChangeLog: * Make-lang.in: Add lto_FDAS; enable FDA collection (create_fdas_for_lto1): Be sure that build fails if create_gcov fails. --- gcc/Makefile.in | 10 ++++++++-- gcc/c/Make-lang.in | 5 +++-- gcc/cp/Make-lang.in | 6 ++++-- gcc/lto/Make-lang.in | 19 ++++++++----------- 4 files changed, 23 insertions(+), 17 deletions(-) diff --git a/gcc/Makefile.in b/gcc/Makefile.in index 4503dab60372..6a9d6204c869 100644 --- a/gcc/Makefile.in +++ b/gcc/Makefile.in @@ -1908,6 +1908,9 @@ OBJS-libcommon-target = $(common_out_object_file) prefix.o \ # This lists all host objects for the front ends. ALL_HOST_FRONTEND_OBJS = $(foreach v,$(CONFIG_LANGUAGES),$($(v)_OBJS)) +# All auto-profile files +ALL_FDAS = $(foreach v,$(CONFIG_LANGUAGES),$($(v)_FDAS)) + ALL_HOST_BACKEND_OBJS = $(GCC_OBJS) $(OBJS) $(OBJS-libcommon) \ $(OBJS-libcommon-target) main.o c-family/cppspec.o \ $(COLLECT2_OBJS) $(EXTRA_GCC_OBJS) $(GCOV_OBJS) $(GCOV_DUMP_OBJS) \ @@ -1918,8 +1921,8 @@ ALL_HOST_BACKEND_OBJS = $(GCC_OBJS) $(OBJS) $(OBJS-libcommon) \ # is likely the most exercised during the build ifeq ($(if $(wildcard ../stage_current),$(shell cat \ ../stage_current)),stageautofeedback) -$(ALL_HOST_BACKEND_OBJS): ALL_COMPILERFLAGS += -fauto-profile=cc1plus.fda -$(ALL_HOST_BACKEND_OBJS): cc1plus.fda +$(ALL_HOST_BACKEND_OBJS): ALL_COMPILERFLAGS += -fauto-profile=all.fda +$(ALL_HOST_BACKEND_OBJS): all.fda endif # This lists all host object files, whether they are included in this @@ -4744,6 +4747,9 @@ paranoia.o: $(srcdir)/../contrib/paranoia.cc $(CONFIG_H) $(SYSTEM_H) $(TREE_H) 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 2 + # These exist for maintenance purposes. CTAGS=@CTAGS@ diff --git a/gcc/c/Make-lang.in b/gcc/c/Make-lang.in index 2517b64439fe..f09fc99467b9 100644 --- a/gcc/c/Make-lang.in +++ b/gcc/c/Make-lang.in @@ -58,6 +58,7 @@ C_AND_OBJC_OBJS = attribs.o c/c-errors.o c/c-decl.o c/c-typeck.o \ # Language-specific object files for C. C_OBJS = c/c-lang.o c-family/stub-objc.o $(C_AND_OBJC_OBJS) c_OBJS = $(C_OBJS) cc1-checksum.o c/gccspec.o +c_FDAS = cc1.fda # Use strict warnings for this front end. c-warn = $(STRICT_WARN) @@ -101,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 2; \ + $(CREATE_GCOV) -binary ../stage1-gcc/cc1$(exeext) -gcov $$profile_name -profile $$perf_path -gcov_version 2 || exit 1; \ fi; \ done; @@ -111,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 2; \ + $(CREATE_GCOV) -binary ../prev-gcc/cc1$(exeext) -gcov $$profile_name -profile $$perf_path -gcov_version 2 || exit 1; \ fi; \ done; diff --git a/gcc/cp/Make-lang.in b/gcc/cp/Make-lang.in index dae3c6846e04..70cfe2b16636 100644 --- a/gcc/cp/Make-lang.in +++ b/gcc/cp/Make-lang.in @@ -123,6 +123,8 @@ CXX_OBJS = cp/cp-lang.o c-family/stub-objc.o $(CXX_AND_OBJCXX_OBJS) c++_OBJS = $(CXX_OBJS) cc1plus-checksum.o cp/g++spec.o +c++_FDAS = cc1plus.fda + # Use strict warnings for this front end. cp-warn = $(STRICT_WARN) @@ -199,7 +201,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 2; \ + $(CREATE_GCOV) -binary ../stage1-gcc/cc1plus$(exeext) -gcov $$profile_name -profile $$perf_path -gcov_version 2 || exit 1; \ fi; \ done; @@ -209,7 +211,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 2; \ + $(CREATE_GCOV) -binary ../prev-gcc/cc1plus$(exeext) -gcov $$profile_name -profile $$perf_path -gcov_version 2 || exit 1; \ fi; \ done; diff --git a/gcc/lto/Make-lang.in b/gcc/lto/Make-lang.in index 553e6ddd0d2b..2af8bba44ca9 100644 --- a/gcc/lto/Make-lang.in +++ b/gcc/lto/Make-lang.in @@ -26,18 +26,15 @@ LTO_DUMP_INSTALL_NAME := $(shell echo lto-dump|sed '$(program_transform_name)') # The LTO-specific object files inclued in $(LTO_EXE). LTO_OBJS = lto/lto-lang.o lto/lto.o lto/lto-object.o attribs.o lto/lto-partition.o lto/lto-symtab.o lto/lto-common.o lto_OBJS = $(LTO_OBJS) +lto_FDAS = lto1.fda LTO_DUMP_OBJS = lto/lto-lang.o lto/lto-object.o attribs.o lto/lto-partition.o lto/lto-symtab.o lto/lto-dump.o lto/lto-common.o lto_dump_OBJS = $(LTO_DUMP_OBJS) -# this is only useful in a LTO bootstrap, but this does not work right -# now. Should reenable after this is fixed, but only when LTO bootstrap -# is enabled. - -#ifeq ($(if $(wildcard ../stage_current),$(shell cat \ -# ../stage_current)),stageautofeedback) -#$(LTO_OBJS): CFLAGS += -fauto-profile=lto1.fda -#$(LTO_OBJS): lto1.fda -#endif +ifeq ($(if $(wildcard ../stage_current),$(shell cat \ + ../stage_current)),stageautofeedback) +$(LTO_OBJS): CFLAGS += -fauto-profile=lto1.fda +$(LTO_OBJS): lto1.fda +endif # Rules @@ -118,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 2; \ + $(CREATE_GCOV) -binary ../stage1-gcc/lto1$(exeext) -gcov $$profile_name -profile $$perf_path -gcov_version 2 || exit 1; \ fi; \ done; @@ -128,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 2; \ + $(CREATE_GCOV) -binary ../prev-gcc/lto1$(exeext) -gcov $$profile_name -profile $$perf_path -gcov_version 2 || exit 1; \ fi; \ done; -- 2.47.3