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]

[sa]: Fix C++ regressions on structure-aliasing branch


This patch fixes the C++ regressions that were occuring on the structure
aliasing branch (more places where the fact that a structure field is
not a real variable, and not quite a memory tag, were important)

Bootstrapped and regtested on i686-pc-linux-gnu
Committed to structure-aliasing-branch.

--Dan
2005-01-12  Daniel Berlin  <dberlin@dberlin.org>

	* tree-ssa-alias.c (setup_pointers_and_addressables):
	Structure fields need underlying type tags too.
	Also don't unmark addressable on a structure unless it's fake
	variables are not addressed.
	(group_aliases): Must also deal with struct fields here.
	(add_pointed_to_var): Don't forget the subvars in addresses_needed.
	(push_fields_on_to_fieldstack): Should have been else if, not just if.
	(create_overlap_variables_for): Experiment with some other heuristics.
	* tree-ssa-operands.c (note_addressable): Var can be null.
	Return early if we handled the component_ref.

Index: tree-ssa-alias.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-ssa-alias.c,v
retrieving revision 2.25.2.11
diff -u -p -r2.25.2.11 tree-ssa-alias.c
--- tree-ssa-alias.c	10 Jan 2005 23:16:41 -0000	2.25.2.11
+++ tree-ssa-alias.c	14 Jan 2005 05:11:58 -0000
@@ -1319,7 +1318,9 @@ group_aliases (struct alias_info *ai)
 	  tree alias = VARRAY_TREE (aliases, j);
 	  var_ann_t ann = var_ann (alias);
 
-	  if (ann->mem_tag_kind == NOT_A_TAG && ann->may_aliases)
+	  if ((ann->mem_tag_kind == NOT_A_TAG 
+	       || ann->mem_tag_kind == STRUCT_FIELD)
+	      && ann->may_aliases)
 	    {
 	      tree new_alias;
 
@@ -1404,13 +1405,19 @@ setup_pointers_and_addressables (struct 
     {
       tree var = referenced_var (i);
       var_ann_t v_ann = var_ann (var);
+      subvar_t svars;
 
       /* Name memory tags already have flow-sensitive aliasing
 	 information, so they need not be processed by
 	 compute_flow_insensitive_aliasing.  Similarly, type memory
 	 tags are already accounted for when we process their
-	 associated pointer.  */
-      if (v_ann->mem_tag_kind != NOT_A_TAG)
+	 associated pointer. 
+      
+         Structure fields, on the other hand, have to have some of this
+         information processed for them, but it's pointless to mark them
+         non-addressable (since they are fake variables anyway).  */
+      if (v_ann->mem_tag_kind != NOT_A_TAG
+	  && v_ann->mem_tag_kind != STRUCT_FIELD) 
 	continue;
 
       /* Remove the ADDRESSABLE flag from every addressable variable whose
@@ -1418,18 +1425,13 @@ setup_pointers_and_addressables (struct 
          of ADDR_EXPR constants into INDIRECT_REF expressions and the
          removal of dead pointer assignments done by the early scalar
          cleanup passes.  */
-      if (TREE_ADDRESSABLE (var))
+      if (TREE_ADDRESSABLE (var) && v_ann->mem_tag_kind != STRUCT_FIELD)
 	{
 	  if (!bitmap_bit_p (ai->addresses_needed, v_ann->uid)
 	      && TREE_CODE (var) != RESULT_DECL
 	      && !is_global_var (var))
 	    {
-	      subvar_t svars;
-	      /* The address of VAR is not needed, remove the
-		 addressable bit, so that it can be optimized as a
-		 regular variable.  */
-	      mark_non_addressable (var);
-
+	      bool okay_to_mark = true;
 	      /* Since VAR is now a regular GIMPLE register, we will need
 		 to rename VAR into SSA afterwards.  */
 	      bitmap_set_bit (vars_to_rename, v_ann->uid);
@@ -1439,10 +1441,21 @@ setup_pointers_and_addressables (struct 
 		  && (svars = get_subvars_for_var (var)))
 		{
 		  subvar_t sv;
-		  
+
 		  for (sv = svars; sv; sv = sv->next)
-		    bitmap_set_bit (vars_to_rename, var_ann (sv->var)->uid);
+		    {	      
+		      var_ann_t svann = var_ann (sv->var);
+		      if (bitmap_bit_p (ai->addresses_needed, svann->uid))
+			okay_to_mark = false;
+		      bitmap_set_bit (vars_to_rename, svann->uid);
+		    }
 		}
+	      /* The address of VAR is not needed, remove the
+		 addressable bit, so that it can be optimized as a
+		 regular variable.  */
+	      if (okay_to_mark)
+		mark_non_addressable (var);
+
 	    }
 	  else
 	    {
@@ -1451,6 +1464,15 @@ setup_pointers_and_addressables (struct 
 		 clobber memory.  In those cases, we need to clobber
 		 all call-clobbered variables and all addressables.  */
 	      bitmap_set_bit (addressable_vars, v_ann->uid);
+	      if (AGGREGATE_TYPE_P (TREE_TYPE (var))
+		  && TREE_CODE (TREE_TYPE (var)) != ARRAY_TYPE
+		  && (svars = get_subvars_for_var (var)))
+		{
+		  subvar_t sv;
+		  for (sv = svars; sv; sv = sv->next)
+		    bitmap_set_bit (addressable_vars, var_ann (sv->var)->uid);
+		}
+
 	    }
 	}
 
@@ -1458,20 +1480,8 @@ setup_pointers_and_addressables (struct 
          entry in ADDRESSABLE_VARS for VAR.  */
       if (may_be_aliased (var))
 	{
-	  subvar_t svars;
-	  
 	  create_alias_map_for (var, ai);
-	  bitmap_set_bit (vars_to_rename, var_ann (var)->uid);
-	  if (AGGREGATE_TYPE_P (TREE_TYPE (var))
-	      && TREE_CODE (TREE_TYPE (var)) != ARRAY_TYPE
-	      && (svars = get_subvars_for_var (var)))
-	    {
-	      subvar_t sv;
-
-	      for (sv = svars; sv; sv = sv->next)
-		bitmap_set_bit (vars_to_rename, var_ann (sv->var)->uid);
-	    }
-	  
+	  bitmap_set_bit (vars_to_rename, var_ann (var)->uid);	  
 	}
 
       /* Add pointer variables that have been dereferenced to the POINTERS
@@ -1991,7 +2003,11 @@ add_pointed_to_var (struct alias_info *a
 	{
 	  subvar_t sv;
 	  for (sv = svars; sv; sv = sv->next)
-	    bitmap_set_bit (pi->pt_vars, var_ann (sv->var)->uid);
+	    {
+	      uid = var_ann (sv->var)->uid;
+	      bitmap_set_bit (ai->addresses_needed, uid);	      
+	      bitmap_set_bit (pi->pt_vars, uid);
+	    }
 	}
       else	
 	bitmap_set_bit (pi->pt_vars, uid);	  
@@ -2674,7 +2690,7 @@ push_fields_onto_fieldstack (tree type, 
 	  VEC_safe_push (fieldoff_t, *fieldstack, pair);
 	}
     }
-  if (TREE_CODE (field) == FIELD_DECL)
+  else if (TREE_CODE (field) == FIELD_DECL)
     {
       pair = xmalloc (sizeof (struct fieldoff));
       pair->field = field;
@@ -2749,7 +2764,7 @@ create_overlap_variables_for (tree var)
       fieldoff_t fo;
       bool notokay = false;
       int i;
-     
+      int count = 0;
       /* Not all fields have DECL_SIZE set for some reason.  Also, we can't
 	 handle variable sized fields.  */
       for (i = 0; VEC_iterate (fieldoff_t, fieldstack, i, fo); i++)
@@ -2757,12 +2772,22 @@ create_overlap_variables_for (tree var)
 	  if (!DECL_SIZE (fo->field) 
 	      || TREE_CODE (DECL_SIZE (fo->field)) != INTEGER_CST)
 	    {
+#if 0
+	      HOST_WIDE_INT fosize = TREE_INT_CST_LOW (DECL_SIZE (fo->field));
+
+	      if (!((fo->offset <= up->minused
+		   && fo->offset + fosize <= up->minused)
+		    || fo->offset >= up->maxused))
+		{
+		  count++;
+		}
+#endif
 	      notokay = true;
 	      break;
 	    }
 	}
       /* Cleanup after ourselves if we can't create overlap variables.  */
-      if (notokay)
+      if (notokay || count > 8)
 	{
 	  while (VEC_length (fieldoff_t, fieldstack) != 0)
 	    {
@@ -2792,7 +2817,8 @@ create_overlap_variables_for (tree var)
 	    {
 	      free (fo);
 	      continue;
-	    }  
+	    }
+
 	  name = alloca (512);
 	  sv->offset = fo->offset;
 	  sv->size = fosize;
Index: tree-ssa-operands.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-ssa-operands.c,v
retrieving revision 2.32.2.13
diff -u -p -r2.32.2.13 tree-ssa-operands.c
--- tree-ssa-operands.c	10 Jan 2005 23:16:41 -0000	2.32.2.13
+++ tree-ssa-operands.c	14 Jan 2005 05:11:58 -0000
@@ -1138,8 +1138,9 @@ get_expr_operands (tree stmt, tree *expr
 	    subvar_t sv;
 	    for (sv = svars; sv; sv = sv->next)
 	      {
+		
 		if (offset == sv->offset && size == sv->size)
-		  add_stmt_operand (&sv->var, s_ann, flags);
+		    add_stmt_operand (&sv->var, s_ann, flags);
 		else if (offset >= sv->offset 
 			 && offset < (sv->offset + sv->size))
 		  add_stmt_operand (&sv->var, s_ann, flags & ~opf_kill_def);
@@ -1657,7 +1658,7 @@ note_addressable (tree var, stmt_ann_t s
     return;
   
   /* We take the address of all the fake variables, plus the real ones.  */
-  if (TREE_CODE (var) == COMPONENT_REF 
+  if (var && TREE_CODE (var) == COMPONENT_REF 
       && (ref = okay_component_ref_for_subvars (var, &offset, &size)))
     {
       subvar_t sv;
@@ -1676,6 +1677,7 @@ note_addressable (tree var, stmt_ann_t s
 		   && (offset + size > sv->offset))
 	    bitmap_set_bit (s_ann->addresses_taken, var_ann (sv->var)->uid);
 	}
+      return;
     }
   
   var = get_base_address (var);

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