gcc/ChangeLog: 2015-07-03 Martin Liska <mli...@suse.cz>
* ipa-reference.c (ipa_ref_opt_summary_t): New class. (get_reference_optimization_summary): Use it. (set_reference_optimization_summary): Likewise. (ipa_init): Remove hook holders usage. (ipa_reference_c_finalize): Likewise. (ipa_ref_opt_summary_t::duplicate): New function. (ipa_ref_opt_summary_t::remove): Likewise. (propagate): Allocate the summary if does not exist. (ipa_reference_read_optimization_summary): Likewise. (struct ipa_reference_vars_info_d): Add new method. (struct ipa_reference_optimization_summary_d): Likewise. (get_reference_vars_info): Use new underlying container. (set_reference_vars_info): Remove. (init_function_info): Set up the container. --- gcc/ipa-reference.c | 203 ++++++++++++++++++++++++++-------------------------- 1 file changed, 102 insertions(+), 101 deletions(-) diff --git a/gcc/ipa-reference.c b/gcc/ipa-reference.c index 465a74b..2afd9ad 100644 --- a/gcc/ipa-reference.c +++ b/gcc/ipa-reference.c @@ -58,12 +58,7 @@ along with GCC; see the file COPYING3. If not see #include "diagnostic.h" #include "data-streamer.h" #include "lto-streamer.h" - -static void remove_node_data (struct cgraph_node *node, - void *data ATTRIBUTE_UNUSED); -static void duplicate_node_data (struct cgraph_node *src, - struct cgraph_node *dst, - void *data ATTRIBUTE_UNUSED); +#include "symbol-summary.h" /* The static variables defined within the compilation unit that are loaded or stored directly by function that owns this structure. */ @@ -89,6 +84,13 @@ struct ipa_reference_global_vars_info_d struct ipa_reference_optimization_summary_d { + /* Return true if the data structure is empty. */ + inline bool + empty_p () + { + return statics_not_read == NULL && statics_not_written == NULL; + } + bitmap statics_not_read; bitmap statics_not_written; }; @@ -99,6 +101,14 @@ typedef struct ipa_reference_optimization_summary_d *ipa_reference_optimization_ struct ipa_reference_vars_info_d { + /* Return true if the data structure is empty. */ + inline bool + empty_p () + { + return local.statics_read == NULL && local.statics_written == NULL + && global.statics_read == NULL && global.statics_written == NULL; + } + struct ipa_reference_local_vars_info_d local; struct ipa_reference_global_vars_info_d global; }; @@ -123,57 +133,61 @@ static bitmap_obstack local_info_obstack; /* Obstack holding global analysis live forever. */ static bitmap_obstack optimization_summary_obstack; -/* Holders of ipa cgraph hooks: */ -static struct cgraph_2node_hook_list *node_duplication_hook_holder; -static struct cgraph_node_hook_list *node_removal_hook_holder; +class ipa_ref_var_info_summary_t: public function_summary + <ipa_reference_vars_info_d *> +{ +public: + ipa_ref_var_info_summary_t (symbol_table *symtab): + function_summary <ipa_reference_vars_info_d *> (symtab) {} +}; -/* Vector where the reference var infos are actually stored. - Indexed by UID of call graph nodes. */ -static vec<ipa_reference_vars_info_t> ipa_reference_vars_vector; +static ipa_ref_var_info_summary_t *ipa_ref_var_info_summaries = NULL; -/* TODO: find a place where we should release the vector. */ -static vec<ipa_reference_optimization_summary_t> ipa_reference_opt_sum_vector; +class ipa_ref_opt_summary_t: public function_summary + <ipa_reference_optimization_summary_d *> +{ +public: + ipa_ref_opt_summary_t (symbol_table *symtab): + function_summary <ipa_reference_optimization_summary_d *> (symtab) {} + + + virtual void remove (cgraph_node *src_node, + ipa_reference_optimization_summary_d *data); + virtual void duplicate (cgraph_node *src_node, cgraph_node *dst_node, + ipa_reference_optimization_summary_d *src_data, + ipa_reference_optimization_summary_d *dst_data); +}; + +static ipa_ref_opt_summary_t *ipa_ref_opt_sum_summaries = NULL; /* 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) { - if (!ipa_reference_vars_vector.exists () - || ipa_reference_vars_vector.length () <= (unsigned int) node->uid) + if (ipa_ref_var_info_summaries == NULL) return NULL; - return ipa_reference_vars_vector[node->uid]; + + ipa_reference_vars_info_t v = ipa_ref_var_info_summaries->get (node); + if (v->empty_p ()) + return NULL; + + return v; } /* Return the ipa_reference_vars structure starting from the cgraph NODE. */ static inline ipa_reference_optimization_summary_t get_reference_optimization_summary (struct cgraph_node *node) { - if (!ipa_reference_opt_sum_vector.exists () - || (ipa_reference_opt_sum_vector.length () <= (unsigned int) node->uid)) + if (ipa_ref_opt_sum_summaries == NULL) return NULL; - return ipa_reference_opt_sum_vector[node->uid]; -} -/* Return the ipa_reference_vars structure starting from the cgraph NODE. */ -static inline void -set_reference_vars_info (struct cgraph_node *node, - ipa_reference_vars_info_t info) -{ - if (!ipa_reference_vars_vector.exists () - || ipa_reference_vars_vector.length () <= (unsigned int) node->uid) - ipa_reference_vars_vector.safe_grow_cleared (node->uid + 1); - ipa_reference_vars_vector[node->uid] = info; -} + ipa_reference_optimization_summary_t v = ipa_ref_opt_sum_summaries->get + (node); -/* Return the ipa_reference_vars structure starting from the cgraph NODE. */ -static inline void -set_reference_optimization_summary (struct cgraph_node *node, - ipa_reference_optimization_summary_t info) -{ - if (!ipa_reference_opt_sum_vector.exists () - || (ipa_reference_opt_sum_vector.length () <= (unsigned int) node->uid)) - ipa_reference_opt_sum_vector.safe_grow_cleared (node->uid + 1); - ipa_reference_opt_sum_vector[node->uid] = info; + if (v->empty_p ()) + return NULL; + + return v; } /* Return a bitmap indexed by DECL_UID for the static variables that @@ -412,10 +426,14 @@ ipa_init (void) all_module_statics = BITMAP_ALLOC (&optimization_summary_obstack); ignore_module_statics = BITMAP_ALLOC (&optimization_summary_obstack); - node_removal_hook_holder = - symtab->add_cgraph_removal_hook (&remove_node_data, NULL); - node_duplication_hook_holder = - symtab->add_cgraph_duplication_hook (&duplicate_node_data, NULL); + 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; + } } @@ -424,11 +442,7 @@ ipa_init (void) static ipa_reference_local_vars_info_t init_function_info (struct cgraph_node *fn) { - ipa_reference_vars_info_t info - = XCNEW (struct ipa_reference_vars_info_d); - - /* Add the info to the tree's annotation. */ - set_reference_vars_info (fn, info); + ipa_reference_vars_info_t info = ipa_ref_var_info_summaries->get (fn); info->local.statics_read = BITMAP_ALLOC (&local_info_obstack); info->local.statics_written = BITMAP_ALLOC (&local_info_obstack); @@ -491,18 +505,12 @@ analyze_function (struct cgraph_node *fn) /* Called when new clone is inserted to callgraph late. */ -static void -duplicate_node_data (struct cgraph_node *src, struct cgraph_node *dst, - void *data ATTRIBUTE_UNUSED) +void +ipa_ref_opt_summary_t::duplicate (cgraph_node *, cgraph_node *, + ipa_reference_optimization_summary_d *ginfo, + ipa_reference_optimization_summary_d + *dst_ginfo) { - ipa_reference_optimization_summary_t ginfo; - ipa_reference_optimization_summary_t dst_ginfo; - - ginfo = get_reference_optimization_summary (src); - if (!ginfo) - return; - dst_ginfo = XCNEW (struct ipa_reference_optimization_summary_d); - set_reference_optimization_summary (dst, dst_ginfo); dst_ginfo->statics_not_read = copy_static_var_set (ginfo->statics_not_read); dst_ginfo->statics_not_written = @@ -511,23 +519,17 @@ duplicate_node_data (struct cgraph_node *src, struct cgraph_node *dst, /* Called when node is removed. */ -static void -remove_node_data (struct cgraph_node *node, void *data ATTRIBUTE_UNUSED) +void +ipa_ref_opt_summary_t::remove (cgraph_node *, + ipa_reference_optimization_summary_d *ginfo) { - ipa_reference_optimization_summary_t ginfo; - ginfo = get_reference_optimization_summary (node); - if (ginfo) - { - if (ginfo->statics_not_read - && ginfo->statics_not_read != all_module_statics) - BITMAP_FREE (ginfo->statics_not_read); - - if (ginfo->statics_not_written - && ginfo->statics_not_written != all_module_statics) - BITMAP_FREE (ginfo->statics_not_written); - free (ginfo); - set_reference_optimization_summary (node, NULL); - } + if (ginfo->statics_not_read + && ginfo->statics_not_read != all_module_statics) + BITMAP_FREE (ginfo->statics_not_read); + + if (ginfo->statics_not_written + && ginfo->statics_not_written != all_module_statics) + BITMAP_FREE (ginfo->statics_not_written); } /* Analyze each function in the cgraph to see which global or statics @@ -837,12 +839,14 @@ propagate (void) } } + if (ipa_ref_opt_sum_summaries == NULL) + ipa_ref_opt_sum_summaries = new ipa_ref_opt_summary_t (symtab); + /* Cleanup. */ FOR_EACH_DEFINED_FUNCTION (node) { ipa_reference_vars_info_t node_info; ipa_reference_global_vars_info_t node_g; - ipa_reference_optimization_summary_t opt; node_info = get_reference_vars_info (node); if (!node->alias && opt_for_fn (node->decl, flag_ipa_reference) @@ -851,8 +855,8 @@ propagate (void) { node_g = &node_info->global; - opt = XCNEW (struct ipa_reference_optimization_summary_d); - set_reference_optimization_summary (node, opt); + ipa_reference_optimization_summary_d *opt = + ipa_ref_opt_sum_summaries->get (node); /* Create the complimentary sets. */ @@ -880,14 +884,20 @@ propagate (void) node_g->statics_written); } } - free (node_info); } ipa_free_postorder_info (); free (order); bitmap_obstack_release (&local_info_obstack); - ipa_reference_vars_vector.release (); + + if (ipa_ref_var_info_summaries == NULL) + { + delete ipa_ref_var_info_summaries; + ipa_ref_var_info_summaries = NULL; + } + + ipa_ref_var_info_summaries = NULL; if (dump_file) splay_tree_delete (reference_vars_to_consider); reference_vars_to_consider = NULL; @@ -907,8 +917,10 @@ write_node_summary_p (struct cgraph_node *node, if (!node->definition || node->global.inlined_to) return false; info = get_reference_optimization_summary (node); - if (!info || (bitmap_empty_p (info->statics_not_read) - && bitmap_empty_p (info->statics_not_written))) + if (!info + || info->empty_p () + || (bitmap_empty_p (info->statics_not_read) + && bitmap_empty_p (info->statics_not_written))) return false; /* See if we want to encode it. @@ -1047,10 +1059,9 @@ ipa_reference_read_optimization_summary (void) unsigned int j = 0; bitmap_obstack_initialize (&optimization_summary_obstack); - node_removal_hook_holder = - symtab->add_cgraph_removal_hook (&remove_node_data, NULL); - node_duplication_hook_holder = - symtab->add_cgraph_duplication_hook (&duplicate_node_data, NULL); + if (ipa_ref_opt_sum_summaries == NULL) + ipa_ref_opt_sum_summaries = new ipa_ref_opt_summary_t (symtab); + all_module_statics = BITMAP_ALLOC (&optimization_summary_obstack); while ((file_data = file_data_vec[j++])) @@ -1085,7 +1096,6 @@ ipa_reference_read_optimization_summary (void) { unsigned int j, index; struct cgraph_node *node; - ipa_reference_optimization_summary_t info; int v_count; lto_symtab_encoder_t encoder; @@ -1093,8 +1103,10 @@ ipa_reference_read_optimization_summary (void) encoder = file_data->symtab_node_encoder; node = dyn_cast<cgraph_node *> (lto_symtab_encoder_deref (encoder, index)); - info = XCNEW (struct ipa_reference_optimization_summary_d); - set_reference_optimization_summary (node, info); + + ipa_reference_optimization_summary_d *info = + ipa_ref_opt_sum_summaries->get (node); + info->statics_not_read = BITMAP_ALLOC (&optimization_summary_obstack); info->statics_not_written = BITMAP_ALLOC (&optimization_summary_obstack); if (dump_file) @@ -1223,15 +1235,4 @@ ipa_reference_c_finalize (void) bitmap_obstack_release (&optimization_summary_obstack); ipa_init_p = false; } - - if (node_removal_hook_holder) - { - symtab->remove_cgraph_removal_hook (node_removal_hook_holder); - node_removal_hook_holder = NULL; - } - if (node_duplication_hook_holder) - { - symtab->remove_cgraph_duplication_hook (node_duplication_hook_holder); - node_duplication_hook_holder = NULL; - } } -- 2.4.5