summaryrefslogtreecommitdiff
path: root/0310-CFGO-Add-cfgo-pgo-optimization.patch
blob: 4a930aba6773ef382ee5c83821b5f3a1894aa8df (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
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