Commit b5b6485f by Jan Hubicka Committed by Jan Hubicka

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
parent 9fdaaf77
2019-10-23 Jan Hubicka <hubicka@ucw.cz>
* 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 <qing.zhao@oracle.com> 2019-10-23 qing zhao <qing.zhao@oracle.com>
PR gcov-profile/91971 PR gcov-profile/91971
...@@ -93,9 +93,11 @@ typedef struct ipa_reference_vars_info_d *ipa_reference_vars_info_t; ...@@ -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 /* This map contains all of the static variables that are
being considered by the compilation level alias analysis. */ being considered by the compilation level alias analysis. */
typedef hash_map<int_hash <unsigned int, -1U>, tree> typedef hash_map<tree, int> reference_vars_map_t;
reference_vars_to_consider_t; static reference_vars_map_t *ipa_reference_vars_map;
static reference_vars_to_consider_t *reference_vars_to_consider; static int ipa_reference_vars_uids;
static vec<tree> *reference_vars_to_consider;
varpool_node_hook_list *varpool_node_hooks;
/* Set of all interesting module statics. A bit is set for every module /* 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 static we are considering. This is added to the local info when asm
...@@ -137,6 +139,31 @@ public: ...@@ -137,6 +139,31 @@ public:
static ipa_ref_opt_summary_t *ipa_ref_opt_sum_summaries = NULL; 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. */ /* Return the ipa_reference_vars structure starting from the cgraph NODE. */
static inline ipa_reference_vars_info_t static inline ipa_reference_vars_info_t
get_reference_vars_info (struct cgraph_node *node) get_reference_vars_info (struct cgraph_node *node)
...@@ -257,7 +284,9 @@ is_improper (symtab_node *n, void *v ATTRIBUTE_UNUSED) ...@@ -257,7 +284,9 @@ is_improper (symtab_node *n, void *v ATTRIBUTE_UNUSED)
static inline bool static inline bool
is_proper_for_analysis (tree t) 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; return false;
if (symtab_node::get (t) if (symtab_node::get (t)
...@@ -273,7 +302,7 @@ is_proper_for_analysis (tree t) ...@@ -273,7 +302,7 @@ is_proper_for_analysis (tree t)
static const char * static const char *
get_static_name (int index) 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. */ /* 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 ...@@ -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; static bool ipa_init_p = false;
/* The init routine for analyzing global static variable usage. See /* The init routine for analyzing global static variable usage. See
...@@ -414,8 +453,19 @@ ipa_init (void) ...@@ -414,8 +453,19 @@ ipa_init (void)
ipa_init_p = true; ipa_init_p = true;
if (dump_file) vec_alloc (reference_vars_to_consider, 10);
reference_vars_to_consider = new reference_vars_to_consider_t(251);
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 (&local_info_obstack);
bitmap_obstack_initialize (&optimization_summary_obstack); bitmap_obstack_initialize (&optimization_summary_obstack);
...@@ -424,12 +474,6 @@ ipa_init (void) ...@@ -424,12 +474,6 @@ ipa_init (void)
if (ipa_ref_var_info_summaries == NULL) if (ipa_ref_var_info_summaries == NULL)
ipa_ref_var_info_summaries = new ipa_ref_var_info_summary_t (symtab); 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) ...@@ -464,6 +508,8 @@ analyze_function (struct cgraph_node *fn)
local = init_function_info (fn); local = init_function_info (fn);
for (i = 0; fn->iterate_reference (i, ref); i++) for (i = 0; fn->iterate_reference (i, ref); i++)
{ {
int id;
bool existed;
if (!is_a <varpool_node *> (ref->referred)) if (!is_a <varpool_node *> (ref->referred))
continue; continue;
var = ref->referred->decl; var = ref->referred->decl;
...@@ -471,22 +517,22 @@ analyze_function (struct cgraph_node *fn) ...@@ -471,22 +517,22 @@ analyze_function (struct cgraph_node *fn)
continue; continue;
/* This is a variable we care about. Check if we have seen it /* 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. */ before, and if not add it the set of variables we care about. */
if (all_module_statics id = ipa_reference_var_get_or_insert_uid (var, &existed);
&& bitmap_set_bit (all_module_statics, ipa_reference_var_uid (var))) if (!existed)
{ {
bitmap_set_bit (all_module_statics, id);
if (dump_file) if (dump_file)
reference_vars_to_consider->put (ipa_reference_var_uid (var), reference_vars_to_consider->safe_push (var);
var);
} }
switch (ref->use) switch (ref->use)
{ {
case IPA_REF_LOAD: case IPA_REF_LOAD:
bitmap_set_bit (local->statics_read, ipa_reference_var_uid (var)); bitmap_set_bit (local->statics_read, id);
break; break;
case IPA_REF_STORE: case IPA_REF_STORE:
if (ref->cannot_lead_to_return ()) if (ref->cannot_lead_to_return ())
break; break;
bitmap_set_bit (local->statics_written, ipa_reference_var_uid (var)); bitmap_set_bit (local->statics_written, id);
break; break;
case IPA_REF_ADDR: case IPA_REF_ADDR:
break; break;
...@@ -896,7 +942,7 @@ propagate (void) ...@@ -896,7 +942,7 @@ propagate (void)
} }
if (dump_file) if (dump_file)
delete reference_vars_to_consider; vec_free (reference_vars_to_consider);
reference_vars_to_consider = NULL; reference_vars_to_consider = NULL;
return remove_p ? TODO_remove_functions : 0; return remove_p ? TODO_remove_functions : 0;
} }
...@@ -966,7 +1012,7 @@ stream_out_bitmap (struct lto_simple_output_block *ob, ...@@ -966,7 +1012,7 @@ stream_out_bitmap (struct lto_simple_output_block *ob,
return; return;
EXECUTE_IF_AND_IN_BITMAP (bits, ltrans_statics, 0, index, bi) 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); lto_output_var_decl_index (ob->decl_state, ob->main_stream, decl);
} }
} }
...@@ -984,22 +1030,23 @@ ipa_reference_write_optimization_summary (void) ...@@ -984,22 +1030,23 @@ ipa_reference_write_optimization_summary (void)
auto_bitmap ltrans_statics; auto_bitmap ltrans_statics;
int i; 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. */ /* See what variables we are interested in. */
for (i = 0; i < lto_symtab_encoder_size (encoder); i++) for (i = 0; i < lto_symtab_encoder_size (encoder); i++)
{ {
symtab_node *snode = lto_symtab_encoder_deref (encoder, i); symtab_node *snode = lto_symtab_encoder_deref (encoder, i);
varpool_node *vnode = dyn_cast <varpool_node *> (snode); varpool_node *vnode = dyn_cast <varpool_node *> (snode);
int id;
if (vnode if (vnode
&& bitmap_bit_p (all_module_statics, && (id = ipa_reference_var_uid (vnode->decl)) != -1
ipa_reference_var_uid (vnode->decl))
&& referenced_from_this_partition_p (vnode, encoder)) && referenced_from_this_partition_p (vnode, encoder))
{ {
tree decl = vnode->decl; tree decl = vnode->decl;
bitmap_set_bit (ltrans_statics, ipa_reference_var_uid (decl)); bitmap_set_bit (ltrans_statics, id);
reference_vars_to_consider->put (*reference_vars_to_consider)[id] = decl;
(ipa_reference_var_uid (decl), decl);
ltrans_statics_bitcount ++; ltrans_statics_bitcount ++;
} }
} }
...@@ -1055,8 +1102,12 @@ ipa_reference_read_optimization_summary (void) ...@@ -1055,8 +1102,12 @@ ipa_reference_read_optimization_summary (void)
unsigned int j = 0; unsigned int j = 0;
bitmap_obstack_initialize (&optimization_summary_obstack); bitmap_obstack_initialize (&optimization_summary_obstack);
if (ipa_ref_opt_sum_summaries == NULL) gcc_checking_assert (ipa_ref_opt_sum_summaries == NULL);
ipa_ref_opt_sum_summaries = new ipa_ref_opt_summary_t (symtab); 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); all_module_statics = BITMAP_ALLOC (&optimization_summary_obstack);
...@@ -1083,8 +1134,11 @@ ipa_reference_read_optimization_summary (void) ...@@ -1083,8 +1134,11 @@ ipa_reference_read_optimization_summary (void)
unsigned int var_index = streamer_read_uhwi (ib); unsigned int var_index = streamer_read_uhwi (ib);
tree v_decl = lto_file_decl_data_get_var_decl (file_data, tree v_decl = lto_file_decl_data_get_var_decl (file_data,
var_index); var_index);
bool existed;
bitmap_set_bit (all_module_statics, 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) if (dump_file)
fprintf (dump_file, " %s", fndecl_name (v_decl)); fprintf (dump_file, " %s", fndecl_name (v_decl));
} }
...@@ -1235,6 +1289,9 @@ ipa_reference_c_finalize (void) ...@@ -1235,6 +1289,9 @@ ipa_reference_c_finalize (void)
{ {
delete ipa_ref_opt_sum_summaries; delete ipa_ref_opt_sum_summaries;
ipa_ref_opt_sum_summaries = NULL; 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) if (ipa_init_p)
......
...@@ -25,12 +25,7 @@ along with GCC; see the file COPYING3. If not see ...@@ -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_read_global (struct cgraph_node *fn);
bitmap ipa_reference_get_not_written_global (struct cgraph_node *fn); bitmap ipa_reference_get_not_written_global (struct cgraph_node *fn);
void ipa_reference_c_finalize (void); void ipa_reference_c_finalize (void);
int ipa_reference_var_uid (tree t);
inline int
ipa_reference_var_uid (tree t)
{
return DECL_UID (symtab_node::get (t)->ultimate_alias_target (NULL)->decl);
}
#endif /* GCC_IPA_REFERENCE_H */ #endif /* GCC_IPA_REFERENCE_H */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment