This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[lto] patch committed to fix TREE_LISTS.


This patch fixes several problem with TREE_LISTs.  We now handle
recursive lists properly as well as handling the TREE_PURPOSE field.

2007-11-01  Kenneth Zadeck <zadeck@naturalbridge.com>

    * lto-function-out.c (output_tree_list): Removed function.
    (output_expr_operand): Added case for TREE_LIST, and
    IDENTIFER_NODE and changed ASM_EXPRs to recursively call
    output_expr_operand.
    (output_local_vars): Changed some calls from output_uleb128 to
    output_zero and changed calls to output_tree_list to
    output_expr_operand.
    (output_ssa_names): Changed some calls from output_uleb128 to
    output_zero.
    (lto_static_init): Initialized IDENTIFIER_NODE and TREE_LIST
    cases.
    * lto-tree-tags.def: Ditto.
    * lto-tags.h: Ditto.
   
   
2007-11-01  Kenneth Zadeck <zadeck@naturalbridge.com>

    * lto-read.c (input_tree_list): Removed.
    (input_tree_flags): Added parameter to force flags no matter what
    tree code.
    (input_expr_operand): Added parameter to input_tree_flags.
    Added case for IDENTIFIER_NODE and TREE_LIST.  Changed ASM to call
    input_expr_operand rather than input_tree_lists.
    (input_local_var): Use input_expr_operand to read attributes
    rather then input_tree_list.
    (input_phi, input_ssa_names): Added parameter to input_tree_flags.

Index: lto-function-out.c
===================================================================
--- lto-function-out.c	(revision 129827)
+++ lto-function-out.c	(working copy)
@@ -1021,30 +1021,6 @@ output_type_list (struct output_block *o
 }
 
 
-/* Output a LIST of TAG.  Note that the list may be a NULL_TREE.  */
-
-static void
-output_tree_list (struct output_block *ob, tree list)
-{
-  tree tl;
-  int count = 0;
-  if (list)
-    {
-      gcc_assert (TREE_CODE (list) == TREE_LIST);
-      for (tl = list; tl; tl = TREE_CHAIN (tl))
-	if (TREE_VALUE (tl) != NULL_TREE)
-	  count++;
-
-      output_uleb128 (ob, count);
-      for (tl = list; tl; tl = TREE_CHAIN (tl))
-	if (TREE_VALUE (tl) != NULL_TREE)
-	  output_expr_operand (ob, TREE_VALUE (tl));
-    }
-  else
-    output_zero (ob);
-}
-
-
 /* Output an eh_cleanup region with REGION_NUMBER.  HAS_INNER is true if
    there are children of this node and HAS_PEER is true if there are
    siblings of this node.  MAY_CONTAIN_THROW and PREV_TRY are the
@@ -1275,6 +1251,16 @@ output_expr_operand (struct output_block
       }
       break;
 
+    case IDENTIFIER_NODE:
+      {
+	output_record_start (ob, expr, expr, LTO_identifier_node);
+	output_string (ob, ob->main_stream, 
+		       IDENTIFIER_POINTER (expr),
+		       IDENTIFIER_LENGTH (expr));
+      }
+      break;
+      
+
     case VECTOR_CST:
       {
 	tree t = TREE_VECTOR_CST_ELTS (expr);
@@ -1497,10 +1483,20 @@ output_expr_operand (struct output_block
 	output_string (ob, ob->main_stream, 
 		       TREE_STRING_POINTER (string_cst),
 		       TREE_STRING_LENGTH (string_cst));
-
-	output_tree_list (ob, ASM_INPUTS (expr));
-	output_tree_list (ob, ASM_OUTPUTS (expr));
-	output_tree_list (ob, ASM_CLOBBERS (expr));
+	if (ASM_INPUTS (expr))
+	  output_expr_operand (ob, ASM_INPUTS (expr));
+	else 
+	  output_zero (ob);
+
+	if (ASM_OUTPUTS (expr))
+	  output_expr_operand (ob, ASM_OUTPUTS (expr));
+	else 
+	  output_zero (ob);
+
+	if (ASM_CLOBBERS (expr))
+	  output_expr_operand (ob, ASM_CLOBBERS (expr));
+	else 
+	  output_zero (ob);
       }
       break;
 
@@ -1557,6 +1553,32 @@ output_expr_operand (struct output_block
       }
       break;
 
+    case TREE_LIST:
+      {
+	tree tl;
+	int count = 0;
+
+	output_record_start (ob, expr, NULL, tag);
+	for (tl = expr; tl; tl = TREE_CHAIN (tl))
+	  count++;
+
+	gcc_assert (count);
+	output_uleb128 (ob, count);
+	for (tl = expr; tl; tl = TREE_CHAIN (tl))
+	  {
+	    if (TREE_VALUE (tl) != NULL_TREE)
+	      output_expr_operand (ob, TREE_VALUE (tl));
+	    else
+	      output_zero (ob);
+	    
+	    if (TREE_PURPOSE (tl))
+	      output_expr_operand (ob, TREE_PURPOSE (tl));
+	    else
+	      output_zero (ob);
+	  }
+      }
+      break;
+
       /* This is the default case. All of the cases that can be done
 	 completely mechanically are done here.  */
       {
@@ -1574,6 +1596,7 @@ output_expr_operand (struct output_block
 	  output_expr_operand (ob, TREE_OPERAND (expr, i));
 	break;
       }
+
       /* This is the error case, these are type codes that will either
 	 never happen or that we have not gotten around to dealing
 	 with are here.  */
@@ -1667,7 +1690,7 @@ output_local_vars (struct output_block *
 			 IDENTIFIER_LENGTH (name));
 	}
       else
-	output_uleb128 (ob, 0);
+	output_zero (ob);
 
       output_type_ref (ob, TREE_TYPE (decl));
 
@@ -1681,13 +1704,13 @@ output_local_vars (struct output_block *
       if (TREE_CHAIN (decl))
 	output_expr_operand (ob, TREE_CHAIN (decl));
       else
-	output_uleb128 (ob, 0);
+	output_zero (ob);
 
       LTO_DEBUG_TOKEN ("context");
       if (DECL_CONTEXT (decl))
 	output_expr_operand (ob, DECL_CONTEXT (decl));
       else 
-	output_uleb128 (ob, 0);
+	output_zero (ob);
 
       LTO_DEBUG_TOKEN ("align");
       output_uleb128 (ob, DECL_ALIGN (decl));
@@ -1698,7 +1721,7 @@ output_local_vars (struct output_block *
       if (DECL_ATTRIBUTES (decl)!= NULL_TREE)
 	{
 	  LTO_DEBUG_TOKEN ("attributes");
-	  output_tree_list (ob, DECL_ATTRIBUTES (decl));
+	  output_expr_operand (ob, DECL_ATTRIBUTES (decl));
 	}
       if (DECL_SIZE_UNIT (decl) != NULL_TREE)
 	output_expr_operand (ob, DECL_SIZE_UNIT (decl));
@@ -1768,7 +1791,6 @@ output_ssa_names (struct output_block *o
   unsigned int len = VEC_length (tree, SSANAMES (fn));
 
   ob->main_stream = ob->ssa_names_stream;
-
   output_uleb128 (ob, len);
 
   for (i = 1; i < len; i++)
@@ -1784,7 +1806,7 @@ output_ssa_names (struct output_block *o
       output_tree_flags (ob, 0, ptr, false);
     }
 
-  output_uleb128 (ob, 0);
+  output_zero (ob);
   ob->main_stream = tmp_stream;
 }
 
@@ -2074,9 +2096,11 @@ lto_static_init (void)
   sbitmap_ones (lto_flags_needed_for);
   RESET_BIT (lto_flags_needed_for, FIELD_DECL);
   RESET_BIT (lto_flags_needed_for, FUNCTION_DECL);
+  RESET_BIT (lto_flags_needed_for, IDENTIFIER_NODE);
   RESET_BIT (lto_flags_needed_for, PARM_DECL);
   RESET_BIT (lto_flags_needed_for, SSA_NAME);
   RESET_BIT (lto_flags_needed_for, VAR_DECL);
+  RESET_BIT (lto_flags_needed_for, TREE_LIST);
   RESET_BIT (lto_flags_needed_for, TYPE_DECL);
 
   lto_types_needed_for = sbitmap_alloc (NUM_TREE_CODES);
@@ -2089,6 +2113,7 @@ lto_static_init (void)
   RESET_BIT (lto_types_needed_for, FIELD_DECL);
   RESET_BIT (lto_types_needed_for, FUNCTION_DECL);
   RESET_BIT (lto_types_needed_for, GIMPLE_MODIFY_STMT);
+  RESET_BIT (lto_types_needed_for, IDENTIFIER_NODE);
   RESET_BIT (lto_types_needed_for, LABEL_DECL);
   RESET_BIT (lto_types_needed_for, LABEL_EXPR);
   RESET_BIT (lto_types_needed_for, MODIFY_EXPR);
@@ -2098,6 +2123,7 @@ lto_static_init (void)
   RESET_BIT (lto_types_needed_for, SSA_NAME);
   RESET_BIT (lto_types_needed_for, SWITCH_EXPR);
   RESET_BIT (lto_types_needed_for, VAR_DECL);
+  RESET_BIT (lto_types_needed_for, TREE_LIST);
   RESET_BIT (lto_types_needed_for, TYPE_DECL);
 #else
   /* These forms will need types, even when the type system is fixed.  */
Index: lto-tree-tags.def
===================================================================
--- lto-tree-tags.def	(revision 129827)
+++ lto-tree-tags.def	(working copy)
@@ -73,6 +73,7 @@
   MAP_EXPR_TAG(FIXED_CST, LTO_fixed_cst)
   MAP_EXPR_TAG(FUNCTION_DECL, LTO_function_decl)
   MAP_EXPR_TAG(GIMPLE_MODIFY_STMT, LTO_gimple_modify_stmt)
+  MAP_EXPR_TAG(IDENTIFIER_NODE, LTO_identifier_node)
   MAP_EXPR_TAG(INTEGER_CST, LTO_integer_cst)
   MAP_EXPR_TAG(LABEL_DECL, LTO_label_decl)
   MAP_EXPR_TAG(LABEL_EXPR, LTO_label_expr)
@@ -85,6 +86,7 @@
   MAP_EXPR_TAG(SSA_NAME, LTO_ssa_name)
   MAP_EXPR_TAG(STRING_CST, LTO_string_cst)
   MAP_EXPR_TAG(SWITCH_EXPR, LTO_switch_expr)
+  MAP_EXPR_TAG(TREE_LIST, LTO_tree_list)
   MAP_EXPR_TAG(TYPE_DECL, LTO_type_decl)
 #endif /* TREE_SINGLE_MECHANICAL_FALSE */
 
@@ -225,6 +227,7 @@
   SET_NAME (LTO_goto_expr, "goto_expr")
   SET_NAME (LTO_gt_expr, "gt_expr")
   SET_NAME (LTO_imagpart_expr, "imagpart_expr")
+  SET_NAME (LTO_identifier_node, "identifier_node")
   SET_NAME (LTO_indirect_ref, "indirect_ref")
   SET_NAME (LTO_integer_cst, "integer_cst")
   SET_NAME (LTO_label_decl, "label_decl")
@@ -270,6 +273,7 @@
   SET_NAME (LTO_ssa_name, "ssa_name")
   SET_NAME (LTO_string_cst, "string_cst")
   SET_NAME (LTO_switch_expr, "switch_expr")
+  SET_NAME (LTO_tree_list, "tree_list")
   SET_NAME (LTO_trunc_div_expr, "trunc_div_expr")
   SET_NAME (LTO_trunc_mod_expr, "trunc_mod_expr")
   SET_NAME (LTO_truth_and_expr, "truth_and_expr")
Index: lto-tags.h
===================================================================
--- lto-tags.h	(revision 129827)
+++ lto-tags.h	(working copy)
@@ -264,11 +264,8 @@ struct lto_header
 #define REDUNDANT_TYPE_SYSTEM 1
 
 enum LTO_tags {
-/* This allows flags to be sent for a tag even if the tag do not indicate one is needed.  */
-  LTO_flags_needed = 1,
-
 /* The 1 variant indicates that the basic block is not empty.  */
-  LTO_bb0,
+  LTO_bb0 = 1,
   LTO_bb1,
 
 /* Variant 1 is used to set region to no zero value.  */
@@ -346,6 +343,7 @@ enum LTO_tags {
   LTO_goto_expr,
   LTO_gt_expr,
   LTO_imagpart_expr,
+  LTO_identifier_node,
   LTO_indirect_ref,
   LTO_integer_cst,
   LTO_label_decl,
@@ -399,6 +397,7 @@ enum LTO_tags {
 
 /* Cases are terminated a zero.  */
   LTO_switch_expr,
+  LTO_tree_list,
   LTO_trunc_div_expr,
   LTO_trunc_mod_expr,
   LTO_truth_and_expr,
Index: lto/lto-read.c
===================================================================
--- lto/lto-read.c	(revision 129827)
+++ lto/lto-read.c	(working copy)
@@ -325,38 +325,6 @@ input_record_start (struct input_block *
 } 
 
 
-/* Build a tree list stopping when the tag is 0.  */
-
-static tree 
-input_tree_list (struct input_block *ib, struct data_in *data_in, struct function *fn)
-{
-  unsigned int count = input_uleb128 (ib);
-
-  tree first = NULL_TREE;
-
-  if (count)
-    {
-      tree next;
-      enum LTO_tags tag = input_record_start (ib);
-
-      /* Peel out the first iteration so we return the correct thing.  */
-      first = build_tree_list (NULL_TREE, input_expr_operand (ib, data_in, fn, tag));
-      next = first;
-      count--;
-
-      while (count--)
-	{
-	  tag = input_record_start (ib);
-	  TREE_CHAIN (next) 
-	    = build_tree_list (NULL_TREE, input_expr_operand (ib, data_in, fn, tag));
-	  next = TREE_CHAIN (next);
-	}
-    }
-
-  return first;
-}
-
-
 /* Get the label referenced by the next token in IB.  */
 
 static tree 
@@ -389,11 +357,11 @@ get_type_ref (struct data_in *data_in, s
 /* Read the tree flags for CODE from IB.  */
 
 static unsigned HOST_WIDE_INT 
-input_tree_flags (struct input_block *ib, enum tree_code code)
+input_tree_flags (struct input_block *ib, enum tree_code code, bool force)
 {
   unsigned HOST_WIDE_INT flags;
 
-  if (TEST_BIT (lto_flags_needed_for, code))
+  if (force || TEST_BIT (lto_flags_needed_for, code))
     {
       LTO_DEBUG_TOKEN ("flags");
       flags = input_uleb128 (ib);
@@ -607,7 +575,7 @@ input_expr_operand (struct input_block *
   if (TEST_BIT (lto_types_needed_for, code))
     type = get_type_ref (data_in, ib);
 
-  flags = input_tree_flags (ib, code);
+  flags = input_tree_flags (ib, code, false);
 
   /* FIXME! need to figure out how to set the file and line number.  */
   if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (code)))
@@ -644,6 +612,14 @@ input_expr_operand (struct input_block *
       TREE_TYPE (result) = type;
       break;
 
+    case IDENTIFIER_NODE:
+      {
+	unsigned int len;
+	const char * ptr = input_string_internal (data_in, input_uleb128 (ib), &len);
+	result = get_identifier_with_length (ptr, len);
+      }
+      break;
+
     case VECTOR_CST:
       {
 	tree chain = NULL_TREE;
@@ -923,10 +899,21 @@ input_expr_operand (struct input_block *
     case ASM_EXPR:
       {
 	tree str = input_string (data_in, input_uleb128 (ib));
-	tree ins = input_tree_list (ib, data_in, fn); 
-	tree outs = input_tree_list (ib, data_in, fn); 
-	tree clobbers = input_tree_list (ib, data_in, fn);
+	tree ins = NULL_TREE;
+	tree outs = NULL_TREE;
+	tree clobbers = NULL_TREE;
 	tree tl;
+
+	tag = input_record_start (ib);
+	if (tag)
+	  ins = input_expr_operand (ib, data_in, fn, tag); 
+	tag = input_record_start (ib);
+	if (tag)
+	  outs = input_expr_operand (ib, data_in, fn, tag); 
+	tag = input_record_start (ib);
+	if (tag)
+	  clobbers = input_expr_operand (ib, data_in, fn, tag);
+
 	result = build4 (code, void_type_node, str, outs, ins, clobbers);
 
 	for (tl = ASM_OUTPUTS (result); tl; tl = TREE_CHAIN (tl))
@@ -997,6 +984,40 @@ input_expr_operand (struct input_block *
       }
       break;
 
+    case TREE_LIST:
+      {
+	unsigned int count = input_uleb128 (ib);
+
+	result = NULL_TREE;
+	while (count--)
+	  {
+	    tree value;
+	    tree purpose;
+	    tree next;
+	    tree elt;
+	    enum LTO_tags tag = input_record_start (ib);
+
+	    if (tag)
+	      value = input_expr_operand (ib, data_in, fn, tag);
+	    else 
+	      value = NULL_TREE;
+	    tag = input_record_start (ib);
+	    if (tag)
+	      purpose = input_expr_operand (ib, data_in, fn, tag);
+	    else 
+	      purpose = NULL_TREE;
+
+	    elt = build_tree_list (purpose, value);
+	    if (result)
+	      TREE_CHAIN (next) = elt;
+	    else
+	      /* Save the first one.  */
+	      result = elt;
+	    next = elt;
+	  }
+      }
+      break;
+
       /* This is the default case. All of the cases that can be done
 	 completely mechanically are done here.  */
 #define SET_NAME(a,b)
@@ -1232,7 +1253,7 @@ input_local_var (struct input_block *ib,
   if (!is_var)
     DECL_ARG_TYPE (result) = get_type_ref (data_in, ib);
 
-  flags = input_tree_flags (ib, LTO_flags_needed);
+  flags = input_tree_flags (ib, 0, true);
   input_line_info (ib, data_in, flags);
   set_line_info (data_in, result);
 
@@ -1258,7 +1279,8 @@ input_local_var (struct input_block *ib,
   if (variant & 0x1)
     {
       LTO_DEBUG_TOKEN ("attributes");
-      DECL_ATTRIBUTES (result) = input_tree_list (ib, data_in, fn);
+      DECL_ATTRIBUTES (result) 
+	= input_expr_operand (ib, data_in, fn, input_record_start (ib));
     }
   if (variant & 0x2)
     DECL_SIZE_UNIT (result) 
@@ -1433,7 +1455,7 @@ static tree
 input_phi (struct input_block *ib, basic_block bb, 
 	   struct data_in *data_in, struct function *fn)
 {
-  unsigned HOST_WIDE_INT flags = input_tree_flags (ib, PHI_NODE);
+  unsigned HOST_WIDE_INT flags = input_tree_flags (ib, PHI_NODE, false);
 
   tree phi_result = VEC_index (tree, SSANAMES (fn), input_uleb128 (ib));
   int len = EDGE_COUNT (bb->preds);
@@ -1481,7 +1503,7 @@ input_ssa_names (struct input_block *ib,
   init_tree_ssa (fn);
   init_ssanames (fn, size);
   i = input_uleb128 (ib);
-  
+
   while (i)
     {
       tree ssa_name;
@@ -1495,9 +1517,8 @@ input_ssa_names (struct input_block *ib,
       name = input_expr_operand (ib, data_in, fn, input_record_start (ib));
       ssa_name = make_ssa_name (fn, name, build_empty_stmt ());
 
-      flags = input_tree_flags (ib, LTO_flags_needed);
+      flags = input_tree_flags (ib, 0, true);
       process_tree_flags (ssa_name, flags);
-
       i = input_uleb128 (ib);
     } 
 }

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]