#include "splay-tree.h"
#include "ipa-utils.h"
#include "ipa-reference.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. */
bitmap statics_not_written;
};
-typedef struct ipa_reference_local_vars_info_d *ipa_reference_local_vars_info_t;
-typedef struct ipa_reference_global_vars_info_d *ipa_reference_global_vars_info_t;
-typedef struct ipa_reference_optimization_summary_d *ipa_reference_optimization_summary_t;
+typedef ipa_reference_local_vars_info_d *ipa_reference_local_vars_info_t;
+typedef ipa_reference_global_vars_info_d *ipa_reference_global_vars_info_t;
+typedef ipa_reference_optimization_summary_d *
+ ipa_reference_optimization_summary_t;
struct ipa_reference_vars_info_d
{
/* 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);
+ return v == NULL ? NULL : 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;
+ return v == NULL ? NULL : v;
}
/* Return a bitmap indexed by ipa_reference_var_uid for the static variables
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;
+ }
}
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_ref_var_info_summaries->get_create (fn);
info->local.statics_read = BITMAP_ALLOC (&local_info_obstack);
info->local.statics_written = BITMAP_ALLOC (&local_info_obstack);
/* 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 =
/* 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
struct cgraph_node *callee = e->callee->function_symbol (&avail);
gcc_checking_assert (callee);
if (avail <= AVAIL_INTERPOSABLE
- || (callee->analyzed && !opt_for_fn (callee->decl, flag_ipa_reference)))
+ || (callee->analyzed && !opt_for_fn (callee->decl,
+ flag_ipa_reference)))
read_write_all_from_decl (callee, read_all, write_all);
}
}
}
+ 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)
{
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_create (node);
/* Create the complimentary sets. */
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;
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
+ || (bitmap_empty_p (info->statics_not_read)
+ && bitmap_empty_p (info->statics_not_written)))
return false;
/* See if we want to encode it.
return;
EXECUTE_IF_AND_IN_BITMAP (bits, ltrans_statics, 0, index, bi)
{
- tree decl = (tree)splay_tree_lookup (reference_vars_to_consider, index)->value;
+ tree decl = (tree)splay_tree_lookup (reference_vars_to_consider,
+ index)->value;
lto_output_var_decl_index (ob->decl_state, ob->main_stream, decl);
}
}
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++]))
{
unsigned int j, index;
struct cgraph_node *node;
- ipa_reference_optimization_summary_t info;
int v_count;
lto_symtab_encoder_t encoder;
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);
- info->statics_not_read = BITMAP_ALLOC (&optimization_summary_obstack);
- info->statics_not_written = BITMAP_ALLOC (&optimization_summary_obstack);
+
+ ipa_reference_optimization_summary_d *info
+ = ipa_ref_opt_sum_summaries->get_create (node);
+
+ info->statics_not_read = BITMAP_ALLOC
+ (&optimization_summary_obstack);
+ info->statics_not_written = BITMAP_ALLOC
+ (&optimization_summary_obstack);
if (dump_file)
fprintf (dump_file,
"\nFunction name:%s:\n static not read:",
ib, data, len);
}
else
- /* Fatal error here. We do not want to support compiling ltrans units with
- different version of compiler or different flags than the WPA unit, so
- this should never happen. */
+ /* Fatal error here. We do not want to support compiling ltrans units
+ with different version of compiler or different flags than
+ the WPA unit, so this should never happen. */
fatal_error (input_location,
"ipa reference summary is missing in ltrans unit");
}
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;
- }
}