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
|
From 610470b1892213afd4ddcf83862667c758724872 Mon Sep 17 00:00:00 2001
From: liyancheng <412998149@qq.com>
Date: Wed, 4 Dec 2024 16:25:01 +0800
Subject: [PATCH] [CSPGO] fix bugs when using cspgo
---
gcc/opts.cc | 36 ++++++++++++++++++++++++++----------
gcc/tree-profile.cc | 20 ++++++++++++++++++++
2 files changed, 46 insertions(+), 10 deletions(-)
diff --git a/gcc/opts.cc b/gcc/opts.cc
index 6ca9dde7e..2433ace06 100644
--- a/gcc/opts.cc
+++ b/gcc/opts.cc
@@ -34,6 +34,7 @@ along with GCC; see the file COPYING3. If not see
#include "diagnostic-color.h"
#include "version.h"
#include "selftest.h"
+#include "ai4c-infer.h"
/* In this file all option sets are explicit. */
#undef OPTION_SET_P
@@ -3086,17 +3087,28 @@ common_handle_option (struct gcc_options *opts,
break;
case OPT_fcfgo_profile_use_:
+ opts->x_profile_data_prefix = xstrdup (arg);
+ opts->x_flag_profile_use = true;
+ value = true;
/* No break here - do -fcfgo-profile-use processing. */
/* FALLTHRU */
case OPT_fcfgo_profile_use:
- value = true;
- if (value)
+ if (get_optimize_decision_from_ai4c ())
{
+ value = true;
enable_cfgo_optimizations (opts, opts_set, value);
SET_OPTION_IF_UNSET (opts, opts_set, flag_cfgo_profile_use, value);
+ /* Enable orig fdo optimizations. */
+ enable_fdo_optimizations (opts, opts_set, value);
+ SET_OPTION_IF_UNSET (opts, opts_set, flag_profile_reorder_functions,
+ value);
+ /* Indirect call profiling should do all useful transformations
+ speculative devirtualization does. */
+ if (opts->x_flag_value_profile_transformations)
+ SET_OPTION_IF_UNSET (opts, opts_set, flag_devirtualize_speculatively,
+ false);
}
- /* No break here - do -fprofile-use processing. */
- /* FALLTHRU */
+ break;
case OPT_fprofile_use_:
opts->x_profile_data_prefix = xstrdup (arg);
opts->x_flag_profile_use = true;
@@ -3116,10 +3128,10 @@ common_handle_option (struct gcc_options *opts,
case OPT_fcfgo_csprofile_use_:
opts->x_csprofile_data_prefix = xstrdup (arg);
- value = true;
/* No break here - do -fcfgo-csprofile-use processing. */
/* FALLTHRU */
case OPT_fcfgo_csprofile_use:
+ value = get_optimize_decision_from_ai4c ();
SET_OPTION_IF_UNSET (opts, opts_set, flag_csprofile_use, value);
break;
@@ -3155,18 +3167,22 @@ common_handle_option (struct gcc_options *opts,
break;
case OPT_fcfgo_profile_generate_:
+ opts->x_profile_data_prefix = xstrdup (arg);
+ value = true;
/* No break here - do -fcfgo-profile-generate processing. */
/* FALLTHRU */
case OPT_fcfgo_profile_generate:
- value = true;
- if (value)
+ if (get_optimize_decision_from_ai4c ())
{
enable_cfgo_optimizations (opts, opts_set, value);
SET_OPTION_IF_UNSET (opts, opts_set, flag_cfgo_profile_generate,
value);
}
- /* No break here - do -fprofile-generate processing. */
- /* FALLTHRU */
+ SET_OPTION_IF_UNSET (opts, opts_set, profile_arc_flag, value);
+ SET_OPTION_IF_UNSET (opts, opts_set, flag_profile_values, value);
+ SET_OPTION_IF_UNSET (opts, opts_set, flag_inline_functions, value);
+ SET_OPTION_IF_UNSET (opts, opts_set, flag_ipa_bit_cp, value);
+ break;
case OPT_fprofile_generate_:
opts->x_profile_data_prefix = xstrdup (arg);
value = true;
@@ -3181,10 +3197,10 @@ common_handle_option (struct gcc_options *opts,
case OPT_fcfgo_csprofile_generate_:
opts->x_csprofile_data_prefix = xstrdup (arg);
- value = true;
/* No break here - do -fcfgo-csprofile-generate processing. */
/* FALLTHRU */
case OPT_fcfgo_csprofile_generate:
+ value = get_optimize_decision_from_ai4c ();
SET_OPTION_IF_UNSET (opts, opts_set, flag_csprofile_generate, value);
break;
diff --git a/gcc/tree-profile.cc b/gcc/tree-profile.cc
index aa3a2b3a9..ace1fe31c 100644
--- a/gcc/tree-profile.cc
+++ b/gcc/tree-profile.cc
@@ -1114,6 +1114,26 @@ public:
to do anything. */
virtual unsigned int execute (function *)
{
+ if (!profile_data_prefix)
+ error ("profile_data_prefix must set when using cspgo.");
+
+ if (!csprofile_data_prefix)
+ error ("csprofile_data_prefix must set when using cspgo.");
+
+ if (!flag_cfgo_profile_use)
+ error ("cspgo must used with cfgo-pgo.");
+
+ /* Just compare canonical pathnames. */
+ char* cfgo_pgo_path = lrealpath (profile_data_prefix);
+ char* cfgo_cspgo_path = lrealpath (csprofile_data_prefix);
+ bool files_differ = filename_cmp (cfgo_pgo_path, cfgo_cspgo_path);
+ if (!files_differ)
+ {
+ error ("pgo and cspgo path must different between %s and %s",
+ cfgo_pgo_path, cfgo_cspgo_path);
+ }
+ free (cfgo_pgo_path);
+ free (cfgo_cspgo_path);
return 0;
}
--
2.25.1
|