From 73127104a245052cd5cf29cdaaca3e5c32c70348 Mon Sep 17 00:00:00 2001 From: CoprDistGit Date: Fri, 28 Feb 2025 10:03:49 +0000 Subject: automatic import of gcc --- 0310-CFGO-Add-cfgo-pgo-optimization.patch | 168 ++++++++++++++++++++++++++++++ 1 file changed, 168 insertions(+) create mode 100644 0310-CFGO-Add-cfgo-pgo-optimization.patch (limited to '0310-CFGO-Add-cfgo-pgo-optimization.patch') diff --git a/0310-CFGO-Add-cfgo-pgo-optimization.patch b/0310-CFGO-Add-cfgo-pgo-optimization.patch new file mode 100644 index 0000000..4a930ab --- /dev/null +++ b/0310-CFGO-Add-cfgo-pgo-optimization.patch @@ -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 + -- cgit v1.2.3