From b5b6485f1cc54f21713b5b03c5d63d56839ca458 Mon Sep 17 00:00:00 2001 From: Jan Hubicka Date: Wed, 23 Oct 2019 20:18:31 +0200 Subject: [PATCH] ipa-reference.h (ipa_reference_var_uid): Move offline. * ipa-reference.h (ipa_reference_var_uid): Move offline. * ipa-reference.c (reference_vars_map_t): new type. (ipa_reference_vars_map, ipa_reference_vars_uids): New static vars. (ipa_reference_var_uid): Implement. (varpool_node_hooks): New static var. (varpool_removal_hook): New function. (is_improper): Do not check bitmap for id==-1 (get_static_name): Update. (ipa_init): Initialize new datastructures. (analyze_function): Do not recompute ids. (propagate): Free reference_vars_to_consider. (stream_out_bitmap): Update. (ipa_reference_read_optimization_summary): Update. From-SVN: r277345 --- gcc/ChangeLog | 16 ++++++ gcc/ipa-reference.c | 117 ++++++++++++++++++++++++++++++++------------ gcc/ipa-reference.h | 7 +-- 3 files changed, 104 insertions(+), 36 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index e1a4213dddd..4cd0fda8f1c 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,19 @@ +2019-10-23 Jan Hubicka + + * ipa-reference.h (ipa_reference_var_uid): Move offline. + * ipa-reference.c (reference_vars_map_t): new type. + (ipa_reference_vars_map, ipa_reference_vars_uids): New static vars. + (ipa_reference_var_uid): Implement. + (varpool_node_hooks): New static var. + (varpool_removal_hook): New function. + (is_improper): Do not check bitmap for id==-1 + (get_static_name): Update. + (ipa_init): Initialize new datastructures. + (analyze_function): Do not recompute ids. + (propagate): Free reference_vars_to_consider. + (stream_out_bitmap): Update. + (ipa_reference_read_optimization_summary): Update. + 2019-10-23 qing zhao PR gcov-profile/91971 diff --git a/gcc/ipa-reference.c b/gcc/ipa-reference.c index 977eb2d0fd8..1e35438bdd8 100644 --- a/gcc/ipa-reference.c +++ b/gcc/ipa-reference.c @@ -93,9 +93,11 @@ typedef struct ipa_reference_vars_info_d *ipa_reference_vars_info_t; /* This map contains all of the static variables that are being considered by the compilation level alias analysis. */ -typedef hash_map, tree> - reference_vars_to_consider_t; -static reference_vars_to_consider_t *reference_vars_to_consider; +typedef hash_map reference_vars_map_t; +static reference_vars_map_t *ipa_reference_vars_map; +static int ipa_reference_vars_uids; +static vec *reference_vars_to_consider; +varpool_node_hook_list *varpool_node_hooks; /* Set of all interesting module statics. A bit is set for every module static we are considering. This is added to the local info when asm @@ -137,6 +139,31 @@ public: static ipa_ref_opt_summary_t *ipa_ref_opt_sum_summaries = NULL; +/* Return ID used by ipa-reference bitmaps. -1 if failed. */ +int +ipa_reference_var_uid (tree t) +{ + if (!ipa_reference_vars_map) + return -1; + int *id = ipa_reference_vars_map->get + (symtab_node::get (t)->ultimate_alias_target (NULL)->decl); + if (!id) + return -1; + return *id; +} + +/* Return ID used by ipa-reference bitmaps. Create new entry if + T is not in map. Set EXISTED accordinly */ +int +ipa_reference_var_get_or_insert_uid (tree t, bool *existed) +{ + int &id = ipa_reference_vars_map->get_or_insert + (symtab_node::get (t)->ultimate_alias_target (NULL)->decl, existed); + if (!*existed) + id = ipa_reference_vars_uids++; + return id; +} + /* Return the ipa_reference_vars structure starting from the cgraph NODE. */ static inline ipa_reference_vars_info_t get_reference_vars_info (struct cgraph_node *node) @@ -257,7 +284,9 @@ is_improper (symtab_node *n, void *v ATTRIBUTE_UNUSED) static inline bool is_proper_for_analysis (tree t) { - if (bitmap_bit_p (ignore_module_statics, ipa_reference_var_uid (t))) + int id = ipa_reference_var_uid (t); + + if (id != -1 && bitmap_bit_p (ignore_module_statics, id)) return false; if (symtab_node::get (t) @@ -273,7 +302,7 @@ is_proper_for_analysis (tree t) static const char * get_static_name (int index) { - return fndecl_name (*reference_vars_to_consider->get (index)); + return fndecl_name ((*reference_vars_to_consider)[index]); } /* Dump a set of static vars to FILE. */ @@ -402,6 +431,16 @@ propagate_bits (ipa_reference_global_vars_info_t x_global, struct cgraph_node *x } } +/* Delete NODE from map. */ + +static void +varpool_removal_hook (varpool_node *node, void *) +{ + int *id = ipa_reference_vars_map->get (node->decl) + if (id) + ipa_reference_vars_map->remove (*id); +} + static bool ipa_init_p = false; /* The init routine for analyzing global static variable usage. See @@ -414,8 +453,19 @@ ipa_init (void) ipa_init_p = true; - if (dump_file) - reference_vars_to_consider = new reference_vars_to_consider_t(251); + vec_alloc (reference_vars_to_consider, 10); + + + if (ipa_ref_opt_sum_summaries != NULL) + { + delete ipa_ref_opt_sum_summaries; + ipa_ref_opt_sum_summaries = NULL; + delete ipa_reference_vars_map; + } + ipa_reference_vars_map = new reference_vars_map_t(257); + varpool_node_hooks + = symtab->add_varpool_removal_hook (varpool_removal_hook, NULL); + ipa_reference_vars_uids = 0; bitmap_obstack_initialize (&local_info_obstack); bitmap_obstack_initialize (&optimization_summary_obstack); @@ -424,12 +474,6 @@ ipa_init (void) if (ipa_ref_var_info_summaries == NULL) ipa_ref_var_info_summaries = new ipa_ref_var_info_summary_t (symtab); - - if (ipa_ref_opt_sum_summaries != NULL) - { - delete ipa_ref_opt_sum_summaries; - ipa_ref_opt_sum_summaries = NULL; - } } @@ -464,6 +508,8 @@ analyze_function (struct cgraph_node *fn) local = init_function_info (fn); for (i = 0; fn->iterate_reference (i, ref); i++) { + int id; + bool existed; if (!is_a (ref->referred)) continue; var = ref->referred->decl; @@ -471,22 +517,22 @@ analyze_function (struct cgraph_node *fn) continue; /* This is a variable we care about. Check if we have seen it before, and if not add it the set of variables we care about. */ - if (all_module_statics - && bitmap_set_bit (all_module_statics, ipa_reference_var_uid (var))) + id = ipa_reference_var_get_or_insert_uid (var, &existed); + if (!existed) { + bitmap_set_bit (all_module_statics, id); if (dump_file) - reference_vars_to_consider->put (ipa_reference_var_uid (var), - var); + reference_vars_to_consider->safe_push (var); } switch (ref->use) { case IPA_REF_LOAD: - bitmap_set_bit (local->statics_read, ipa_reference_var_uid (var)); + bitmap_set_bit (local->statics_read, id); break; case IPA_REF_STORE: if (ref->cannot_lead_to_return ()) break; - bitmap_set_bit (local->statics_written, ipa_reference_var_uid (var)); + bitmap_set_bit (local->statics_written, id); break; case IPA_REF_ADDR: break; @@ -896,7 +942,7 @@ propagate (void) } if (dump_file) - delete reference_vars_to_consider; + vec_free (reference_vars_to_consider); reference_vars_to_consider = NULL; return remove_p ? TODO_remove_functions : 0; } @@ -966,7 +1012,7 @@ stream_out_bitmap (struct lto_simple_output_block *ob, return; EXECUTE_IF_AND_IN_BITMAP (bits, ltrans_statics, 0, index, bi) { - tree decl = *reference_vars_to_consider->get (index); + tree decl = (*reference_vars_to_consider) [index]; lto_output_var_decl_index (ob->decl_state, ob->main_stream, decl); } } @@ -984,22 +1030,23 @@ ipa_reference_write_optimization_summary (void) auto_bitmap ltrans_statics; int i; - reference_vars_to_consider = new reference_vars_to_consider_t (251); + vec_alloc (reference_vars_to_consider, ipa_reference_vars_uids); + reference_vars_to_consider->safe_grow (ipa_reference_vars_uids); /* See what variables we are interested in. */ for (i = 0; i < lto_symtab_encoder_size (encoder); i++) { symtab_node *snode = lto_symtab_encoder_deref (encoder, i); varpool_node *vnode = dyn_cast (snode); + int id; + if (vnode - && bitmap_bit_p (all_module_statics, - ipa_reference_var_uid (vnode->decl)) + && (id = ipa_reference_var_uid (vnode->decl)) != -1 && referenced_from_this_partition_p (vnode, encoder)) { tree decl = vnode->decl; - bitmap_set_bit (ltrans_statics, ipa_reference_var_uid (decl)); - reference_vars_to_consider->put - (ipa_reference_var_uid (decl), decl); + bitmap_set_bit (ltrans_statics, id); + (*reference_vars_to_consider)[id] = decl; ltrans_statics_bitcount ++; } } @@ -1055,8 +1102,12 @@ ipa_reference_read_optimization_summary (void) unsigned int j = 0; bitmap_obstack_initialize (&optimization_summary_obstack); - if (ipa_ref_opt_sum_summaries == NULL) - ipa_ref_opt_sum_summaries = new ipa_ref_opt_summary_t (symtab); + gcc_checking_assert (ipa_ref_opt_sum_summaries == NULL); + ipa_ref_opt_sum_summaries = new ipa_ref_opt_summary_t (symtab); + ipa_reference_vars_map = new reference_vars_map_t(257); + varpool_node_hooks + = symtab->add_varpool_removal_hook (varpool_removal_hook, NULL); + ipa_reference_vars_uids = 0; all_module_statics = BITMAP_ALLOC (&optimization_summary_obstack); @@ -1083,8 +1134,11 @@ ipa_reference_read_optimization_summary (void) unsigned int var_index = streamer_read_uhwi (ib); tree v_decl = lto_file_decl_data_get_var_decl (file_data, var_index); + bool existed; bitmap_set_bit (all_module_statics, - ipa_reference_var_uid (v_decl)); + ipa_reference_var_get_or_insert_uid + (v_decl, &existed)); + gcc_checking_assert (!existed); if (dump_file) fprintf (dump_file, " %s", fndecl_name (v_decl)); } @@ -1235,6 +1289,9 @@ ipa_reference_c_finalize (void) { delete ipa_ref_opt_sum_summaries; ipa_ref_opt_sum_summaries = NULL; + delete ipa_reference_vars_map; + ipa_reference_vars_map = NULL; + symtab->remove_varpool_removal_hook (varpool_node_hooks) } if (ipa_init_p) diff --git a/gcc/ipa-reference.h b/gcc/ipa-reference.h index 3be02fbb32f..6563db6defa 100644 --- a/gcc/ipa-reference.h +++ b/gcc/ipa-reference.h @@ -25,12 +25,7 @@ along with GCC; see the file COPYING3. If not see bitmap ipa_reference_get_not_read_global (struct cgraph_node *fn); bitmap ipa_reference_get_not_written_global (struct cgraph_node *fn); void ipa_reference_c_finalize (void); - -inline int -ipa_reference_var_uid (tree t) -{ - return DECL_UID (symtab_node::get (t)->ultimate_alias_target (NULL)->decl); -} +int ipa_reference_var_uid (tree t); #endif /* GCC_IPA_REFERENCE_H */ -- 2.30.2