Patchwork [pph] Pickle some more language-dependent fields (issue4389050)

login
register
mail settings
Submitter Diego Novillo
Date April 12, 2011, 7:56 p.m.
Message ID <20110412195620.ABB881DA1BE@topo.tor.corp.google.com>
Download mbox | patch
Permalink /patch/90859/
State New
Headers show

Comments

Diego Novillo - April 12, 2011, 7:56 p.m.
In reconstructing pph images, I found some more language-specific
fields that we were not pickling.  There's a few more that I will be
sending shortly.

Tested on x86_64.  Committed to pph.


2011-04-12  Diego Novillo  <dnovillo@google.com>

	* pph-streamer-in.c (pph_stream_unpack_value_fields): Unpack
	TYPE_LANG_FLAGS and DECL_LANG_FLAGS.
	(pph_stream_read_tree): Handle TYPE_DECL.
	* pph-streamer-out.c (pph_stream_pack_value_fields): Pack
	TYPE_LANG_FLAGS and DECL_LANG_FLAGS.
	(pph_stream_write_binding_level): Call pph_output_chain_filtered
	with a NO_BUILTINS filter for fields that have DECLs in them.
	(pph_stream_write_tree): Handle TYPE_DECL.
	(pph_output_chain_filtered): New.
	* pph-streamer.c (pph_stream_trace): Show the code of the tree
	if it is not NULL_TREE.
	* pph-streamer.h (enum chain_filter): Declare.
	(pph_output_chain_filtered): Declare.


--
This patch is available for review at http://codereview.appspot.com/4389050
Lawrence Crowl - April 13, 2011, 12:34 a.m.
LGTM

On 4/12/11, Diego Novillo <dnovillo@google.com> wrote:
>
> In reconstructing pph images, I found some more language-specific
> fields that we were not pickling.  There's a few more that I will be
> sending shortly.
>
> Tested on x86_64.  Committed to pph.
>
>
> 2011-04-12  Diego Novillo  <dnovillo@google.com>
>
> 	* pph-streamer-in.c (pph_stream_unpack_value_fields): Unpack
> 	TYPE_LANG_FLAGS and DECL_LANG_FLAGS.
> 	(pph_stream_read_tree): Handle TYPE_DECL.
> 	* pph-streamer-out.c (pph_stream_pack_value_fields): Pack
> 	TYPE_LANG_FLAGS and DECL_LANG_FLAGS.
> 	(pph_stream_write_binding_level): Call pph_output_chain_filtered
> 	with a NO_BUILTINS filter for fields that have DECLs in them.
> 	(pph_stream_write_tree): Handle TYPE_DECL.
> 	(pph_output_chain_filtered): New.
> 	* pph-streamer.c (pph_stream_trace): Show the code of the tree
> 	if it is not NULL_TREE.
> 	* pph-streamer.h (enum chain_filter): Declare.
> 	(pph_output_chain_filtered): Declare.
>
> diff --git a/gcc/cp/pph-streamer-in.c b/gcc/cp/pph-streamer-in.c
> index af7cd57..38a4561 100644
> --- a/gcc/cp/pph-streamer-in.c
> +++ b/gcc/cp/pph-streamer-in.c
> @@ -36,10 +36,30 @@ along with GCC; see the file COPYING3.  If not see
>     we are unpacking from.  EXPR is the tree to unpack.  */
>
>  void
> -pph_stream_unpack_value_fields (struct bitpack_d *bp ATTRIBUTE_UNUSED,
> -				tree expr ATTRIBUTE_UNUSED)
> +pph_stream_unpack_value_fields (struct bitpack_d *bp, tree expr)
>  {
> -  /* Do nothing for now.  */
> +  if (TYPE_P (expr))
> +    {
> +      TYPE_LANG_FLAG_0 (expr) = bp_unpack_value (bp, 1);
> +      TYPE_LANG_FLAG_1 (expr) = bp_unpack_value (bp, 1);
> +      TYPE_LANG_FLAG_2 (expr) = bp_unpack_value (bp, 1);
> +      TYPE_LANG_FLAG_3 (expr) = bp_unpack_value (bp, 1);
> +      TYPE_LANG_FLAG_4 (expr) = bp_unpack_value (bp, 1);
> +      TYPE_LANG_FLAG_5 (expr) = bp_unpack_value (bp, 1);
> +      TYPE_LANG_FLAG_6 (expr) = bp_unpack_value (bp, 1);
> +    }
> +  else if (DECL_P (expr))
> +    {
> +      DECL_LANG_FLAG_0 (expr) = bp_unpack_value (bp, 1);
> +      DECL_LANG_FLAG_1 (expr) = bp_unpack_value (bp, 1);
> +      DECL_LANG_FLAG_2 (expr) = bp_unpack_value (bp, 1);
> +      DECL_LANG_FLAG_3 (expr) = bp_unpack_value (bp, 1);
> +      DECL_LANG_FLAG_4 (expr) = bp_unpack_value (bp, 1);
> +      DECL_LANG_FLAG_5 (expr) = bp_unpack_value (bp, 1);
> +      DECL_LANG_FLAG_6 (expr) = bp_unpack_value (bp, 1);
> +      DECL_LANG_FLAG_7 (expr) = bp_unpack_value (bp, 1);
> +      DECL_LANG_FLAG_8 (expr) = bp_unpack_value (bp, 1);
> +    }
>  }
>
>
> @@ -585,6 +605,8 @@ pph_stream_read_tree (struct lto_input_block *ib
> ATTRIBUTE_UNUSED,
>  	  if (TREE_CODE (expr) == FUNCTION_DECL)
>  	    DECL_SAVED_TREE (expr) = pph_input_tree (stream);
>  	}
> +      else if (TREE_CODE (expr) == TYPE_DECL)
> +	DECL_ORIGINAL_TYPE (expr) = pph_input_tree (stream);
>      }
>    else if (TREE_CODE (expr) == STATEMENT_LIST)
>      {
> diff --git a/gcc/cp/pph-streamer-out.c b/gcc/cp/pph-streamer-out.c
> index aeba8eb..609673b 100644
> --- a/gcc/cp/pph-streamer-out.c
> +++ b/gcc/cp/pph-streamer-out.c
> @@ -42,10 +42,30 @@ static FILE *current_pph_file = NULL;
>     we are packing into.  EXPR is the tree to pack.  */
>
>  void
> -pph_stream_pack_value_fields (struct bitpack_d *bp ATTRIBUTE_UNUSED,
> -			      tree expr ATTRIBUTE_UNUSED)
> +pph_stream_pack_value_fields (struct bitpack_d *bp, tree expr)
>  {
> -  /* Do nothing for now.  */
> +  if (TYPE_P (expr))
> +    {
> +      bp_pack_value (bp, TYPE_LANG_FLAG_0 (expr), 1);
> +      bp_pack_value (bp, TYPE_LANG_FLAG_1 (expr), 1);
> +      bp_pack_value (bp, TYPE_LANG_FLAG_2 (expr), 1);
> +      bp_pack_value (bp, TYPE_LANG_FLAG_3 (expr), 1);
> +      bp_pack_value (bp, TYPE_LANG_FLAG_4 (expr), 1);
> +      bp_pack_value (bp, TYPE_LANG_FLAG_5 (expr), 1);
> +      bp_pack_value (bp, TYPE_LANG_FLAG_6 (expr), 1);
> +    }
> +  else if (DECL_P (expr))
> +    {
> +      bp_pack_value (bp, DECL_LANG_FLAG_0 (expr), 1);
> +      bp_pack_value (bp, DECL_LANG_FLAG_1 (expr), 1);
> +      bp_pack_value (bp, DECL_LANG_FLAG_2 (expr), 1);
> +      bp_pack_value (bp, DECL_LANG_FLAG_3 (expr), 1);
> +      bp_pack_value (bp, DECL_LANG_FLAG_4 (expr), 1);
> +      bp_pack_value (bp, DECL_LANG_FLAG_5 (expr), 1);
> +      bp_pack_value (bp, DECL_LANG_FLAG_6 (expr), 1);
> +      bp_pack_value (bp, DECL_LANG_FLAG_7 (expr), 1);
> +      bp_pack_value (bp, DECL_LANG_FLAG_8 (expr), 1);
> +    }
>  }
>
>
> @@ -344,14 +364,14 @@ pph_stream_write_binding_level (pph_stream *stream,
> struct cp_binding_level *bl,
>    if (!pph_start_record (stream, bl))
>      return;
>
> -  pph_output_chain (stream, bl->names, ref_p);
> +  pph_output_chain_filtered (stream, bl->names, ref_p, NO_BUILTINS);
>    pph_output_uint (stream, bl->names_size);
> -  pph_output_chain (stream, bl->namespaces, ref_p);
> +  pph_output_chain_filtered (stream, bl->namespaces, ref_p, NO_BUILTINS);
>
>    pph_stream_write_tree_vec (stream, bl->static_decls, ref_p);
>
> -  pph_output_chain (stream, bl->usings, ref_p);
> -  pph_output_chain (stream, bl->using_directives, ref_p);
> +  pph_output_chain_filtered (stream, bl->usings, ref_p, NO_BUILTINS);
> +  pph_output_chain_filtered (stream, bl->using_directives, ref_p,
> NO_BUILTINS);
>
>    pph_output_uint (stream, VEC_length (cp_class_binding,
> bl->class_shadowed));
>    for (i = 0; VEC_iterate (cp_class_binding, bl->class_shadowed, i, cs);
> i++)
> @@ -594,6 +614,8 @@ pph_stream_write_tree (struct output_block *ob, tree
> expr, bool ref_p)
>  	  if (TREE_CODE (expr) == FUNCTION_DECL)
>  	    pph_output_tree_aux (stream, DECL_SAVED_TREE (expr), ref_p);
>  	}
> +      else if (TREE_CODE (expr) == TYPE_DECL)
> +	pph_output_tree (stream, DECL_ORIGINAL_TYPE (expr), ref_p);
>      }
>    else if (TREE_CODE (expr) == STATEMENT_LIST)
>      {
> @@ -611,3 +633,52 @@ pph_stream_write_tree (struct output_block *ob, tree
> expr, bool ref_p)
>  	pph_output_tree_aux (stream, tsi_stmt (i), ref_p);
>      }
>  }
> +
> +
> +/* Output a chain of nodes to STREAM starting with FIRST.  Skip any
> +   nodes that do not match FILTER.  REF_P is true if nodes in the chain
> +   should be emitted as references.  */
> +
> +void
> +pph_output_chain_filtered (pph_stream *stream, tree first, bool ref_p,
> +			   enum chain_filter filter)
> +{
> +  unsigned count;
> +  tree t;
> +
> +  /* Special case.  If the caller wants no filtering, it is much
> +     faster to just call pph_output_chain directly.  */
> +  if (filter == NONE)
> +    {
> +      pph_output_chain (stream, first, ref_p);
> +      return;
> +    }
> +
> +  /* Count all the nodes that match the filter.  */
> +  for (t = first, count = 0; t; t = TREE_CHAIN (t))
> +    {
> +      if (filter == NO_BUILTINS && DECL_P (t) && DECL_IS_BUILTIN (t))
> +	continue;
> +      count++;
> +    }
> +  pph_output_uint (stream, count);
> +
> +  /* Output all the nodes that match the filter.  */
> +  for (t = first; t; t = TREE_CHAIN (t))
> +    {
> +      tree saved_chain;
> +
> +      /* Apply filters to T.  */
> +      if (filter == NO_BUILTINS && DECL_P (t) && DECL_IS_BUILTIN (t))
> +	continue;
> +
> +      /* Clear TREE_CHAIN to avoid blindly recursing into the rest
> +	 of the list.  */
> +      saved_chain = TREE_CHAIN (t);
> +      TREE_CHAIN (t) = NULL_TREE;
> +
> +      pph_output_tree (stream, t, ref_p);
> +
> +      TREE_CHAIN (t) = saved_chain;
> +    }
> +}
> diff --git a/gcc/cp/pph-streamer.c b/gcc/cp/pph-streamer.c
> index e65a792..91e01a4 100644
> --- a/gcc/cp/pph-streamer.c
> +++ b/gcc/cp/pph-streamer.c
> @@ -146,8 +146,14 @@ pph_stream_trace (pph_stream *stream, const void *data,
> unsigned int nbytes,
>      case PPH_TRACE_TREE:
>        {
>  	const_tree t = (const_tree) data;
> -	print_generic_expr (pph_logfile, CONST_CAST (union tree_node *, t),
> -			    TDF_SLIM);
> +	if (t)
> +	  {
> +	    print_generic_expr (pph_logfile, CONST_CAST (union tree_node *, t),
> +				0);
> +	    fprintf (pph_logfile, ", code=%s", tree_code_name[TREE_CODE (t)]);
> +	  }
> +	else
> +	  fprintf (pph_logfile, "NULL_TREE");
>        }
>        break;
>
> diff --git a/gcc/cp/pph-streamer.h b/gcc/cp/pph-streamer.h
> index 8731eb8..329e507 100644
> --- a/gcc/cp/pph-streamer.h
> +++ b/gcc/cp/pph-streamer.h
> @@ -87,6 +87,9 @@ typedef struct pph_stream {
>    unsigned int write_p : 1;
>  } pph_stream;
>
> +/* Filter values for pph_output_chain_filtered.  */
> +enum chain_filter { NONE, NO_BUILTINS };
> +
>  /* In pph-streamer.c.  */
>  pph_stream *pph_stream_open (const char *, const char *);
>  void pph_stream_close (pph_stream *);
> @@ -104,6 +107,7 @@ void pph_stream_init_write (pph_stream *);
>  void pph_stream_write_tree (struct output_block *, tree, bool ref_p);
>  void pph_stream_pack_value_fields (struct bitpack_d *, tree);
>  void pph_stream_output_tree_header (struct output_block *, tree);
> +void pph_output_chain_filtered (pph_stream *, tree, bool, enum
> chain_filter);
>
>  /* In pph-streamer-in.c.  */
>  void pph_stream_init_read (pph_stream *);
>
> --
> This patch is available for review at http://codereview.appspot.com/4389050
>

Patch

diff --git a/gcc/cp/pph-streamer-in.c b/gcc/cp/pph-streamer-in.c
index af7cd57..38a4561 100644
--- a/gcc/cp/pph-streamer-in.c
+++ b/gcc/cp/pph-streamer-in.c
@@ -36,10 +36,30 @@  along with GCC; see the file COPYING3.  If not see
    we are unpacking from.  EXPR is the tree to unpack.  */
 
 void
-pph_stream_unpack_value_fields (struct bitpack_d *bp ATTRIBUTE_UNUSED,
-				tree expr ATTRIBUTE_UNUSED)
+pph_stream_unpack_value_fields (struct bitpack_d *bp, tree expr)
 {
-  /* Do nothing for now.  */
+  if (TYPE_P (expr))
+    {
+      TYPE_LANG_FLAG_0 (expr) = bp_unpack_value (bp, 1);
+      TYPE_LANG_FLAG_1 (expr) = bp_unpack_value (bp, 1);
+      TYPE_LANG_FLAG_2 (expr) = bp_unpack_value (bp, 1);
+      TYPE_LANG_FLAG_3 (expr) = bp_unpack_value (bp, 1);
+      TYPE_LANG_FLAG_4 (expr) = bp_unpack_value (bp, 1);
+      TYPE_LANG_FLAG_5 (expr) = bp_unpack_value (bp, 1);
+      TYPE_LANG_FLAG_6 (expr) = bp_unpack_value (bp, 1);
+    }
+  else if (DECL_P (expr))
+    {
+      DECL_LANG_FLAG_0 (expr) = bp_unpack_value (bp, 1);
+      DECL_LANG_FLAG_1 (expr) = bp_unpack_value (bp, 1);
+      DECL_LANG_FLAG_2 (expr) = bp_unpack_value (bp, 1);
+      DECL_LANG_FLAG_3 (expr) = bp_unpack_value (bp, 1);
+      DECL_LANG_FLAG_4 (expr) = bp_unpack_value (bp, 1);
+      DECL_LANG_FLAG_5 (expr) = bp_unpack_value (bp, 1);
+      DECL_LANG_FLAG_6 (expr) = bp_unpack_value (bp, 1);
+      DECL_LANG_FLAG_7 (expr) = bp_unpack_value (bp, 1);
+      DECL_LANG_FLAG_8 (expr) = bp_unpack_value (bp, 1);
+    }
 }
 
 
@@ -585,6 +605,8 @@  pph_stream_read_tree (struct lto_input_block *ib ATTRIBUTE_UNUSED,
 	  if (TREE_CODE (expr) == FUNCTION_DECL)
 	    DECL_SAVED_TREE (expr) = pph_input_tree (stream);
 	}
+      else if (TREE_CODE (expr) == TYPE_DECL)
+	DECL_ORIGINAL_TYPE (expr) = pph_input_tree (stream);
     }
   else if (TREE_CODE (expr) == STATEMENT_LIST)
     {
diff --git a/gcc/cp/pph-streamer-out.c b/gcc/cp/pph-streamer-out.c
index aeba8eb..609673b 100644
--- a/gcc/cp/pph-streamer-out.c
+++ b/gcc/cp/pph-streamer-out.c
@@ -42,10 +42,30 @@  static FILE *current_pph_file = NULL;
    we are packing into.  EXPR is the tree to pack.  */
 
 void
-pph_stream_pack_value_fields (struct bitpack_d *bp ATTRIBUTE_UNUSED,
-			      tree expr ATTRIBUTE_UNUSED)
+pph_stream_pack_value_fields (struct bitpack_d *bp, tree expr)
 {
-  /* Do nothing for now.  */
+  if (TYPE_P (expr))
+    {
+      bp_pack_value (bp, TYPE_LANG_FLAG_0 (expr), 1);
+      bp_pack_value (bp, TYPE_LANG_FLAG_1 (expr), 1);
+      bp_pack_value (bp, TYPE_LANG_FLAG_2 (expr), 1);
+      bp_pack_value (bp, TYPE_LANG_FLAG_3 (expr), 1);
+      bp_pack_value (bp, TYPE_LANG_FLAG_4 (expr), 1);
+      bp_pack_value (bp, TYPE_LANG_FLAG_5 (expr), 1);
+      bp_pack_value (bp, TYPE_LANG_FLAG_6 (expr), 1);
+    }
+  else if (DECL_P (expr))
+    {
+      bp_pack_value (bp, DECL_LANG_FLAG_0 (expr), 1);
+      bp_pack_value (bp, DECL_LANG_FLAG_1 (expr), 1);
+      bp_pack_value (bp, DECL_LANG_FLAG_2 (expr), 1);
+      bp_pack_value (bp, DECL_LANG_FLAG_3 (expr), 1);
+      bp_pack_value (bp, DECL_LANG_FLAG_4 (expr), 1);
+      bp_pack_value (bp, DECL_LANG_FLAG_5 (expr), 1);
+      bp_pack_value (bp, DECL_LANG_FLAG_6 (expr), 1);
+      bp_pack_value (bp, DECL_LANG_FLAG_7 (expr), 1);
+      bp_pack_value (bp, DECL_LANG_FLAG_8 (expr), 1);
+    }
 }
 
 
@@ -344,14 +364,14 @@  pph_stream_write_binding_level (pph_stream *stream, struct cp_binding_level *bl,
   if (!pph_start_record (stream, bl))
     return;
 
-  pph_output_chain (stream, bl->names, ref_p);
+  pph_output_chain_filtered (stream, bl->names, ref_p, NO_BUILTINS);
   pph_output_uint (stream, bl->names_size);
-  pph_output_chain (stream, bl->namespaces, ref_p);
+  pph_output_chain_filtered (stream, bl->namespaces, ref_p, NO_BUILTINS);
 
   pph_stream_write_tree_vec (stream, bl->static_decls, ref_p);
 
-  pph_output_chain (stream, bl->usings, ref_p);
-  pph_output_chain (stream, bl->using_directives, ref_p);
+  pph_output_chain_filtered (stream, bl->usings, ref_p, NO_BUILTINS);
+  pph_output_chain_filtered (stream, bl->using_directives, ref_p, NO_BUILTINS);
 
   pph_output_uint (stream, VEC_length (cp_class_binding, bl->class_shadowed));
   for (i = 0; VEC_iterate (cp_class_binding, bl->class_shadowed, i, cs); i++)
@@ -594,6 +614,8 @@  pph_stream_write_tree (struct output_block *ob, tree expr, bool ref_p)
 	  if (TREE_CODE (expr) == FUNCTION_DECL)
 	    pph_output_tree_aux (stream, DECL_SAVED_TREE (expr), ref_p);
 	}
+      else if (TREE_CODE (expr) == TYPE_DECL)
+	pph_output_tree (stream, DECL_ORIGINAL_TYPE (expr), ref_p);
     }
   else if (TREE_CODE (expr) == STATEMENT_LIST)
     {
@@ -611,3 +633,52 @@  pph_stream_write_tree (struct output_block *ob, tree expr, bool ref_p)
 	pph_output_tree_aux (stream, tsi_stmt (i), ref_p);
     }
 }
+
+
+/* Output a chain of nodes to STREAM starting with FIRST.  Skip any
+   nodes that do not match FILTER.  REF_P is true if nodes in the chain
+   should be emitted as references.  */
+
+void
+pph_output_chain_filtered (pph_stream *stream, tree first, bool ref_p,
+			   enum chain_filter filter)
+{
+  unsigned count;
+  tree t;
+
+  /* Special case.  If the caller wants no filtering, it is much
+     faster to just call pph_output_chain directly.  */
+  if (filter == NONE)
+    {
+      pph_output_chain (stream, first, ref_p);
+      return;
+    }
+
+  /* Count all the nodes that match the filter.  */
+  for (t = first, count = 0; t; t = TREE_CHAIN (t))
+    {
+      if (filter == NO_BUILTINS && DECL_P (t) && DECL_IS_BUILTIN (t))
+	continue;
+      count++;
+    }
+  pph_output_uint (stream, count);
+
+  /* Output all the nodes that match the filter.  */
+  for (t = first; t; t = TREE_CHAIN (t))
+    {
+      tree saved_chain;
+
+      /* Apply filters to T.  */
+      if (filter == NO_BUILTINS && DECL_P (t) && DECL_IS_BUILTIN (t))
+	continue;
+
+      /* Clear TREE_CHAIN to avoid blindly recursing into the rest
+	 of the list.  */
+      saved_chain = TREE_CHAIN (t);
+      TREE_CHAIN (t) = NULL_TREE;
+
+      pph_output_tree (stream, t, ref_p);
+
+      TREE_CHAIN (t) = saved_chain;
+    }
+}
diff --git a/gcc/cp/pph-streamer.c b/gcc/cp/pph-streamer.c
index e65a792..91e01a4 100644
--- a/gcc/cp/pph-streamer.c
+++ b/gcc/cp/pph-streamer.c
@@ -146,8 +146,14 @@  pph_stream_trace (pph_stream *stream, const void *data, unsigned int nbytes,
     case PPH_TRACE_TREE:
       {
 	const_tree t = (const_tree) data;
-	print_generic_expr (pph_logfile, CONST_CAST (union tree_node *, t),
-			    TDF_SLIM);
+	if (t)
+	  {
+	    print_generic_expr (pph_logfile, CONST_CAST (union tree_node *, t),
+				0);
+	    fprintf (pph_logfile, ", code=%s", tree_code_name[TREE_CODE (t)]);
+	  }
+	else
+	  fprintf (pph_logfile, "NULL_TREE");
       }
       break;
 
diff --git a/gcc/cp/pph-streamer.h b/gcc/cp/pph-streamer.h
index 8731eb8..329e507 100644
--- a/gcc/cp/pph-streamer.h
+++ b/gcc/cp/pph-streamer.h
@@ -87,6 +87,9 @@  typedef struct pph_stream {
   unsigned int write_p : 1;
 } pph_stream;
 
+/* Filter values for pph_output_chain_filtered.  */
+enum chain_filter { NONE, NO_BUILTINS };
+
 /* In pph-streamer.c.  */
 pph_stream *pph_stream_open (const char *, const char *);
 void pph_stream_close (pph_stream *);
@@ -104,6 +107,7 @@  void pph_stream_init_write (pph_stream *);
 void pph_stream_write_tree (struct output_block *, tree, bool ref_p);
 void pph_stream_pack_value_fields (struct bitpack_d *, tree);
 void pph_stream_output_tree_header (struct output_block *, tree);
+void pph_output_chain_filtered (pph_stream *, tree, bool, enum chain_filter);
 
 /* In pph-streamer-in.c.  */
 void pph_stream_init_read (pph_stream *);