summaryrefslogtreecommitdiff
path: root/0319-CSPGO-fix-bugs-when-using-cspgo.patch
diff options
context:
space:
mode:
Diffstat (limited to '0319-CSPGO-fix-bugs-when-using-cspgo.patch')
-rw-r--r--0319-CSPGO-fix-bugs-when-using-cspgo.patch140
1 files changed, 140 insertions, 0 deletions
diff --git a/0319-CSPGO-fix-bugs-when-using-cspgo.patch b/0319-CSPGO-fix-bugs-when-using-cspgo.patch
new file mode 100644
index 0000000..bd86bb8
--- /dev/null
+++ b/0319-CSPGO-fix-bugs-when-using-cspgo.patch
@@ -0,0 +1,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
+