From 84895d28940b46040028e8736adbd83dc2d77b23 Mon Sep 17 00:00:00 2001 From: hubicka Date: Mon, 6 Nov 2017 13:45:41 +0000 Subject: PR bootstrap/82832 * ipa-inline-transform.c (update_noncloned_frequencies): Always scale. (inline_transform): Likewise. * predict.c (counts_to_freqs): Remove useless conditional. * profile-count.h (profile_count::apply_scale): Move sanity check. * tree-inline.c (copy_bb): Always scale. (copy_cfg_body): Likewise. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@254452 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/tree-inline.c | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) (limited to 'gcc/tree-inline.c') diff --git a/gcc/tree-inline.c b/gcc/tree-inline.c index 040799c778c..7ef107247b5 100644 --- a/gcc/tree-inline.c +++ b/gcc/tree-inline.c @@ -1770,8 +1770,18 @@ copy_bb (copy_body_data *id, basic_block bb, basic_block copy_basic_block; tree decl; basic_block prev; - bool scale = !num.initialized_p () - || (den.nonzero_p () || num == profile_count::zero ()); + + /* We always must scale to be sure counters end up compatible. + If den is zero, just force it nonzero and hope for reasonable + approximation. + When num is forced nonzero, also update den, so we do not scale profile + to 0. */ + if (!(num == den) + && !(den.force_nonzero () == den)) + { + den = den.force_nonzero (); + num = num.force_nonzero (); + } /* Search for previous copied basic block. */ prev = bb->prev_bb; @@ -1781,10 +1791,7 @@ copy_bb (copy_body_data *id, basic_block bb, /* create_basic_block() will append every new block to basic_block_info automatically. */ copy_basic_block = create_basic_block (NULL, (basic_block) prev->aux); - if (scale) - copy_basic_block->count = bb->count.apply_scale (num, den); - else if (num.initialized_p ()) - copy_basic_block->count = bb->count; + copy_basic_block->count = bb->count.apply_scale (num, den); copy_gsi = gsi_start_bb (copy_basic_block); @@ -2691,6 +2698,18 @@ copy_cfg_body (copy_body_data * id, profile_count, profile_count den = ENTRY_BLOCK_PTR_FOR_FN (src_cfun)->count; profile_count num = entry_block_map->count; + /* We always must scale to be sure counters end up compatible. + If den is zero, just force it nonzero and hope for reasonable + approximation. + When num is forced nonzero, also update den, so we do not scale profile + to 0. */ + if (!(num == den) + && !(den.force_nonzero () == den)) + { + den = den.force_nonzero (); + num = num.force_nonzero (); + } + cfun_to_copy = id->src_cfun = DECL_STRUCT_FUNCTION (callee_fndecl); /* Register specific tree functions. */ -- cgit v1.2.1 From 371858d4588d4757de1f809368d8678232b65cc8 Mon Sep 17 00:00:00 2001 From: hubicka Date: Thu, 9 Nov 2017 14:05:14 +0000 Subject: PR ipa/82879 * ipa-inline-transform.c (update_noncloned_frequencies): Use profile_count::adjust_for_ipa_scaling. * tree-inline.c (copy_bb, copy_cfg_body): Likewise. * profile-count.c (profile_count::adjust_for_ipa_scaling): New member function. * profile-count.h (profile_count::adjust_for_ipa_scaling): Declare. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@254582 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/tree-inline.c | 24 ++---------------------- 1 file changed, 2 insertions(+), 22 deletions(-) (limited to 'gcc/tree-inline.c') diff --git a/gcc/tree-inline.c b/gcc/tree-inline.c index 7ef107247b5..fc5d2c703ab 100644 --- a/gcc/tree-inline.c +++ b/gcc/tree-inline.c @@ -1771,17 +1771,7 @@ copy_bb (copy_body_data *id, basic_block bb, tree decl; basic_block prev; - /* We always must scale to be sure counters end up compatible. - If den is zero, just force it nonzero and hope for reasonable - approximation. - When num is forced nonzero, also update den, so we do not scale profile - to 0. */ - if (!(num == den) - && !(den.force_nonzero () == den)) - { - den = den.force_nonzero (); - num = num.force_nonzero (); - } + profile_count::adjust_for_ipa_scaling (&num, &den); /* Search for previous copied basic block. */ prev = bb->prev_bb; @@ -2698,17 +2688,7 @@ copy_cfg_body (copy_body_data * id, profile_count, profile_count den = ENTRY_BLOCK_PTR_FOR_FN (src_cfun)->count; profile_count num = entry_block_map->count; - /* We always must scale to be sure counters end up compatible. - If den is zero, just force it nonzero and hope for reasonable - approximation. - When num is forced nonzero, also update den, so we do not scale profile - to 0. */ - if (!(num == den) - && !(den.force_nonzero () == den)) - { - den = den.force_nonzero (); - num = num.force_nonzero (); - } + profile_count::adjust_for_ipa_scaling (&num, &den); cfun_to_copy = id->src_cfun = DECL_STRUCT_FUNCTION (callee_fndecl); -- cgit v1.2.1 From 151b9ff52a095baa99b7cd3f392f82b221d81f98 Mon Sep 17 00:00:00 2001 From: hubicka Date: Fri, 10 Nov 2017 20:14:52 +0000 Subject: * auto-profile.c (afdo_indirect_call): Drop frequency. * cgraph.c (symbol_table::create_edge): Drop frequency argument. (cgraph_node::create_edge): Drop frequency argument. (cgraph_node::create_indirect_edge): Drop frequency argument. (cgraph_edge::make_speculative): Drop frequency arguments. (cgraph_edge::resolve_speculation): Do not update frequencies (cgraph_edge::dump_edge_flags): Do not dump frequency. (cgraph_node::dump): Check consistency in IPA mode. (cgraph_edge::maybe_hot_p): Use IPA counter. (cgraph_edge::verify_count_and_frequency): Rename to ... (cgraph_edge::verify_count): ... this one; drop frequency checking. (cgraph_node::verify_node): Update. * cgraph.h (struct cgraph_edge): Drop frequency. (cgraph_edge::frequency): New function. * cgraphbuild.c (pass_build_cgraph_edges::execute): Donot pass frequencies. (cgraph_edge::rebuild_edges): Likewise. * cgraphclones.c (cgraph_edge::clone): Scale only counts. (duplicate_thunk_for_node): Do not pass frequency. (cgraph_node::create_clone): Scale only counts. (cgraph_node::create_virtual_clone): Do not pass frequency. (cgraph_node::create_edge_including_clones): Do not pass frequency. (cgraph_node::create_version_clone): Do not pass frequency. * cgraphunit.c (cgraph_node::analyze): Do not pass frequency. (cgraph_node::expand_thunk): Do not pass frequency. (cgraph_node::create_wrapper): Do not pass frequency. * gimple-iterator.c (update_call_edge_frequencies): Do not pass frequency. * gimple-streamer-in.c (input_bb): Scale only IPA counts. * ipa-chkp.c (chkp_produce_thunks): Do not pass frequency. * ipa-cp.c (ipcp_lattice::print): Use frequency function. (gather_caller_stats): Use frequency function. (ipcp_cloning_candidate_p): Use frequency function. (ipcp_propagate_stage): Use frequency function. (get_info_about_necessary_edges): Use frequency function. (update_profiling_info): Update only IPA profile. (update_specialized_profile): Use frequency functoin. (perhaps_add_new_callers): Update only IPA profile. * ipa-devirt.c (ipa_devirt): Use IPA profile. * ipa-fnsummary.c (redirect_to_unreachable): Do not set frequrency. (dump_ipa_call_summary): Use frequency function. (estimate_edge_size_and_time): Use frequency function. (ipa_merge_fn_summary_after_inlining): Use frequency function. * ipa-inline-analysis.c (do_estimate_edge_time): Use IPA profile. * ipa-inline-transform.c (update_noncloned_frequencies): Rename to .. (update_noncloned_counts): ... ths one; scale counts only. (clone_inlined_nodes): Do not scale frequency. (inline_call): Do not pass frequency. * ipa-inline.c (compute_uninlined_call_time): Use IPA profile. (compute_inlined_call_time): Use IPA profile. (want_inline_small_function_p): Use IPA profile. (want_inline_self_recursive_call_p): Use IPA profile. (edge_badness): Use IPA profile. (lookup_recursive_calls): Use IPA profile. (recursive_inlining): Do not pass frequency. (resolve_noninline_speculation): Do not update frequency. (inline_small_functions): Collect max of IPA profile. (dump_overall_stats): Dump IPA porfile. (dump_inline_stats): Dump IPA porfile. (ipa_inline): Collect IPA stats. * ipa-inline.h (clone_inlined_nodes): Update prototype. * ipa-profile.c (ipa_propagate_frequency_1): Use frequency function. (ipa_propagate_frequency): Use frequency function. (ipa_profile): Cleanup. * ipa-prop.c (ipa_make_edge_direct_to_target): Do not pass frequency * ipa-utils.c (ipa_merge_profiles): Merge all profiles. * lto-cgraph.c (lto_output_edge): Do not stream frequency. (input_node): Do not stream frequency. (input_edge): Do not stream frequency. (merge_profile_summaries): Scale only IPA profiles. * omp-simd-clone.c (simd_clone_adjust): Do not pass frequency. * predict.c (drop_profile): Do not recompute frequency. * trans-mem.c (ipa_tm_insert_irr_call): Do not pass frequency. (ipa_tm_insert_gettmclone_call): Do not pass frequency. * tree-cfg.c (execute_fixup_cfg): Drop profile to global0 if needed. * tree-chkp.c (chkp_copy_bounds_for_assign): Do not pass frequency. * tree-emutls.c (gen_emutls_addr): Do not pass frequency. * tree-inline.c (copy_bb): Do not scale frequency. (expand_call_inline): Do not scale frequency. (tree_function_versioning): Do not scale frequency. * ubsan.c (ubsan_create_edge): Do not pass frequency. lto/ChangeLog: 2017-11-10 Jan Hubicka * lto-partition.c (lto_balanced_map): Use frequency accessor. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@254636 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/tree-inline.c | 81 +++++++++++++++---------------------------------------- 1 file changed, 21 insertions(+), 60 deletions(-) (limited to 'gcc/tree-inline.c') diff --git a/gcc/tree-inline.c b/gcc/tree-inline.c index fc5d2c703ab..5c49214663f 100644 --- a/gcc/tree-inline.c +++ b/gcc/tree-inline.c @@ -2001,23 +2001,16 @@ copy_bb (copy_body_data *id, basic_block bb, edge = id->src_node->get_edge (orig_stmt); if (edge) { - int edge_freq = edge->frequency; - int new_freq; struct cgraph_edge *old_edge = edge; + profile_count old_cnt = edge->count; edge = edge->clone (id->dst_node, call_stmt, gimple_uid (stmt), - profile_count::one (), - profile_count::one (), - CGRAPH_FREQ_BASE, + num, den, true); - /* We could also just rescale the frequency, but - doing so would introduce roundoff errors and make - verifier unhappy. */ - new_freq = compute_call_stmt_bb_frequency (id->dst_node->decl, - copy_basic_block); - - /* Speculative calls consist of two edges - direct and indirect. - Duplicate the whole thing and distribute frequencies accordingly. */ + + /* Speculative calls consist of two edges - direct and + indirect. Duplicate the whole thing and distribute + frequencies accordingly. */ if (edge->speculative) { struct cgraph_edge *direct, *indirect; @@ -2025,42 +2018,22 @@ copy_bb (copy_body_data *id, basic_block bb, gcc_assert (!edge->indirect_unknown_callee); old_edge->speculative_call_info (direct, indirect, ref); + + profile_count indir_cnt = indirect->count; indirect = indirect->clone (id->dst_node, call_stmt, gimple_uid (stmt), - profile_count::one (), - profile_count::one (), - CGRAPH_FREQ_BASE, + num, den, true); - if (old_edge->frequency + indirect->frequency) - { - edge->frequency = MIN (RDIV ((gcov_type)new_freq * old_edge->frequency, - (old_edge->frequency + indirect->frequency)), - CGRAPH_FREQ_MAX); - indirect->frequency = MIN (RDIV ((gcov_type)new_freq * indirect->frequency, - (old_edge->frequency + indirect->frequency)), - CGRAPH_FREQ_MAX); - } + + profile_probability prob + = indir_cnt.probability_in (old_cnt + indir_cnt); + indirect->count + = copy_basic_block->count.apply_probability (prob); + edge->count = copy_basic_block->count - indirect->count; id->dst_node->clone_reference (ref, stmt); } else - { - edge->frequency = new_freq; - if (dump_file - && profile_status_for_fn (cfun) != PROFILE_ABSENT - && (edge_freq > edge->frequency + 10 - || edge_freq < edge->frequency - 10)) - { - fprintf (dump_file, "Edge frequency estimated by " - "cgraph %i diverge from inliner's estimate %i\n", - edge_freq, - edge->frequency); - fprintf (dump_file, - "Orig bb: %i, orig bb freq %i, new bb freq %i\n", - bb->index, - bb->count.to_frequency (cfun), - copy_basic_block->count.to_frequency (cfun)); - } - } + edge->count = copy_basic_block->count; } break; @@ -2103,15 +2076,10 @@ copy_bb (copy_body_data *id, basic_block bb, if (id->transform_call_graph_edges == CB_CGE_MOVE_CLONES) id->dst_node->create_edge_including_clones (dest, orig_stmt, call_stmt, bb->count, - compute_call_stmt_bb_frequency (id->dst_node->decl, - copy_basic_block), CIF_ORIGINALLY_INDIRECT_CALL); else id->dst_node->create_edge (dest, call_stmt, - bb->count, - compute_call_stmt_bb_frequency - (id->dst_node->decl, - copy_basic_block))->inline_failed + bb->count)->inline_failed = CIF_ORIGINALLY_INDIRECT_CALL; if (dump_file) { @@ -4475,7 +4443,6 @@ expand_call_inline (basic_block bb, gimple *stmt, copy_body_data *id) { cgraph_edge *edge; tree virtual_offset = NULL; - int freq = cg_edge->frequency; profile_count count = cg_edge->count; tree op; gimple_stmt_iterator iter = gsi_for_stmt (stmt); @@ -4485,9 +4452,7 @@ expand_call_inline (basic_block bb, gimple *stmt, copy_body_data *id) gimple_uid (stmt), profile_count::one (), profile_count::one (), - CGRAPH_FREQ_BASE, true); - edge->frequency = freq; edge->count = count; if (id->src_node->thunk.virtual_offset_p) virtual_offset = size_int (id->src_node->thunk.virtual_value); @@ -4709,7 +4674,7 @@ expand_call_inline (basic_block bb, gimple *stmt, copy_body_data *id) print_generic_expr (dump_file, id->src_fn); fprintf (dump_file, " to "); print_generic_expr (dump_file, id->dst_fn); - fprintf (dump_file, " with frequency %i\n", cg_edge->frequency); + fprintf (dump_file, " with frequency %i\n", cg_edge->frequency ()); } /* This is it. Duplicate the callee body. Assume callee is @@ -6089,20 +6054,16 @@ tree_function_versioning (tree old_decl, tree new_decl, struct cgraph_edge *e; rebuild_frequencies (); - new_version_node->count = ENTRY_BLOCK_PTR_FOR_FN (cfun)->count.ipa (); + new_version_node->count = ENTRY_BLOCK_PTR_FOR_FN (cfun)->count; for (e = new_version_node->callees; e; e = e->next_callee) { basic_block bb = gimple_bb (e->call_stmt); - e->frequency = compute_call_stmt_bb_frequency (current_function_decl, - bb); - e->count = bb->count.ipa (); + e->count = bb->count; } for (e = new_version_node->indirect_calls; e; e = e->next_callee) { basic_block bb = gimple_bb (e->call_stmt); - e->frequency = compute_call_stmt_bb_frequency (current_function_decl, - bb); - e->count = bb->count.ipa (); + e->count = bb->count; } } -- cgit v1.2.1 From 688b6bc6943dc52195ca8748fdb741a4ad719bc0 Mon Sep 17 00:00:00 2001 From: hubicka Date: Tue, 14 Nov 2017 09:18:35 +0000 Subject: * auto-profile.c (afdo_annotate_cfg): Use update_max_bb_count. * cgraphunit.c (cgraph_node::expand_thunk): Use update_max_bb_count. * ipa-utils.c (ipa_merge_profiles): Use update_max_bb_count. * lto-streamer-in.c (input_function): Use update_max_bb_count. * omp-expand.c (expand_omp_taskreg): Use update_max_bb_count. * predict.c (maybe_hot_frequency_p): Inline to ... (maybe_hot_count_p): ... here; rewrite to counts. (counts_to_freqs): Rename to ... (update_max_bb_count): ... this one. (expensive_function_p): Use counts. (estimate_bb_frequencies): Update. (rebuild_frequencies): Update. * predict.h (counts_to_freqs): Rename to ... (update_max_bb_count): ... this one. * profile.c (compute_branch_probabilities): Add debug info * tree-inline.c (expand_call_inline): Update debug info. (optimize_inline_calls): Use update_max_bb_count.. (tree_function_versioning): Use update_max_bb_count.. * value-prof.c (gimple_value_profile_transformations): Do not use update_max_bb_count. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@254725 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/tree-inline.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'gcc/tree-inline.c') diff --git a/gcc/tree-inline.c b/gcc/tree-inline.c index 5c49214663f..d4aa5bed739 100644 --- a/gcc/tree-inline.c +++ b/gcc/tree-inline.c @@ -59,6 +59,7 @@ along with GCC; see the file COPYING3. If not see #include "tree-chkp.h" #include "stringpool.h" #include "attribs.h" +#include "sreal.h" /* I'm not real happy about this, but we need to handle gimple and non-gimple trees. */ @@ -4670,11 +4671,12 @@ expand_call_inline (basic_block bb, gimple *stmt, copy_body_data *id) if (dump_file && (dump_flags & TDF_DETAILS)) { - fprintf (dump_file, "Inlining "); - print_generic_expr (dump_file, id->src_fn); - fprintf (dump_file, " to "); - print_generic_expr (dump_file, id->dst_fn); - fprintf (dump_file, " with frequency %i\n", cg_edge->frequency ()); + fprintf (dump_file, "Inlining %s to %s with frequency %4.2f\n", + xstrdup_for_dump (id->src_node->dump_name ()), + xstrdup_for_dump (id->dst_node->dump_name ()), + cg_edge->sreal_frequency ().to_double ()); + id->src_node->dump (dump_file); + id->dst_node->dump (dump_file); } /* This is it. Duplicate the callee body. Assume callee is @@ -5057,7 +5059,7 @@ optimize_inline_calls (tree fn) } /* Fold queued statements. */ - counts_to_freqs (); + update_max_bb_count (); fold_marked_statements (last, id.statements_to_fold); delete id.statements_to_fold; @@ -6034,7 +6036,7 @@ tree_function_versioning (tree old_decl, tree new_decl, free_dominance_info (CDI_DOMINATORS); free_dominance_info (CDI_POST_DOMINATORS); - counts_to_freqs (); + update_max_bb_count (); fold_marked_statements (0, id.statements_to_fold); delete id.statements_to_fold; delete_unreachable_blocks_update_callgraph (&id); -- cgit v1.2.1