!513 [Sync] Sync from openEuler/gcc

From: @li-yancheng 
Reviewed-by: @huang-xiaoquan 
Signed-off-by: @huang-xiaoquan
This commit is contained in:
openeuler-ci-bot 2024-11-27 12:27:40 +00:00 committed by Gitee
commit 17af7ac13f
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
4 changed files with 1414 additions and 1 deletions

View File

@ -0,0 +1,168 @@
From 84635dc65ebe285457d0c16bbb5caf995f803436 Mon Sep 17 00:00:00 2001
From: liyancheng <412998149@qq.com>
Date: Wed, 27 Nov 2024 18:36:27 +0800
Subject: [PATCH] [CFGO] Add cfgo-pgo optimization
Add a cfgo-pgo to better optimize with AI4C
---
gcc/common.opt | 16 +++++++++++++
gcc/gcc.cc | 4 ++--
gcc/lto-cgraph.cc | 3 ++-
gcc/opts.cc | 57 +++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 77 insertions(+), 3 deletions(-)
diff --git a/gcc/common.opt b/gcc/common.opt
index c9baa12be..a45fbfe1b 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -2485,6 +2485,14 @@ fprofile-generate=
Common Joined RejectNegative
Enable common options for generating profile info for profile feedback directed optimizations, and set -fprofile-dir=.
+fcfgo-profile-generate
+Common Var(flag_cfgo_profile_generate)
+Enable common options for generating cfgo profile info for profile feedback directed optimizations.
+
+fcfgo-profile-generate=
+Common Joined RejectNegative
+Enable common options for generating cfgo profile info for profile feedback directed optimizations, and set -fprofile-dir=.
+
fcfgo-csprofile-generate
Common Var(flag_csprofile_generate)
Enable common options for generating context sensitive profile info for profile feedback directed optimizations.
@@ -2517,6 +2525,14 @@ fprofile-use=
Common Joined RejectNegative
Enable common options for performing profile feedback directed optimizations, and set -fprofile-dir=.
+fcfgo-profile-use
+Common Var(flag_cfgo_profile_use)
+Enable common options for performing profile feedback directed optimizations.
+
+fcfgo-profile-use=
+Common Joined RejectNegative
+Enable common options for performing profile feedback directed optimizations, and set -fprofile-dir=.
+
fcfgo-csprofile-use
Common Var(flag_csprofile_use)
Enable common options for performing context sensitive profile feedback directed optimizations.
diff --git a/gcc/gcc.cc b/gcc/gcc.cc
index b37b50be2..e5c43dd90 100644
--- a/gcc/gcc.cc
+++ b/gcc/gcc.cc
@@ -1147,7 +1147,7 @@ proper position among the other output files. */
%:include(libgomp.spec)%(link_gomp)}\
%{fgnu-tm:%:include(libitm.spec)%(link_itm)}\
%(mflib) " STACK_SPLIT_SPEC "\
- %{fprofile-arcs|fprofile-generate*|fcfgo-csprofile-generate*|coverage:-lgcov} \
+ %{fprofile-arcs|fprofile-generate*|fcfgo-profile-generate*|fcfgo-csprofile-generate*|coverage:-lgcov} \
" SANITIZER_SPEC " \
%{!nostdlib:%{!r:%{!nodefaultlibs:%(link_ssp) %(link_gcc_c_sequence)}}}\
%{!nostdlib:%{!r:%{!nostartfiles:%E}}} %{T*} \n%(post_link) }}}}}}"
@@ -1266,7 +1266,7 @@ static const char *cc1_options =
%{!fsyntax-only:%{S:%W{o*}%{!o*:-o %w%b.s}}}\
%{fsyntax-only:-o %j} %{-param*}\
%{coverage:-fprofile-arcs -ftest-coverage}\
- %{fprofile-arcs|fprofile-generate*|fcfgo-csprofile-generate*|coverage:\
+ %{fprofile-arcs|fprofile-generate*|fcfgo-profile-generate*|fcfgo-csprofile-generate*|coverage:\
%{!fprofile-update=single:\
%{pthread:-fprofile-update=prefer-atomic}}}";
diff --git a/gcc/lto-cgraph.cc b/gcc/lto-cgraph.cc
index fd41941d1..9a30f1190 100644
--- a/gcc/lto-cgraph.cc
+++ b/gcc/lto-cgraph.cc
@@ -1681,7 +1681,8 @@ merge_profile_summaries (struct lto_file_decl_data **file_data_vec)
stages with unknown bug resulted in different scaling results, which led
different optimization decisions and finally led to coverage mismatch.
Therefore, skip the following processing steps when doing cspgo. */
- if (flag_csprofile_generate || flag_csprofile_use)
+ if (flag_csprofile_generate || flag_csprofile_use
+ || flag_cfgo_profile_generate || flag_cfgo_profile_use)
return;
/* Now compute count_materialization_scale of each node.
diff --git a/gcc/opts.cc b/gcc/opts.cc
index 89d03e834..84dd8925a 100644
--- a/gcc/opts.cc
+++ b/gcc/opts.cc
@@ -2087,6 +2087,38 @@ enable_fdo_optimizations (struct gcc_options *opts,
SET_OPTION_IF_UNSET (opts, opts_set, flag_tree_loop_distribution, value);
}
+/* Enable cfgo-related flags. */
+
+static void
+enable_cfgo_optimizations (struct gcc_options *opts,
+ struct gcc_options *opts_set,
+ int value)
+{
+ SET_OPTION_IF_UNSET (opts, opts_set, flag_modulo_sched, value);
+ SET_OPTION_IF_UNSET (opts, opts_set, flag_selective_scheduling, value);
+ SET_OPTION_IF_UNSET (opts, opts_set, flag_rename_registers, value);
+
+ SET_OPTION_IF_UNSET (opts, opts_set, param_max_inline_insns_auto, 185);
+ SET_OPTION_IF_UNSET (opts, opts_set, param_inline_unit_growth, 66);
+ SET_OPTION_IF_UNSET (opts, opts_set, param_max_inline_recursive_depth_auto,
+ 31);
+ SET_OPTION_IF_UNSET (opts, opts_set, param_large_function_insns, 7286);
+ SET_OPTION_IF_UNSET (opts, opts_set, param_large_function_growth, 89);
+ SET_OPTION_IF_UNSET (opts, opts_set, param_large_unit_insns, 11783);
+ SET_OPTION_IF_UNSET (opts, opts_set, param_ipa_cp_eval_threshold, 864);
+ SET_OPTION_IF_UNSET (opts, opts_set, param_ipa_cp_loop_hint_bonus, 440);
+ SET_OPTION_IF_UNSET (opts, opts_set, param_ipa_cp_max_recursive_depth, 29);
+ SET_OPTION_IF_UNSET (opts, opts_set, param_ipa_cp_min_recursive_probability,
+ 4);
+ SET_OPTION_IF_UNSET (opts, opts_set, param_ipa_cp_recursive_freq_factor, 18);
+ SET_OPTION_IF_UNSET (opts, opts_set, param_ipa_cp_recursion_penalty, 64);
+ SET_OPTION_IF_UNSET (opts, opts_set, param_ipa_cp_single_call_penalty, 43);
+ SET_OPTION_IF_UNSET (opts, opts_set, param_ipa_cp_unit_growth, 96);
+ SET_OPTION_IF_UNSET (opts, opts_set, param_ipa_cp_large_unit_insns, 47631);
+ SET_OPTION_IF_UNSET (opts, opts_set, param_ipa_cp_value_list_size, 12);
+ SET_OPTION_IF_UNSET (opts, opts_set, param_ipa_cp_profile_count_base, 54);
+}
+
/* -f{,no-}sanitize{,-recover}= suboptions. */
const struct sanitizer_opts_s sanitizer_opts[] =
{
@@ -3033,6 +3065,18 @@ common_handle_option (struct gcc_options *opts,
/* Deferred. */
break;
+ case OPT_fcfgo_profile_use_:
+ /* No break here - do -fcfgo-profile-use processing. */
+ /* FALLTHRU */
+ case OPT_fcfgo_profile_use:
+ value = true;
+ if (value)
+ {
+ enable_cfgo_optimizations (opts, opts_set, value);
+ SET_OPTION_IF_UNSET (opts, opts_set, flag_cfgo_profile_use, value);
+ }
+ /* No break here - do -fprofile-use processing. */
+ /* FALLTHRU */
case OPT_fprofile_use_:
opts->x_profile_data_prefix = xstrdup (arg);
opts->x_flag_profile_use = true;
@@ -3090,6 +3134,19 @@ common_handle_option (struct gcc_options *opts,
SET_OPTION_IF_UNSET (opts, opts_set, flag_ipa_struct_reorg, value);
break;
+ case OPT_fcfgo_profile_generate_:
+ /* No break here - do -fcfgo-profile-generate processing. */
+ /* FALLTHRU */
+ case OPT_fcfgo_profile_generate:
+ value = true;
+ if (value)
+ {
+ enable_cfgo_optimizations (opts, opts_set, value);
+ SET_OPTION_IF_UNSET (opts, opts_set, flag_cfgo_profile_generate,
+ value);
+ }
+ /* No break here - do -fcfgo-profile-generate processing. */
+ /* FALLTHRU */
case OPT_fprofile_generate_:
opts->x_profile_data_prefix = xstrdup (arg);
value = true;
--
2.25.1

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,23 @@
diff --git a/gcc/config/loongarch/loongarch.cc b/gcc/config/loongarch/loongarch.cc
index 6be0d80b3..12af95f70 100644
--- a/gcc/config/loongarch/loongarch.cc
+++ b/gcc/config/loongarch/loongarch.cc
@@ -7917,15 +7917,13 @@ loongarch_handle_model_attribute (tree *node, tree name, tree arg, int,
return NULL_TREE;
}
-static const struct attribute_spec loongarch_attribute_table[] =
+TARGET_GNU_ATTRIBUTES (loongarch_attribute_table,
{
/* { name, min_len, max_len, decl_req, type_req, fn_type_req,
affects_type_identity, handler, exclude } */
{ "model", 1, 1, true, false, false, false,
- loongarch_handle_model_attribute, NULL },
- /* The last attribute spec is set to be NULL. */
- {}
-};
+ loongarch_handle_model_attribute, NULL }
+});
bool
loongarch_use_anchors_for_symbol_p (const_rtx symbol)

View File

@ -2,7 +2,7 @@
%global gcc_major 12 %global gcc_major 12
# Note, gcc_release must be integer, if you want to add suffixes to # Note, gcc_release must be integer, if you want to add suffixes to
# %%{release}, append them after %%{gcc_release} on Release: line. # %%{release}, append them after %%{gcc_release} on Release: line.
%global gcc_release 46 %global gcc_release 49
%global _unpackaged_files_terminate_build 0 %global _unpackaged_files_terminate_build 0
%global _performance_build 1 %global _performance_build 1
@ -415,6 +415,8 @@ Patch306: 0306-RISC-V-Install-libstdc-libcc1-etc-to-lib64-instead-o.patch
Patch307: 0307-Set-fallback-value-for-print-multi-os-directory.patch Patch307: 0307-Set-fallback-value-for-print-multi-os-directory.patch
Patch308: 0308-Fix-enum-INPUT-MIDDLE-FINAL-aes_stage.patch Patch308: 0308-Fix-enum-INPUT-MIDDLE-FINAL-aes_stage.patch
Patch309: 0309-CSPGO-Add-context-sensitive-PGO.patch Patch309: 0309-CSPGO-Add-context-sensitive-PGO.patch
Patch310: 0310-CFGO-Add-cfgo-pgo-optimization.patch
Patch311: 0311-PATCH-Add-if-split-optimization-pass.patch
# Part 3000 ~ 4999 # Part 3000 ~ 4999
%ifarch loongarch64 %ifarch loongarch64
@ -740,6 +742,7 @@ Patch3319: 0189-LoongArch-fix-building-errors.patch
Patch3320: 0190-tree-optimization-110702-avoid-zero-based-memory-ref.patch Patch3320: 0190-tree-optimization-110702-avoid-zero-based-memory-ref.patch
Patch3321: 0191-LoongArch-Change-OSDIR-for-distribution.patch Patch3321: 0191-LoongArch-Change-OSDIR-for-distribution.patch
Patch3322: Fix-indentation-and-numbering-errors.diff Patch3322: Fix-indentation-and-numbering-errors.diff
Patch3323: LoongArch-Allow-attributes-in-non-gnu-namespaces.diff
%endif %endif
# On ARM EABI systems, we do want -gnueabi to be part of the # On ARM EABI systems, we do want -gnueabi to be part of the
@ -1488,6 +1491,8 @@ not stable, so plugins must be rebuilt any time GCC is updated.
%patch -P307 -p1 %patch -P307 -p1
%patch -P308 -p1 %patch -P308 -p1
%patch -P309 -p1 %patch -P309 -p1
%patch -P310 -p1
%patch -P311 -p1
%ifarch loongarch64 %ifarch loongarch64
%patch -P3001 -p1 %patch -P3001 -p1
@ -1812,6 +1817,7 @@ not stable, so plugins must be rebuilt any time GCC is updated.
%patch -P3320 -p1 %patch -P3320 -p1
%patch -P3321 -p1 %patch -P3321 -p1
%patch -P3322 -p1 %patch -P3322 -p1
%patch -P3323 -p1
%endif %endif
echo '%{_vendor} %{version}-%{release}' > gcc/DEV-PHASE echo '%{_vendor} %{version}-%{release}' > gcc/DEV-PHASE
@ -4080,6 +4086,19 @@ end
%doc rpm.doc/changelogs/libcc1/ChangeLog* %doc rpm.doc/changelogs/libcc1/ChangeLog*
%changelog %changelog
* Wed Nov 27 2024 liyancheng <412998149@qq.com> - 12.3.1-49
- Type: Sync
- DESC: Add if split optimization
* Wed Nov 27 2024 Peng Fan <fanpeng@loongson.cn> - 12.3.1-48
- Type: BUGFIX
- DESC:
- LoongArch: Allow attributes in non-gnu namespaces.
* Wed Nov 27 2024 liyancheng <412998149@qq.com> - 12.3.1-47
- Type: Sync
- DESC: Add cfgo-pgo optimization
* Wed Nov 27 2024 liyancheng <412998149@qq.com> - 12.3.1-46 * Wed Nov 27 2024 liyancheng <412998149@qq.com> - 12.3.1-46
- Type: Sync - Type: Sync
- DESC: Add context sensitive PGO - DESC: Add context sensitive PGO