aboutsummaryrefslogtreecommitdiff
path: root/gcc/value-prof.c
diff options
context:
space:
mode:
authorXiong Hu Luo <luoxhu@linux.ibm.com>2019-04-24 00:10:44 -0500
committerXiong Hu Luo <luoxhu@linux.vnet.ibm.com>2020-01-13 19:10:46 -0600
commitf1ba88b1b20cb579b3b7ce6ce65470205742be7e (patch)
tree98070d8a50651dab76f87ca3470e7b1fad571a44 /gcc/value-prof.c
parent64378144aabf65bf3df2313191250accc042170e (diff)
downloadgcc-f1ba88b1b20cb579b3b7ce6ce65470205742be7e.zip
gcc-f1ba88b1b20cb579b3b7ce6ce65470205742be7e.tar.gz
gcc-f1ba88b1b20cb579b3b7ce6ce65470205742be7e.tar.bz2
Missed function specialization + partial devirtualization
v8: 1. Rebase to master with Martin's static function (r280043) comments merge. Boostrap/testsuite/SPEC2017 tested pass on Power8-LE. 2. TODO: 2.1. C++ devirt for multiple speculative call targets. 2.2. ipa-icf ipa_merge_profiles refine with COMDAT inline testcase. This patch aims to fix PR69678 caused by PGO indirect call profiling performance issues. The bug that profiling data is never working was fixed by Martin's pull back of topN patches, performance got GEOMEAN ~1% improvement(+24% for 511.povray_r specifically). Still, currently the default profile only generates SINGLE indirect target that called more than 75%. This patch leverages MULTIPLE indirect targets use in LTO-WPA and LTO-LTRANS stage, as a result, function specialization, profiling, partial devirtualization, inlining and cloning could be done successfully based on it. Performance can get improved from 0.70 sec to 0.38 sec on simple tests. Details are: 1. PGO with topn is enabled by default now, but only one indirect target edge will be generated in ipa-profile pass, so add variables to enable multiple speculative edges through passes, speculative_id will record the direct edge index bind to the indirect edge, indirect_call_targets length records how many direct edges owned by the indirect edge, postpone gimple_ic to ipa-profile like default as inline pass will decide whether it is benefit to transform indirect call. 2. Use speculative_id to track and search the reference node matched with the direct edge's callee for multiple targets. Actually, it is the caller's responsibility to handle the direct edges mapped to same indirect edge. speculative_call_info will return one of the direct edge specified, this will leverage current IPA edge process framework mostly. 3. Enable LTO WPA/LTRANS stage multiple indirect call targets analysis for profile full support in ipa passes and cgraph_edge functions. speculative_id can be set by make_speculative id when multiple targets are binded to one indirect edge, and cloned if new edge is cloned. speculative_id is streamed out and stream int by lto like lto_stmt_uid. 4. Create and duplicate all speculative direct edge's call summary in ipa-fnsummary.c with auto_vec. 5. Add 1 in module testcase and 2 cross module testcases. 6. Bootstrap and regression test passed on Power8-LE. No function and performance regression for SPEC2017. gcc/ChangeLog 2020-01-14 Xiong Hu Luo <luoxhu@linux.ibm.com> PR ipa/69678 * cgraph.c (symbol_table::create_edge): Init speculative_id and target_prob. (cgraph_edge::make_speculative): Add param for setting speculative_id and target_prob. (cgraph_edge::speculative_call_info): Update comments and find reference by speculative_id for multiple indirect targets. (cgraph_edge::resolve_speculation): Decrease the speculations for indirect edge, drop it's speculative if not direct target left. Update comments. (cgraph_edge::redirect_call_stmt_to_callee): Likewise. (cgraph_node::dump): Print num_speculative_call_targets. (cgraph_node::verify_node): Don't report error if speculative edge not include statement. (cgraph_edge::num_speculative_call_targets_p): New function. * cgraph.h (int common_target_id): Remove. (int common_target_probability): Remove. (num_speculative_call_targets): New variable. (make_speculative): Add param for setting speculative_id. (cgraph_edge::num_speculative_call_targets_p): New declare. (target_prob): New variable. (speculative_id): New variable. * ipa-fnsummary.c (analyze_function_body): Create and duplicate call summaries for multiple speculative call targets. * cgraphclones.c (cgraph_node::create_clone): Clone speculative_id. * ipa-profile.c (struct speculative_call_target): New struct. (class speculative_call_summary): New class. (class speculative_call_summaries): New class. (call_sums): New variable. (ipa_profile_generate_summary): Generate indirect multiple targets summaries. (ipa_profile_write_edge_summary): New function. (ipa_profile_write_summary): Stream out indirect multiple targets summaries. (ipa_profile_dump_all_summaries): New function. (ipa_profile_read_edge_summary): New function. (ipa_profile_read_summary_section): New function. (ipa_profile_read_summary): Stream in indirect multiple targets summaries. (ipa_profile): Generate num_speculative_call_targets from profile summaries. * ipa-ref.h (speculative_id): New variable. * ipa-utils.c (ipa_merge_profiles): Update with target_prob. * lto-cgraph.c (lto_output_edge): Remove indirect common_target_id and common_target_probability. Stream out speculative_id and num_speculative_call_targets. (input_edge): Likewise. * predict.c (dump_prediction): Remove edges count assert to be precise. * symtab.c (symtab_node::create_reference): Init speculative_id. (symtab_node::clone_references): Clone speculative_id. (symtab_node::clone_referring): Clone speculative_id. (symtab_node::clone_reference): Clone speculative_id. (symtab_node::clear_stmts_in_references): Clear speculative_id. * tree-inline.c (copy_bb): Duplicate all the speculative edges if indirect call contains multiple speculative targets. * value-prof.h (check_ic_target): Remove. * value-prof.c (gimple_value_profile_transformations): Use void function gimple_ic_transform. * value-prof.c (gimple_ic_transform): Handle topn case. Fix comment typos. Change it to a void function. gcc/testsuite/ChangeLog 2020-01-14 Xiong Hu Luo <luoxhu@linux.ibm.com> PR ipa/69678 * gcc.dg/tree-prof/indir-call-prof-topn.c: New testcase. * gcc.dg/tree-prof/crossmodule-indir-call-topn-1.c: New testcase. * gcc.dg/tree-prof/crossmodule-indir-call-topn-1a.c: New testcase. * gcc.dg/tree-prof/crossmodule-indir-call-topn-2.c: New testcase. * lib/scandump.exp: Dump executable file name. * lib/scanwpaipa.exp: New scan-pgo-wap-ipa-dump.
Diffstat (limited to 'gcc/value-prof.c')
-rw-r--r--gcc/value-prof.c87
1 files changed, 47 insertions, 40 deletions
diff --git a/gcc/value-prof.c b/gcc/value-prof.c
index 8199496..9a2c462 100644
--- a/gcc/value-prof.c
+++ b/gcc/value-prof.c
@@ -106,7 +106,7 @@ static bool gimple_divmod_fixed_value_transform (gimple_stmt_iterator *);
static bool gimple_mod_pow2_value_transform (gimple_stmt_iterator *);
static bool gimple_mod_subtract_transform (gimple_stmt_iterator *);
static bool gimple_stringops_transform (gimple_stmt_iterator *);
-static bool gimple_ic_transform (gimple_stmt_iterator *);
+static void gimple_ic_transform (gimple_stmt_iterator *);
/* Allocate histogram value. */
@@ -616,8 +616,7 @@ gimple_value_profile_transformations (void)
if (gimple_mod_subtract_transform (&gsi)
|| gimple_divmod_fixed_value_transform (&gsi)
|| gimple_mod_pow2_value_transform (&gsi)
- || gimple_stringops_transform (&gsi)
- || gimple_ic_transform (&gsi))
+ || gimple_stringops_transform (&gsi))
{
stmt = gsi_stmt (gsi);
changed = true;
@@ -628,6 +627,9 @@ gimple_value_profile_transformations (void)
gsi = gsi_for_stmt (stmt);
}
}
+
+ /* The function never thansforms a GIMPLE statement. */
+ gimple_ic_transform (&gsi);
}
}
@@ -1386,13 +1388,12 @@ gimple_ic (gcall *icall_stmt, struct cgraph_node *direct_call,
return dcall_stmt;
}
-/*
- For every checked indirect/virtual call determine if most common pid of
- function/class method has probability more than 50%. If yes modify code of
- this call to:
- */
+/* There maybe multiple indirect targets in histogram. Check every
+ indirect/virtual call if callee function exists, if not exist, leave it to
+ LTO stage for later process. Modify code of this indirect call to an if-else
+ structure in ipa-profile finally. */
-static bool
+static void
gimple_ic_transform (gimple_stmt_iterator *gsi)
{
gcall *stmt;
@@ -1402,52 +1403,58 @@ gimple_ic_transform (gimple_stmt_iterator *gsi)
stmt = dyn_cast <gcall *> (gsi_stmt (*gsi));
if (!stmt)
- return false;
+ return;
if (gimple_call_fndecl (stmt) != NULL_TREE)
- return false;
+ return;
if (gimple_call_internal_p (stmt))
- return false;
+ return;
histogram = gimple_histogram_value_of_type (cfun, stmt, HIST_TYPE_INDIR_CALL);
if (!histogram)
- return false;
+ return;
- if (!get_nth_most_common_value (NULL, "indirect call", histogram, &val,
- &count, &all))
- return false;
+ count = 0;
+ all = histogram->hvalue.counters[0];
- if (4 * count <= 3 * all)
- return false;
+ for (unsigned j = 0; j < GCOV_TOPN_VALUES; j++)
+ {
+ if (!get_nth_most_common_value (NULL, "indirect call", histogram, &val,
+ &count, &all, j))
+ return;
- direct_call = find_func_by_profile_id ((int)val);
+ /* Minimum probability. should be higher than 25%. */
+ if (4 * count <= all)
+ return;
- if (direct_call == NULL)
- {
- if (val)
+ direct_call = find_func_by_profile_id ((int) val);
+
+ if (direct_call == NULL)
{
- if (dump_enabled_p ())
- dump_printf_loc (MSG_MISSED_OPTIMIZATION, stmt,
- "Indirect call -> direct call from other "
- "module %T=> %i (will resolve only with LTO)\n",
- gimple_call_fn (stmt), (int)val);
+ if (val)
+ {
+ if (dump_enabled_p ())
+ dump_printf_loc (
+ MSG_MISSED_OPTIMIZATION, stmt,
+ "Indirect call -> direct call from other "
+ "module %T=> %i (will resolve only with LTO)\n",
+ gimple_call_fn (stmt), (int) val);
+ }
+ return;
}
- return false;
- }
- if (dump_enabled_p ())
- {
- dump_printf_loc (MSG_OPTIMIZED_LOCATIONS, stmt,
- "Indirect call -> direct call "
- "%T => %T transformation on insn postponed\n",
- gimple_call_fn (stmt), direct_call->decl);
- dump_printf_loc (MSG_NOTE, stmt,
- "hist->count %" PRId64
- " hist->all %" PRId64"\n", count, all);
+ if (dump_enabled_p ())
+ {
+ dump_printf_loc (MSG_OPTIMIZED_LOCATIONS, stmt,
+ "Indirect call -> direct call "
+ "%T => %T transformation on insn postponed\n",
+ gimple_call_fn (stmt), direct_call->decl);
+ dump_printf_loc (MSG_NOTE, stmt,
+ "hist->count %" PRId64 " hist->all %" PRId64 "\n",
+ count, all);
+ }
}
-
- return true;
}
/* Return true if the stringop CALL shall be profiled. SIZE_ARG be