f1ba88b1b2
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.
141 lines
3.5 KiB
C++
141 lines
3.5 KiB
C++
/* IPA reference lists.
|
|
Copyright (C) 2010-2020 Free Software Foundation, Inc.
|
|
Contributed by Jan Hubicka
|
|
|
|
This file is part of GCC.
|
|
|
|
GCC is free software; you can redistribute it and/or modify it under
|
|
the terms of the GNU General Public License as published by the Free
|
|
Software Foundation; either version 3, or (at your option) any later
|
|
version.
|
|
|
|
GCC is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with GCC; see the file COPYING3. If not see
|
|
<http://www.gnu.org/licenses/>. */
|
|
|
|
#ifndef GCC_IPA_REF_H
|
|
#define GCC_IPA_REF_H
|
|
|
|
struct cgraph_node;
|
|
struct varpool_node;
|
|
struct symtab_node;
|
|
|
|
|
|
/* How the reference is done. */
|
|
enum GTY(()) ipa_ref_use
|
|
{
|
|
IPA_REF_LOAD,
|
|
IPA_REF_STORE,
|
|
IPA_REF_ADDR,
|
|
IPA_REF_ALIAS
|
|
};
|
|
|
|
/* Record of reference in callgraph or varpool. */
|
|
struct GTY(()) ipa_ref
|
|
{
|
|
public:
|
|
/* Remove reference. */
|
|
void remove_reference ();
|
|
|
|
/* Return true when execution of reference can lead to return from
|
|
function. */
|
|
bool cannot_lead_to_return ();
|
|
|
|
/* Return true if reference may be used in address compare. */
|
|
bool address_matters_p ();
|
|
|
|
/* Return reference list this reference is in. */
|
|
struct ipa_ref_list * referring_ref_list (void);
|
|
|
|
/* Return reference list this reference is in. */
|
|
struct ipa_ref_list * referred_ref_list (void);
|
|
|
|
symtab_node *referring;
|
|
symtab_node *referred;
|
|
gimple *stmt;
|
|
unsigned int lto_stmt_uid;
|
|
/* speculative id is used to link direct calls with their corresponding
|
|
IPA_REF_ADDR references when representing speculative calls. */
|
|
unsigned int speculative_id : 16;
|
|
unsigned int referred_index;
|
|
ENUM_BITFIELD (ipa_ref_use) use:3;
|
|
unsigned int speculative:1;
|
|
};
|
|
|
|
typedef struct ipa_ref ipa_ref_t;
|
|
typedef struct ipa_ref *ipa_ref_ptr;
|
|
|
|
|
|
/* List of references. This is stored in both callgraph and varpool nodes. */
|
|
struct GTY(()) ipa_ref_list
|
|
{
|
|
public:
|
|
/* Return first reference in list or NULL if empty. */
|
|
struct ipa_ref *first_reference (void)
|
|
{
|
|
if (!vec_safe_length (references))
|
|
return NULL;
|
|
return &(*references)[0];
|
|
}
|
|
|
|
/* Return first referring ref in list or NULL if empty. */
|
|
struct ipa_ref *first_referring (void)
|
|
{
|
|
if (!referring.length ())
|
|
return NULL;
|
|
return referring[0];
|
|
}
|
|
|
|
/* Return first referring alias. */
|
|
struct ipa_ref *first_alias (void)
|
|
{
|
|
struct ipa_ref *r = first_referring ();
|
|
|
|
return r && r->use == IPA_REF_ALIAS ? r : NULL;
|
|
}
|
|
|
|
/* Return last referring alias. */
|
|
struct ipa_ref *last_alias (void)
|
|
{
|
|
unsigned int i = 0;
|
|
|
|
for(i = 0; i < referring.length (); i++)
|
|
if (referring[i]->use != IPA_REF_ALIAS)
|
|
break;
|
|
|
|
return i == 0 ? NULL : referring[i - 1];
|
|
}
|
|
|
|
/* Return true if the symbol has an alias. */
|
|
bool inline has_aliases_p (void)
|
|
{
|
|
return first_alias ();
|
|
}
|
|
|
|
/* Clear reference list. */
|
|
void clear (void)
|
|
{
|
|
referring.create (0);
|
|
references = NULL;
|
|
}
|
|
|
|
/* Return number of references. */
|
|
unsigned int nreferences (void)
|
|
{
|
|
return vec_safe_length (references);
|
|
}
|
|
|
|
/* Store actual references in references vector. */
|
|
vec<ipa_ref_t, va_gc> *references;
|
|
/* Referring is vector of pointers to references. It must not live in GGC space
|
|
or GGC will try to mark middle of references vectors. */
|
|
vec<ipa_ref_ptr> GTY((skip)) referring;
|
|
};
|
|
|
|
#endif /* GCC_IPA_REF_H */
|