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]

[tree-ssa] Fix V_DEF/relocate reference creation [patch]


We were only creating V_DEF/relocate references if there had been
a previous dereference of a pointer.  For instance, in the
following code fragment:

	    1	int *ptr;
	    2	ptr = foo();
	    3	while (*ptr)
	  	  ...

The assignment to 'ptr' at line 2 would not create a /relocate
definition for '*ptr' which is needed to know that *ptr
represents a new value because ptr is pointing to a new location.

The patch also fixes equality tests for E_* reference types that
I had failed to convert when I changed the types for the V_* and
E_* constants.

Bootstrapped and tested on x86.


2002-10-31  Diego Novillo  <dnovillo@redhat.com>

	* tree-dfa.c (create_indirect_ref): New local function.
	(find_refs_in_expr): Call it.
	(create_ref): Check E_* reference types with == instead of &.
	(dump_ref): Likewise.
	(count_tree_refs): Likewise.
	* tree-ssa.c (set_ssa_links): Update documentation comment for
	save_chain.

Index: tree-dfa.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-dfa.c,v
retrieving revision 1.1.4.37
diff -d -u -p -r1.1.4.37 tree-dfa.c
--- tree-dfa.c	26 Oct 2002 20:37:07 -0000	1.1.4.37
+++ tree-dfa.c	31 Oct 2002 17:26:18 -0000
@@ -96,6 +96,7 @@ static void add_may_alias		PARAMS ((tree
 static bool may_alias_p			PARAMS ((tree, tree));
 static bool is_visible_to		PARAMS ((tree, tree));
 static size_t tree_ref_size		PARAMS ((enum tree_ref_type));
+static inline tree create_indirect_ref	PARAMS ((tree));
 
 
 /* Global declarations.  */
@@ -290,10 +291,14 @@ find_refs_in_expr (expr_p, ref_type, ref
 	 we have to clobber the associated '*p' variable, because now 'p'
 	 is pointing to a different memory location.  */
       if (ref_type == V_DEF
-	  && POINTER_TYPE_P (TREE_TYPE (expr))
-	  && indirect_var (expr))
-	create_ref (indirect_var (expr), V_DEF, TRM_RELOCATE, bb, parent_stmt_p,
-	            parent_expr_p, NULL, 1);
+	  && POINTER_TYPE_P (TREE_TYPE (expr)))
+	{
+	  if (indirect_var (expr) == NULL)
+	    set_indirect_var (expr, create_indirect_ref (expr));
+
+	  create_ref (indirect_var (expr), V_DEF, TRM_RELOCATE, bb,
+		      parent_stmt_p, parent_expr_p, NULL, 1);
+	}
 
       return;
     }
@@ -891,7 +896,7 @@ create_ref (var, ref_type, ref_mod, bb, 
 
       ref->vuse.rdefs = create_ref_list ();
     }
-  else if (ref_type & E_PHI)
+  else if (ref_type == E_PHI)
     {
       varray_type temp;
       VARRAY_GENERIC_PTR_INIT (temp, 
@@ -1159,7 +1164,7 @@ dump_ref (outf, prefix, ref, indent, det
 	    }
 	}
 
-      if ((ref_type (ref) & E_PHI) && exprphi_phi_args (ref))
+      if ((ref_type (ref) == E_PHI) && exprphi_phi_args (ref))
 	{
 	  if (details)
 	    fprintf (outf, " class:%d downsafe:%d can_be_avail:%d later:%d\n", 
@@ -1181,7 +1186,7 @@ dump_ref (outf, prefix, ref, indent, det
 	  dump_ref (outf, prefix, imm_reaching_def (ref), indent + 4, 0);
 	}	  
 
-      if ((ref_type (ref) & E_USE) && expruse_phiop (ref))
+      if ((ref_type (ref) == E_USE) && expruse_phiop (ref))
 	{
 	  char *temp_indent;
 	  fprintf (outf, " class:%d has_real_use:%d  operand defined by:\n", 
@@ -1648,11 +1653,11 @@ count_tree_refs (dfa_stats_p, list)
 	  if (num > dfa_stats_p->max_num_phi_args)
 	    dfa_stats_p->max_num_phi_args = num;
 	}
-      else if (ref_type (ref) & E_PHI)
+      else if (ref_type (ref) == E_PHI)
 	dfa_stats_p->num_ephis++;
-      else if (ref_type (ref) & E_USE)
+      else if (ref_type (ref) == E_USE)
 	dfa_stats_p->num_euses++;
-      else if (ref_type (ref) & E_KILL)
+      else if (ref_type (ref) == E_KILL)
 	dfa_stats_p->num_ekills++;
     }
 }
@@ -2009,4 +2014,18 @@ tree_ref_structure (ref)
     return TR_EXPR_REF_COMMON;
 
   abort ();
+}
+
+
+/* Create and return a new INDIRECT_REF for pointer symbol PTR_SYM.  */
+
+static inline tree
+create_indirect_ref (ptr_sym)
+     tree ptr_sym;
+{
+#if defined ENABLE_CHECKING
+  if (!POINTER_TYPE_P (TREE_TYPE (ptr_sym)))
+    abort ();
+#endif
+  return build1 (INDIRECT_REF, TREE_TYPE (TREE_TYPE (ptr_sym)), ptr_sym);
 }
Index: tree-ssa.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-ssa.c,v
retrieving revision 1.1.4.26
diff -d -u -p -r1.1.4.26 tree-ssa.c
--- tree-ssa.c	26 Oct 2002 20:37:07 -0000	1.1.4.26
+++ tree-ssa.c	31 Oct 2002 17:26:18 -0000
@@ -867,8 +867,11 @@ set_ssa_links (ref, var, alias_ix)
     }
   else if (ref_type (ref) == V_DEF || ref_type (ref) == V_PHI)
     {
-      /* Save the current definition chain (only when not processing
-	 aliases).  */
+      /* Save the current definition chain for the variable.  This is used
+	 when visiting the dominator children of a block in
+	 search_fud_chains.  Once all the dominator children of block BB
+	 have been visited, we need to restore CURRDEF for all the
+	 variables referenced in BB.  */
       save_chain[ref_id (ref)] = currdef;
 
       /* Set a def-def link for partial definitions.  */


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