From a4a3cdd04308ce45c4bee32401fc8121cb561807 Mon Sep 17 00:00:00 2001 From: Martin Jambor Date: Mon, 10 May 2021 16:24:08 +0200 Subject: ipa: Get rid of IPA_NODE_REF and IPA_EDGE_REF The node and edge summaries defined in ipa-prop.h are probably the oldest in GCC and so it happened that they are the only ones using macros to look them up and create them. With Honza and Martin we agreed it is ugly and the macros should be removed and the ipa-prop summaries should be accessed like all the other ones but somehow I never got to it until now. The patch is mostly mechanical. Because the lookup machinery was much simpler in the old times (something like the fast summaries we have today), a lot of code queried for the summary multiple times for no good reasons and I fixed that in places where it was easy. Also, before we switched to hash based summaries, new summary pointers had to be obtained whenever the underlying array could be reallocated because of new cgraph nodes/edges. This is no longer necessary and so I removed the instances which I found. Both kinds of these non-mechanical changes should be specifically called out in the ChangeLog. I also removed the IS_VALID_JUMP_FUNC_INDEX macro because it not used anywhere. gcc/ChangeLog: 2021-05-07 Martin Jambor * ipa-prop.h (IPA_NODE_REF): Removed. (IPA_NODE_REF_GET_CREATE): Likewise. (IPA_EDGE_REF): Likewise. (IPA_EDGE_REF_GET_CREATE): Likewise. (IS_VALID_JUMP_FUNC_INDEX): Likewise. * ipa-cp.c (print_all_lattices): Replaced IPA_NODE_REF with a direct use of ipa_node_params_sum. (ipcp_versionable_function_p): Likewise. (push_node_to_stack): Likewise. (pop_node_from_stack): Likewise. (set_single_call_flag): Replaced two IPA_NODE_REF with one single direct use of ipa_node_params_sum. (initialize_node_lattices): Replaced IPA_NODE_REF with a direct use of ipa_node_params_sum. (ipa_context_from_jfunc): Replaced IPA_EDGE_REF with a direct use of ipa_edge_args_sum. (ipcp_verify_propagated_values): Replaced IPA_NODE_REF with a direct use of ipa_node_params_sum. (self_recursively_generated_p): Likewise. (propagate_scalar_across_jump_function): Likewise. (propagate_context_across_jump_function): Replaced IPA_EDGE_REF with a direct use of ipa_edge_args_sum, moved the lookup after the early exit. Replaced IPA_NODE_REF with a direct use of ipa_node_params_sum. (propagate_bits_across_jump_function): Replaced IPA_NODE_REF with direct uses of ipa_node_params_sum. (propagate_vr_across_jump_function): Likewise. (propagate_aggregate_lattice): Likewise. (propagate_aggs_across_jump_function): Likewise. (propagate_constants_across_call): Likewise, also replaced IPA_EDGE_REF with a direct use of ipa_edge_args_sum. (good_cloning_opportunity_p): Replaced IPA_NODE_REF with a direct use of ipa_node_params_sum. (estimate_local_effects): Likewise. (add_all_node_vals_to_toposort): Likewise. (propagate_constants_topo): Likewise. (ipcp_propagate_stage): Likewise. (ipcp_discover_new_direct_edges): Likewise. (calls_same_node_or_its_all_contexts_clone_p): Likewise. (cgraph_edge_brings_value_p): Likewise (in both overloaded functions). (get_info_about_necessary_edges): Likewise. (want_remove_some_param_p): Likewise. (create_specialized_node): Likewise. (self_recursive_pass_through_p): Likewise. (self_recursive_agg_pass_through_p): Likewise. (find_more_scalar_values_for_callers_subset): Likewise and also replaced IPA_EDGE_REF with direct uses of ipa_edge_args_sum, in one case replacing two of those with a single query. (find_more_contexts_for_caller_subset): Likewise for the ipa_polymorphic_call_context overload. (intersect_aggregates_with_edge): Replaced IPA_EDGE_REF with a direct use of ipa_edge_args_sum. Replaced IPA_NODE_REF with direct uses of ipa_node_params_sum. (find_aggregate_values_for_callers_subset): Likewise, also reusing results of ipa_edge_args_sum->get. (cgraph_edge_brings_all_scalars_for_node): Replaced IPA_NODE_REF with direct uses of ipa_node_params_sum, replaced IPA_EDGE_REF with a direct use of ipa_edge_args_sum. (cgraph_edge_brings_all_agg_vals_for_node): Likewise, moved node summary query after the early exit and reused the result later. (decide_about_value): Replaced IPA_NODE_REF with a direct use of ipa_node_params_sum. (decide_whether_version_node): Likewise. Removed re-querying for summaries after cloning. (spread_undeadness): Replaced IPA_NODE_REF with a direct use of ipa_node_params_sum. (has_undead_caller_from_outside_scc_p): Likewise, reusing results of some queries. (identify_dead_nodes): Likewise. (ipcp_store_bits_results): Replaced IPA_NODE_REF with direct uses of ipa_node_params_sum. (ipcp_store_vr_results): Likewise. * ipa-fnsummary.c (evaluate_properties_for_edge): Likewise. (ipa_fn_summary_t::duplicate): Likewise. (analyze_function_body): Likewise. (estimate_calls_size_and_time): Likewise. (ipa_cached_call_context::duplicate_from): Likewise. (ipa_call_context::equal_to): Likewise. (remap_edge_params): Likewise. (ipa_merge_fn_summary_after_inlining): Likewise. (inline_read_section): Likewise. * ipa-icf.c (sem_function::param_used_p): Likewise. * ipa-modref.c (compute_parm_map): Likewise. (compute_parm_map): Replaced IPA_EDGE_REF with a direct use of ipa_edge_args_sum. (get_access_for_fnspec): Replaced IPA_NODE_REF with a direct use of ipa_node_params_sum and replaced IPA_EDGE_REF with a direct use of ipa_edge_args_sum. * ipa-profile.c (check_argument_count): Likewise. * ipa-prop.c (ipa_alloc_node_params): Replaced IPA_NODE_REF_GET_CREATE with a direct use of ipa_node_params_sum. (ipa_initialize_node_params): Likewise. (ipa_print_node_jump_functions_for_edge): Replaced IPA_EDGE_REF with a direct use of ipa_edge_args_sum and reused the query result. (ipa_compute_jump_functions_for_edge): Replaced IPA_NODE_REF with a direct use of ipa_node_params_sum and replaced IPA_EDGE_REF with a direct use of ipa_edge_args_sum. (ipa_note_param_call): Replaced IPA_NODE_REF with a direct use of ipa_node_params_sum and reused the result of the query. (ipa_analyze_node): Likewise. (ipa_analyze_controlled_uses): Replaced IPA_NODE_REF with a direct use of ipa_node_params_sum. (update_jump_functions_after_inlining): Replaced IPA_EDGE_REF with direct uses of ipa_edge_args_sum. (update_indirect_edges_after_inlining): Replaced IPA_NODE_REF with direct uses of ipa_node_params_sum and replaced IPA_EDGE_REF with a direct use of ipa_edge_args_sum. Removed superficial re-querying the top edge summary. (propagate_controlled_uses): Replaced IPA_NODE_REF with direct uses of ipa_node_params_sum and replaced IPA_EDGE_REF with a direct use of ipa_edge_args_sum. (ipa_propagate_indirect_call_infos): Replaced IPA_EDGE_REF with a direct use of ipa_edge_args_sum. (ipa_edge_args_sum_t::duplicate): Replaced IPA_NODE_REF with a direct use of ipa_node_params_sum. (ipa_print_node_params): Likewise. (ipa_write_node_info): Likewise and also replaced IPA_EDGE_REF with direct uses of ipa_edge_args_sum. (ipa_read_edge_info): Replaced IPA_EDGE_REF with a direct use of ipa_edge_args_sum. (ipa_read_node_info): Replaced IPA_NODE_REF with a direct use of ipa_node_params_sum. (ipa_prop_write_jump_functions): Likewise. Move variable node to the scopes where it is used. --- gcc/ipa-prop.c | 76 ++++++++++++++++++++++++++++------------------------------ 1 file changed, 36 insertions(+), 40 deletions(-) (limited to 'gcc/ipa-prop.c') diff --git a/gcc/ipa-prop.c b/gcc/ipa-prop.c index 02c483b..0591ef1 100644 --- a/gcc/ipa-prop.c +++ b/gcc/ipa-prop.c @@ -276,7 +276,7 @@ ipa_dump_param (FILE *file, class ipa_node_params *info, int i) static bool ipa_alloc_node_params (struct cgraph_node *node, int param_count) { - class ipa_node_params *info = IPA_NODE_REF_GET_CREATE (node); + ipa_node_params *info = ipa_node_params_sum->get_create (node); if (!info->descriptors && param_count) { @@ -294,7 +294,7 @@ ipa_alloc_node_params (struct cgraph_node *node, int param_count) void ipa_initialize_node_params (struct cgraph_node *node) { - class ipa_node_params *info = IPA_NODE_REF_GET_CREATE (node); + ipa_node_params *info = ipa_node_params_sum->get_create (node); if (!info->descriptors && ipa_alloc_node_params (node, count_formal_params (node->decl))) @@ -306,15 +306,15 @@ ipa_initialize_node_params (struct cgraph_node *node) static void ipa_print_node_jump_functions_for_edge (FILE *f, struct cgraph_edge *cs) { - int i, count; + ipa_edge_args *args = ipa_edge_args_sum->get (cs); + int count = ipa_get_cs_argument_count (args); - count = ipa_get_cs_argument_count (IPA_EDGE_REF (cs)); - for (i = 0; i < count; i++) + for (int i = 0; i < count; i++) { struct ipa_jump_func *jump_func; enum jump_func_type type; - jump_func = ipa_get_ith_jump_func (IPA_EDGE_REF (cs), i); + jump_func = ipa_get_ith_jump_func (args, i); type = jump_func->type; fprintf (f, " param %d: ", i); @@ -410,7 +410,7 @@ ipa_print_node_jump_functions_for_edge (FILE *f, struct cgraph_edge *cs) } class ipa_polymorphic_call_context *ctx - = ipa_get_ith_polymorhic_call_context (IPA_EDGE_REF (cs), i); + = ipa_get_ith_polymorhic_call_context (args, i); if (ctx && !ctx->useless_p ()) { fprintf (f, " Context: "); @@ -2232,8 +2232,8 @@ static void ipa_compute_jump_functions_for_edge (struct ipa_func_body_info *fbi, struct cgraph_edge *cs) { - class ipa_node_params *info = IPA_NODE_REF (cs->caller); - class ipa_edge_args *args = IPA_EDGE_REF_GET_CREATE (cs); + ipa_node_params *info = ipa_node_params_sum->get (cs->caller); + ipa_edge_args *args = ipa_edge_args_sum->get_create (cs); gcall *call = cs->call_stmt; int n, arg_num = gimple_call_num_args (call); bool useful_context = false; @@ -2509,11 +2509,10 @@ ipa_note_param_call (struct cgraph_node *node, int param_index, cs->indirect_info->agg_contents = 0; cs->indirect_info->member_ptr = 0; cs->indirect_info->guaranteed_unmodified = 0; - ipa_set_param_used_by_indirect_call (IPA_NODE_REF (node), - param_index, true); + ipa_node_params *info = ipa_node_params_sum->get (node); + ipa_set_param_used_by_indirect_call (info, param_index, true); if (cs->indirect_info->polymorphic || polymorphic) - ipa_set_param_used_by_polymorphic_call - (IPA_NODE_REF (node), param_index, true); + ipa_set_param_used_by_polymorphic_call (info, param_index, true); return cs; } @@ -2884,7 +2883,7 @@ ipa_analyze_params_uses_in_bb (struct ipa_func_body_info *fbi, basic_block bb) static void ipa_analyze_controlled_uses (struct cgraph_node *node) { - class ipa_node_params *info = IPA_NODE_REF (node); + ipa_node_params *info = ipa_node_params_sum->get (node); for (int i = 0; i < ipa_get_param_count (info); i++) { @@ -2980,7 +2979,7 @@ ipa_analyze_node (struct cgraph_node *node) ipa_check_create_node_params (); ipa_check_create_edge_args (); - info = IPA_NODE_REF_GET_CREATE (node); + info = ipa_node_params_sum->get_create (node); if (info->analysis_done) return; @@ -3003,7 +3002,7 @@ ipa_analyze_node (struct cgraph_node *node) ipa_analyze_controlled_uses (node); fbi.node = node; - fbi.info = IPA_NODE_REF (node); + fbi.info = info; fbi.bb_infos = vNULL; fbi.bb_infos.safe_grow_cleared (last_basic_block_for_fn (cfun), true); fbi.param_count = ipa_get_param_count (info); @@ -3036,8 +3035,8 @@ static void update_jump_functions_after_inlining (struct cgraph_edge *cs, struct cgraph_edge *e) { - class ipa_edge_args *top = IPA_EDGE_REF (cs); - class ipa_edge_args *args = IPA_EDGE_REF (e); + ipa_edge_args *top = ipa_edge_args_sum->get (cs); + ipa_edge_args *args = ipa_edge_args_sum->get (e); if (!args) return; int count = ipa_get_cs_argument_count (args); @@ -3889,11 +3888,11 @@ update_indirect_edges_after_inlining (struct cgraph_edge *cs, bool res = false; ipa_check_create_edge_args (); - top = IPA_EDGE_REF (cs); + top = ipa_edge_args_sum->get (cs); new_root = cs->caller->inlined_to ? cs->caller->inlined_to : cs->caller; - new_root_info = IPA_NODE_REF (new_root); - inlined_node_info = IPA_NODE_REF (cs->callee->function_symbol ()); + new_root_info = ipa_node_params_sum->get (new_root); + inlined_node_info = ipa_node_params_sum->get (cs->callee->function_symbol ()); for (ie = node->indirect_calls; ie; ie = next_ie) { @@ -3947,7 +3946,6 @@ update_indirect_edges_after_inlining (struct cgraph_edge *cs, && spec_targets.contains (new_direct_edge->callee)) { new_direct_edge->indirect_inlining_edge = 1; - top = IPA_EDGE_REF (cs); res = true; if (!new_direct_edge->speculative) continue; @@ -3960,7 +3958,6 @@ update_indirect_edges_after_inlining (struct cgraph_edge *cs, new_edges->safe_push (new_direct_edge); res = true; } - top = IPA_EDGE_REF (cs); /* If speculative edge was introduced we still need to update call info of the indirect edge. */ if (!new_direct_edge->speculative) @@ -4060,13 +4057,13 @@ combine_controlled_uses_counters (int c, int d) static void propagate_controlled_uses (struct cgraph_edge *cs) { - class ipa_edge_args *args = IPA_EDGE_REF (cs); + ipa_edge_args *args = ipa_edge_args_sum->get (cs); if (!args) return; struct cgraph_node *new_root = cs->caller->inlined_to ? cs->caller->inlined_to : cs->caller; - class ipa_node_params *new_root_info = IPA_NODE_REF (new_root); - class ipa_node_params *old_root_info = IPA_NODE_REF (cs->callee); + ipa_node_params *new_root_info = ipa_node_params_sum->get (new_root); + ipa_node_params *old_root_info = ipa_node_params_sum->get (cs->callee); int count, i; if (!old_root_info) @@ -4195,7 +4192,7 @@ ipa_propagate_indirect_call_infos (struct cgraph_edge *cs, changed = propagate_info_to_inlined_callees (cs, cs->callee, new_edges); ipa_node_params_sum->remove (cs->callee); - class ipa_edge_args *args = IPA_EDGE_REF (cs); + ipa_edge_args *args = ipa_edge_args_sum->get (cs); if (args) { bool ok = true; @@ -4403,7 +4400,7 @@ ipa_edge_args_sum_t::duplicate (cgraph_edge *src, cgraph_edge *dst, { struct cgraph_node *inline_root = dst->caller->inlined_to ? dst->caller->inlined_to : dst->caller; - class ipa_node_params *root_info = IPA_NODE_REF (inline_root); + ipa_node_params *root_info = ipa_node_params_sum->get (inline_root); int idx = ipa_get_jf_pass_through_formal_id (dst_jf); int c = ipa_get_controlled_uses (root_info, idx); @@ -4553,7 +4550,7 @@ ipa_print_node_params (FILE *f, struct cgraph_node *node) if (!node->definition) return; - info = IPA_NODE_REF (node); + info = ipa_node_params_sum->get (node); fprintf (f, " function %s parameter descriptors:\n", node->dump_name ()); if (!info) { @@ -4956,7 +4953,7 @@ ipa_write_node_info (struct output_block *ob, struct cgraph_node *node) { int node_ref; lto_symtab_encoder_t encoder; - class ipa_node_params *info = IPA_NODE_REF (node); + ipa_node_params *info = ipa_node_params_sum->get (node); int j; struct cgraph_edge *e; struct bitpack_d bp; @@ -4983,7 +4980,7 @@ ipa_write_node_info (struct output_block *ob, struct cgraph_node *node) } for (e = node->callees; e; e = e->next_callee) { - class ipa_edge_args *args = IPA_EDGE_REF (e); + ipa_edge_args *args = ipa_edge_args_sum->get (e); if (!args) { @@ -5003,7 +5000,7 @@ ipa_write_node_info (struct output_block *ob, struct cgraph_node *node) } for (e = node->indirect_calls; e; e = e->next_callee) { - class ipa_edge_args *args = IPA_EDGE_REF (e); + ipa_edge_args *args = ipa_edge_args_sum->get (e); if (!args) streamer_write_uhwi (ob, 0); else @@ -5041,7 +5038,7 @@ ipa_read_edge_info (class lto_input_block *ib, will get fnspecs. */ || fndecl_built_in_p (e->callee->decl, BUILT_IN_NORMAL))) { - class ipa_edge_args *args = IPA_EDGE_REF_GET_CREATE (e); + ipa_edge_args *args = ipa_edge_args_sum->get_create (e); vec_safe_grow_cleared (args->jump_functions, count, true); if (contexts_computed) vec_safe_grow_cleared (args->polymorphic_call_contexts, count, true); @@ -5080,8 +5077,8 @@ ipa_read_node_info (class lto_input_block *ib, struct cgraph_node *node, struct cgraph_edge *e; struct bitpack_d bp; bool prevails = node->prevailing_p (); - class ipa_node_params *info = prevails - ? IPA_NODE_REF_GET_CREATE (node) : NULL; + ipa_node_params *info + = prevails ? ipa_node_params_sum->get_create (node) : NULL; int param_count = streamer_read_uhwi (ib); if (prevails) @@ -5130,7 +5127,6 @@ ipa_read_node_info (class lto_input_block *ib, struct cgraph_node *node, void ipa_prop_write_jump_functions (void) { - struct cgraph_node *node; struct output_block *ob; unsigned int count = 0; lto_symtab_encoder_iterator lsei; @@ -5145,9 +5141,9 @@ ipa_prop_write_jump_functions (void) for (lsei = lsei_start_function_in_partition (encoder); !lsei_end_p (lsei); lsei_next_function_in_partition (&lsei)) { - node = lsei_cgraph_node (lsei); + cgraph_node *node = lsei_cgraph_node (lsei); if (node->has_gimple_body_p () - && IPA_NODE_REF (node) != NULL) + && ipa_node_params_sum->get (node) != NULL) count++; } @@ -5157,9 +5153,9 @@ ipa_prop_write_jump_functions (void) for (lsei = lsei_start_function_in_partition (encoder); !lsei_end_p (lsei); lsei_next_function_in_partition (&lsei)) { - node = lsei_cgraph_node (lsei); + cgraph_node *node = lsei_cgraph_node (lsei); if (node->has_gimple_body_p () - && IPA_NODE_REF (node) != NULL) + && ipa_node_params_sum->get (node) != NULL) ipa_write_node_info (ob, node); } streamer_write_char_stream (ob->main_stream, 0); -- cgit v1.1