> > I think you are also not removing the common_target and
> > common_target_probability from cgraph_edge.
> > There is now code in ipa-utils merging the histograms. You will need to
> > update that to your representation. It should not be hard - it either
> > copies all the values from target function or merges them with given
> > probability scales.
> 
> This seems a bit tricky for me.  ipa-icf runs after ipa-profile, the reason 
> why 
> remove <common_target_id, common_target_probability> is they are never used in
> later passes during previous discussion.

There is also merging done from lto-symtab.  If you have COMDAT inline
which is late inlined at -fprofile-generate time you will end up with
multiple profiles for it and they needs to be merged.  This is done
before IPA passes including ipa-profile.
> 
> I added a new variable target_prob to save it in direct edge when calling
> make_speculative, since the target_prob is assigned in ipa-profile, so no
> need to stream out and in through LTO like speculative_id.
> 
> Even though, scaling in ipa-icf with multiple direct edges is more complicate 
> then
> single direct edge, need double circulation to find each src to dst edge map 
> and do
> scaling one by one. 
> 
> BTW, the breaking patch r279373 "Fix merging of common traget info." only 
> mentioned
> firefox but doesn't include a testcase, I tried to construct some test
> cases, but fail to cover all the circumstance (I just implemented the N:N map 
> yet, 
> please refer to the code in below patch.), do you have cases other than 
> firefox to
> cover it?  Or how to test it as r279373 required?  As this piece of code is 
> not quite
> related to this patch, can we just leave it for future refine?  Thanks :)

You need testcase with a comdat that is used & inlined in two units,
contains indirect call and build with -fno-early-inlining.

However we can handle this incrementally.

>       2019-12-26  Xiong Hu Luo  <luo...@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
> 
>       2019-12-26  Xiong Hu Luo  <luo...@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.

OK. You will need to do the obvious updates for Martin's patch
which turned some member functions into static functions.

Honza

Reply via email to