diff mbox series

Cleanup indexable tree ref streaming

Message ID 20200531153550.GD67938@kam.mff.cuni.cz
State New
Headers show
Series Cleanup indexable tree ref streaming | expand

Commit Message

Jan Hubicka May 31, 2020, 3:35 p.m. UTC
Hi,
this patch removes some abstraction around streaming references which
makes it difficult to play with the format of actual streamed
references. They are alway spair of integers, one represents the tag
and other is index.  So I separated code computing them to common place
followed by the uhwi stores.

Boostrapped/regtested x86_64-linux, comitted.

2020-05-30  Jan Hubicka  <hubicka@ucw.cz>

gcc/

	* lto-section-out.c (lto_output_decl_index): Remove.
	(lto_output_field_decl_index): Move to lto-streamer-out.c
	(lto_output_fn_decl_index): Move to lto-streamer-out.c
	(lto_output_namespace_decl_index): Remove.
	(lto_output_var_decl_index): Remove.
	(lto_output_type_decl_index): Remove.
	(lto_output_type_ref_index): Remove.
	* lto-streamer-out.c (output_type_ref): Remove.
	(lto_get_index): New function.
	(lto_output_tree_ref): Remove.
	(lto_indexable_tree_ref): New function.
	(lto_output_var_decl_index): Move here from lto-section-out.c; simplify.
	(lto_output_fn_decl_index): Move here from lto-section-out.c; simplify.
	(stream_write_tree_ref): Update.
	(lto_output_tree): Update.
	* lto-streamer.h (lto_output_decl_index): Remove prototype.
	(lto_output_field_decl_index): Remove prototype.
	(lto_output_namespace_decl_index): Remove prototype.
	(lto_output_type_decl_index): Remove prototype.
	(lto_output_type_ref_index): Remove prototype.
	(lto_output_var_decl_index): Move.
	(lto_output_fn_decl_index): Move
diff mbox series

Patch

diff --git a/gcc/fortran/class.c b/gcc/fortran/class.c
index db395624a16..fb1a9dc3fc5 100644
--- a/gcc/fortran/class.c
+++ b/gcc/fortran/class.c
@@ -484,7 +484,8 @@  get_unique_type_string (char *string, gfc_symbol *derived)
   if (derived->attr.unlimited_polymorphic)
     strcpy (dt_name, "STAR");
   else
-    strncpy (dt_name, gfc_dt_upper_string (derived->name), sizeof (dt_name));
+    strncpy (dt_name, gfc_dt_upper_string (derived->name),
+	     sizeof (dt_name) - 1);
   if (derived->attr.unlimited_polymorphic)
     sprintf (string, "_%s", dt_name);
   else if (derived->module)
diff --git a/gcc/lto-section-out.c b/gcc/lto-section-out.c
index 0182cd6059e..b546e8a2fe0 100644
--- a/gcc/lto-section-out.c
+++ b/gcc/lto-section-out.c
@@ -147,111 +147,6 @@  lto_write_stream (struct lto_output_stream *obs)
     }
 }
 
-
-/* Lookup NAME in ENCODER.  If NAME is not found, create a new entry in
-   ENCODER for NAME with the next available index of ENCODER,  then
-   print the index to OBS.  True is returned if NAME was added to
-   ENCODER.  The resulting index is stored in THIS_INDEX.
-
-   If OBS is NULL, the only action is to add NAME to the encoder. */
-
-bool
-lto_output_decl_index (struct lto_output_stream *obs,
-		       struct lto_tree_ref_encoder *encoder,
-		       tree name, unsigned int *this_index)
-{
-  bool new_entry_p = FALSE;
-  bool existed_p;
-
-  unsigned int &index
-    = encoder->tree_hash_table->get_or_insert (name, &existed_p);
-  if (!existed_p)
-    {
-      index = encoder->trees.length ();
-      if (streamer_dump_file)
-	{
-	  print_node_brief (streamer_dump_file, "     Encoding indexable ",
-			    name, 4);
-	  fprintf (streamer_dump_file, "  as %i \n", index);
-	}
-      encoder->trees.safe_push (name);
-      new_entry_p = TRUE;
-    }
-
-  if (obs)
-    streamer_write_uhwi_stream (obs, index);
-  *this_index = index;
-  return new_entry_p;
-}
-
-/* Output a field DECL to OBS.  */
-
-void
-lto_output_field_decl_index (struct lto_out_decl_state *decl_state,
-			     struct lto_output_stream * obs, tree decl)
-{
-  unsigned int index;
-  lto_output_decl_index (obs, &decl_state->streams[LTO_DECL_STREAM_FIELD_DECL],
-			 decl, &index);
-}
-
-/* Output a function DECL to OBS.  */
-
-void
-lto_output_fn_decl_index (struct lto_out_decl_state *decl_state,
-			  struct lto_output_stream * obs, tree decl)
-{
-  unsigned int index;
-  lto_output_decl_index (obs, &decl_state->streams[LTO_DECL_STREAM_FN_DECL],
-			 decl, &index);
-}
-
-/* Output a namespace DECL to OBS.  */
-
-void
-lto_output_namespace_decl_index (struct lto_out_decl_state *decl_state,
-				 struct lto_output_stream * obs, tree decl)
-{
-  unsigned int index;
-  lto_output_decl_index (obs,
-			 &decl_state->streams[LTO_DECL_STREAM_NAMESPACE_DECL],
-			 decl, &index);
-}
-
-/* Output a static or extern var DECL to OBS.  */
-
-void
-lto_output_var_decl_index (struct lto_out_decl_state *decl_state,
-			   struct lto_output_stream * obs, tree decl)
-{
-  unsigned int index;
-  lto_output_decl_index (obs, &decl_state->streams[LTO_DECL_STREAM_VAR_DECL],
-			 decl, &index);
-}
-
-/* Output a type DECL to OBS.  */
-
-void
-lto_output_type_decl_index (struct lto_out_decl_state *decl_state,
-			    struct lto_output_stream * obs, tree decl)
-{
-  unsigned int index;
-  lto_output_decl_index (obs, &decl_state->streams[LTO_DECL_STREAM_TYPE_DECL],
-			 decl, &index);
-}
-
-/* Output a type REF to OBS.  */
-
-void
-lto_output_type_ref_index (struct lto_out_decl_state *decl_state,
-			   struct lto_output_stream *obs, tree ref)
-{
-  unsigned int index;
-  lto_output_decl_index (obs, &decl_state->streams[LTO_DECL_STREAM_TYPE],
-			 ref, &index);
-}
-
-
 /* Create the output block and return it.  */
 
 struct lto_simple_output_block *
diff --git a/gcc/lto-streamer-out.c b/gcc/lto-streamer-out.c
index 1e147a3ab8a..1910ee2a5ea 100644
--- a/gcc/lto-streamer-out.c
+++ b/gcc/lto-streamer-out.c
@@ -119,15 +119,6 @@  destroy_output_block (struct output_block *ob)
 }
 
 
-/* Look up NODE in the type table and write the index for it to OB.  */
-
-static void
-output_type_ref (struct output_block *ob, tree node)
-{
-  streamer_write_record_start (ob, LTO_type_ref);
-  lto_output_type_ref_index (ob->decl_state, ob->main_stream, node);
-}
-
 /* Wrapper around variably_modified_type_p avoiding type modification
    during WPA streaming.  */
 
@@ -224,97 +215,148 @@  lto_output_location (struct output_block *ob, struct bitpack_d *bp,
 }
 
 
+/* Lookup NAME in ENCODER.  If NAME is not found, create a new entry in
+   ENCODER for NAME with the next available index of ENCODER,  then
+   print the index to OBS.
+   Return the index.  */
+
+
+static unsigned
+lto_get_index (struct lto_tree_ref_encoder *encoder, tree t)
+{
+  bool existed_p;
+
+  unsigned int &index
+    = encoder->tree_hash_table->get_or_insert (t, &existed_p);
+  if (!existed_p)
+    {
+      index = encoder->trees.length ();
+      if (streamer_dump_file)
+	{
+	  print_node_brief (streamer_dump_file, "     Encoding indexable ",
+			    t, 4);
+	  fprintf (streamer_dump_file, "  as %i \n", index);
+	}
+      encoder->trees.safe_push (t);
+    }
+
+  return index;
+}
+
+
 /* If EXPR is an indexable tree node, output a reference to it to
    output block OB.  Otherwise, output the physical representation of
    EXPR to OB.  */
 
 static void
-lto_output_tree_ref (struct output_block *ob, tree expr)
+lto_indexable_tree_ref (struct output_block *ob, tree expr,
+			enum LTO_tags *tag, unsigned *index)
 {
   enum tree_code code;
+  enum lto_decl_stream_e_t encoder;
+
+  gcc_checking_assert (tree_is_indexable (expr));
 
   if (TYPE_P (expr))
     {
-      output_type_ref (ob, expr);
-      return;
+      *tag = LTO_type_ref;
+      encoder = LTO_DECL_STREAM_TYPE;
     }
-
-  code = TREE_CODE (expr);
-  switch (code)
+  else
     {
-    case SSA_NAME:
-      streamer_write_record_start (ob, LTO_ssa_name_ref);
-      streamer_write_uhwi (ob, SSA_NAME_VERSION (expr));
-      break;
+      code = TREE_CODE (expr);
+      switch (code)
+	{
+	case SSA_NAME:
+	  *tag = LTO_ssa_name_ref;
+	  *index = SSA_NAME_VERSION (expr);
+	  return;
+	  break;
 
-    case FIELD_DECL:
-      streamer_write_record_start (ob, LTO_field_decl_ref);
-      lto_output_field_decl_index (ob->decl_state, ob->main_stream, expr);
-      break;
+	case FIELD_DECL:
+	  *tag = LTO_field_decl_ref;
+	  encoder = LTO_DECL_STREAM_FIELD_DECL;
+	  break;
 
-    case FUNCTION_DECL:
-      streamer_write_record_start (ob, LTO_function_decl_ref);
-      lto_output_fn_decl_index (ob->decl_state, ob->main_stream, expr);
-      break;
+	case FUNCTION_DECL:
+	  *tag = LTO_function_decl_ref;
+	  encoder = LTO_DECL_STREAM_FN_DECL;
+	  break;
 
-    case VAR_DECL:
-    case DEBUG_EXPR_DECL:
-      gcc_assert (decl_function_context (expr) == NULL || TREE_STATIC (expr));
-      /* FALLTHRU */
-    case PARM_DECL:
-      streamer_write_record_start (ob, LTO_global_decl_ref);
-      lto_output_var_decl_index (ob->decl_state, ob->main_stream, expr);
-      break;
-
-    case CONST_DECL:
-      streamer_write_record_start (ob, LTO_const_decl_ref);
-      lto_output_var_decl_index (ob->decl_state, ob->main_stream, expr);
-      break;
-
-    case IMPORTED_DECL:
-      gcc_assert (decl_function_context (expr) == NULL);
-      streamer_write_record_start (ob, LTO_imported_decl_ref);
-      lto_output_var_decl_index (ob->decl_state, ob->main_stream, expr);
-      break;
-
-    case TYPE_DECL:
-      streamer_write_record_start (ob, LTO_type_decl_ref);
-      lto_output_type_decl_index (ob->decl_state, ob->main_stream, expr);
-      break;
-
-    case NAMELIST_DECL:
-      streamer_write_record_start (ob, LTO_namelist_decl_ref);
-      lto_output_var_decl_index (ob->decl_state, ob->main_stream, expr);
-      break;
+	case VAR_DECL:
+	case DEBUG_EXPR_DECL:
+	  gcc_checking_assert (decl_function_context (expr) == NULL
+			       || TREE_STATIC (expr));
+	  /* FALLTHRU */
+	case PARM_DECL:
+	  *tag = LTO_global_decl_ref;
+	  encoder = LTO_DECL_STREAM_VAR_DECL;
+	  break;
 
-    case NAMESPACE_DECL:
-      streamer_write_record_start (ob, LTO_namespace_decl_ref);
-      lto_output_namespace_decl_index (ob->decl_state, ob->main_stream, expr);
-      break;
+	case CONST_DECL:
+	  *tag = LTO_const_decl_ref;
+	  encoder = LTO_DECL_STREAM_VAR_DECL;
+	  break;
 
-    case LABEL_DECL:
-      streamer_write_record_start (ob, LTO_label_decl_ref);
-      lto_output_var_decl_index (ob->decl_state, ob->main_stream, expr);
-      break;
+	case TYPE_DECL:
+	  *tag = LTO_type_decl_ref;
+	  encoder = LTO_DECL_STREAM_TYPE_DECL;
+	  break;
 
-    case RESULT_DECL:
-      streamer_write_record_start (ob, LTO_result_decl_ref);
-      lto_output_var_decl_index (ob->decl_state, ob->main_stream, expr);
-      break;
+	case NAMESPACE_DECL:
+	  *tag = LTO_namespace_decl_ref;
+	  encoder = LTO_DECL_STREAM_NAMESPACE_DECL;
+	  break;
 
-    case TRANSLATION_UNIT_DECL:
-      streamer_write_record_start (ob, LTO_translation_unit_decl_ref);
-      lto_output_var_decl_index (ob->decl_state, ob->main_stream, expr);
-      break;
+	case LABEL_DECL:
+	  *tag = LTO_label_decl_ref;
+	  encoder = LTO_DECL_STREAM_VAR_DECL;
+	  break;
 
-    default:
-      /* No other node is indexable, so it should have been handled by
-	 lto_output_tree.  */
-      gcc_unreachable ();
+	case RESULT_DECL:
+	  *tag = LTO_result_decl_ref;
+	  encoder = LTO_DECL_STREAM_VAR_DECL;
+	  break;
+
+	case TRANSLATION_UNIT_DECL:
+	  *tag = LTO_translation_unit_decl_ref;
+	  encoder = LTO_DECL_STREAM_VAR_DECL;
+	  break;
+
+	default:
+	  /* No other node is indexable, so it should have been handled by
+	     lto_output_tree.  */
+	  gcc_unreachable ();
+	}
     }
+  *index = lto_get_index (&ob->decl_state->streams[encoder], expr);
 }
 
 
+/* Output a static or extern var DECL to OBS.  */
+
+void
+lto_output_var_decl_index (struct lto_out_decl_state *decl_state,
+			   struct lto_output_stream * obs, tree decl)
+{
+  gcc_checking_assert (TREE_CODE (decl) == VAR_DECL);
+  streamer_write_uhwi_stream
+     (obs, lto_get_index (&decl_state->streams[LTO_DECL_STREAM_VAR_DECL],
+			  decl));
+}
+
+
+/* Output a static or extern var DECL to OBS.  */
+
+void
+lto_output_fn_decl_index (struct lto_out_decl_state *decl_state,
+			  struct lto_output_stream * obs, tree decl)
+{
+  gcc_checking_assert (TREE_CODE (decl) == FUNCTION_DECL);
+  streamer_write_uhwi_stream
+     (obs, lto_get_index (&decl_state->streams[LTO_DECL_STREAM_FN_DECL], decl));
+}
+
 /* Return true if EXPR is a tree node that can be written to disk.  */
 
 static inline bool
@@ -427,8 +469,12 @@  stream_write_tree_ref (struct output_block *ob, tree t)
 	streamer_write_uhwi (ob, ix + LTO_NUM_TAGS);
       else
 	{
-	  gcc_checking_assert (tree_is_indexable (t));
-	  lto_output_tree_ref (ob, t);
+	  enum LTO_tags tag;
+	  unsigned ix;
+
+	  lto_indexable_tree_ref (ob, t, &tag, &ix);
+	  streamer_write_uhwi (ob, tag);
+	  streamer_write_uhwi (ob, ix);
 	}
       if (streamer_debugging)
 	streamer_write_uhwi (ob, TREE_CODE (t));
@@ -1754,7 +1800,12 @@  lto_output_tree (struct output_block *ob, tree expr,
 
   if (this_ref_p && tree_is_indexable (expr))
     {
-      lto_output_tree_ref (ob, expr);
+      enum LTO_tags tag;
+      unsigned ix;
+
+      lto_indexable_tree_ref (ob, expr, &tag, &ix);
+      streamer_write_record_start (ob, tag);
+      streamer_write_uhwi (ob, ix);
       return;
     }
 
diff --git a/gcc/lto-streamer.h b/gcc/lto-streamer.h
index d527d51ef36..6ab0505c3fd 100644
--- a/gcc/lto-streamer.h
+++ b/gcc/lto-streamer.h
@@ -841,21 +841,6 @@  extern void lto_end_section (void);
 extern void lto_write_data (const void *, unsigned int);
 extern void lto_write_raw_data (const void *, unsigned int);
 extern void lto_write_stream (struct lto_output_stream *);
-extern bool lto_output_decl_index (struct lto_output_stream *,
-			    struct lto_tree_ref_encoder *,
-			    tree, unsigned int *);
-extern void lto_output_field_decl_index (struct lto_out_decl_state *,
-				  struct lto_output_stream *, tree);
-extern void lto_output_fn_decl_index (struct lto_out_decl_state *,
-			       struct lto_output_stream *, tree);
-extern void lto_output_namespace_decl_index (struct lto_out_decl_state *,
-				      struct lto_output_stream *, tree);
-extern void lto_output_var_decl_index (struct lto_out_decl_state *,
-				struct lto_output_stream *, tree);
-extern void lto_output_type_decl_index (struct lto_out_decl_state *,
-				 struct lto_output_stream *, tree);
-extern void lto_output_type_ref_index (struct lto_out_decl_state *,
-				struct lto_output_stream *, tree);
 extern struct lto_simple_output_block *lto_create_simple_output_block (
 				enum lto_section_type);
 extern void lto_destroy_simple_output_block (struct lto_simple_output_block *);
@@ -923,6 +908,10 @@  extern struct output_block *create_output_block (enum lto_section_type);
 extern void destroy_output_block (struct output_block *);
 extern void lto_output_tree (struct output_block *, tree, bool, bool);
 extern void stream_write_tree_ref (struct output_block *, tree);
+extern void lto_output_var_decl_index (struct lto_out_decl_state *,
+				       struct lto_output_stream *, tree);
+extern void lto_output_fn_decl_index (struct lto_out_decl_state *,
+				      struct lto_output_stream *, tree);
 extern void lto_output_toplevel_asms (void);
 extern void produce_asm (struct output_block *ob, tree fn);
 extern void lto_output ();