Use symtab_summary in ipa-reference.c.
authorMartin Liska <mliska@suse.cz>
Fri, 8 Jun 2018 12:14:57 +0000 (14:14 +0200)
committerMartin Liska <marxin@gcc.gnu.org>
Fri, 8 Jun 2018 12:14:57 +0000 (12:14 +0000)
2018-06-08  Martin Liska  <mliska@suse.cz>

* ipa-reference.c (remove_node_data): Remove.
(duplicate_node_data): Likewise.
(class ipa_ref_var_info_summary_t): New class.
(class ipa_ref_opt_summary_t): Likewise.
(get_reference_vars_info): Use ipa_ref_var_info_summaries.
(get_reference_optimization_summary): Use
ipa_ref_opt_sum_summaries.
(set_reference_vars_info): Remove.
(set_reference_optimization_summary): Likewise.
(ipa_init): Create summaries.
(init_function_info): Use function summary.
(ipa_ref_opt_summary_t::duplicate): New function.
(ipa_ref_opt_summary_t::remove): New function.
(get_read_write_all_from_node): Fix GNU coding style.
(propagate): Use function summary.
(write_node_summary_p): Fix GNU coding style.
(stream_out_bitmap): Likewise.
(ipa_reference_read_optimization_summary): Use function summary.
(ipa_reference_c_finalize): Do not release hooks.

From-SVN: r261312

gcc/ChangeLog
gcc/ipa-reference.c

index d44a78d06b684f599b38ed640ea13198e2d4611d..5d10daed4050595c02e165daf5a776faf2b3a6fc 100644 (file)
@@ -1,3 +1,25 @@
+2018-06-08  Martin Liska  <mliska@suse.cz>
+
+       * ipa-reference.c (remove_node_data): Remove.
+       (duplicate_node_data): Likewise.
+       (class ipa_ref_var_info_summary_t): New class.
+       (class ipa_ref_opt_summary_t): Likewise.
+       (get_reference_vars_info): Use ipa_ref_var_info_summaries.
+       (get_reference_optimization_summary): Use
+       ipa_ref_opt_sum_summaries.
+       (set_reference_vars_info): Remove.
+       (set_reference_optimization_summary): Likewise.
+       (ipa_init): Create summaries.
+       (init_function_info): Use function summary.
+       (ipa_ref_opt_summary_t::duplicate): New function.
+       (ipa_ref_opt_summary_t::remove): New function.
+       (get_read_write_all_from_node): Fix GNU coding style.
+       (propagate): Use function summary.
+       (write_node_summary_p): Fix GNU coding style.
+       (stream_out_bitmap): Likewise.
+       (ipa_reference_read_optimization_summary): Use function summary.
+       (ipa_reference_c_finalize): Do not release hooks.
+
 2018-06-08  Martin Liska  <mliska@suse.cz>
 
        * ipa-fnsummary.c (dump_ipa_call_summary): Use ::get method.
index 6490c03f8d059b8e2c0b2aa5c5c3580e5effa5de..9a9e94c3414637d4c4a8babbde10e5d8b987cc0c 100644 (file)
@@ -49,12 +49,7 @@ along with GCC; see the file COPYING3.  If not see
 #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.  */
@@ -84,9 +79,10 @@ struct ipa_reference_optimization_summary_d
   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
 {
@@ -114,57 +110,55 @@ 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);
+  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
@@ -430,10 +424,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;
+    }
 }
 
 
@@ -443,10 +441,7 @@ 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_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);
@@ -510,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 =
@@ -530,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
@@ -671,7 +654,8 @@ get_read_write_all_from_node (struct cgraph_node *node,
       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);
     }
 
@@ -849,12 +833,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)
@@ -863,8 +849,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_create (node);
 
          /* Create the complimentary sets.  */
 
@@ -892,14 +878,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;
@@ -919,8 +911,9 @@ 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
+      || (bitmap_empty_p (info->statics_not_read)
+         && bitmap_empty_p (info->statics_not_written)))
     return false;
 
   /* See if we want to encode it.
@@ -970,7 +963,8 @@ stream_out_bitmap (struct lto_simple_output_block *ob,
     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);
     }
 }
@@ -1060,10 +1054,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++]))
@@ -1099,7 +1092,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;
 
@@ -1107,10 +1099,14 @@ 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);
-             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:",
@@ -1167,9 +1163,9 @@ ipa_reference_read_optimization_summary (void)
                                          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");
     }
@@ -1239,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;
-    }
 }