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-branch] New addressof attribute for variable uses [patch]


Taking the address of a variable does not represent a load
operation, but it should be marked.  This patch adds a new
addressof attribute to V_USE references that is added when an
ADDR_EXPR is found.

Bootstrapped and tested on x86.


Diego.



	* tree-dfa.c (M_ADDRESSOF): Define.
	(find_refs_in_expr): Create addressof-use references for ADDR_EXPR
	nodes.
	Don't create references for FUNCTION_DECL nodes.
	(ref_type_name): Handle M_ADDRESSOF.
	(validate_ref_type): Ditto.
	(clobber_vars_r): Don't clobber FUNCTION_DECL nodes.
	* tree-flow.h (M_ADDRESSOF): Declare.

Index: tree-dfa.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-dfa.c,v
retrieving revision 1.1.4.17
diff -d -u -p -r1.1.4.17 tree-dfa.c
--- tree-dfa.c	17 Sep 2002 19:46:20 -0000	1.1.4.17
+++ tree-dfa.c	18 Sep 2002 14:28:09 -0000
@@ -101,6 +101,7 @@ const HOST_WIDE_INT M_PARTIAL	= 1 << 11;
 const HOST_WIDE_INT M_INITIAL	= 1 << 12;
 const HOST_WIDE_INT M_INDIRECT	= 1 << 13;
 const HOST_WIDE_INT M_VOLATILE	= 1 << 14;
+const HOST_WIDE_INT M_ADDRESSOF	= 1 << 15;
 
 
 /* Look for variable references in every block of the flowgraph.  */
@@ -308,8 +309,8 @@ find_refs_in_expr (expr_p, ref_type, bb,
   if (class == 'c'
       || class == 't'
       || class == 'b'
-      || code == ADDR_EXPR
       || code == RESULT_DECL
+      || code == FUNCTION_DECL
       || code == LABEL_DECL)
     return;
 
@@ -327,7 +328,7 @@ find_refs_in_expr (expr_p, ref_type, bb,
     }
 
   /* If we found a _DECL node, create a reference to it and return.  */
-  if (code == VAR_DECL || code == PARM_DECL || code == FUNCTION_DECL)
+  if (code == VAR_DECL || code == PARM_DECL)
     {
       tree_ref ref = create_ref (expr, ref_type, bb, parent_stmt, parent_expr,
 	                         expr_p, true);
@@ -436,6 +437,15 @@ find_refs_in_expr (expr_p, ref_type, bb,
       return;
     }
 
+  /* ADDR_EXPR nodes create an address-of use of their operand.  This means
+     that the variable is not read, but its address is needed.  */
+  if (code == ADDR_EXPR)
+    {
+      find_refs_in_expr (&TREE_OPERAND (expr, 0), V_USE|M_ADDRESSOF, bb,
+			 parent_stmt, parent_expr);
+      return;
+    }
+
   /* Lists.  */
   if (code == TREE_LIST)
     {
@@ -1316,6 +1326,9 @@ ref_type_name (type)
   if (type & M_VOLATILE)
     strncat (str, "/volatile", max - strlen (str));
 
+  if (type & M_ADDRESSOF)
+    strncat (str, "/addressof", max - strlen (str));
+
   return str;
 }
 
@@ -1336,7 +1349,7 @@ validate_ref_type (type)
     }
   else if (type & V_USE)
     {
-      type &= ~(M_MAY | M_PARTIAL | M_INDIRECT);
+      type &= ~(M_DEFAULT | M_MAY | M_PARTIAL | M_INDIRECT | M_ADDRESSOF);
       return type == V_USE;
     }
   else if (type & V_PHI)
@@ -1380,7 +1393,7 @@ clobber_vars_r (tp, walk_subtrees, data)
   struct clobber_data_d *clobber = (struct clobber_data_d *)data;
 
   /* Create may-use and clobber references for every *_DECL in sight.  */
-  if (code == VAR_DECL || code == PARM_DECL || code == FUNCTION_DECL)
+  if (code == VAR_DECL || code == PARM_DECL)
     {
       create_ref (*tp, V_USE | M_MAY, clobber->bb, clobber->parent_stmt,
 		  clobber->parent_expr, NULL, true);
Index: tree-flow.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-flow.h,v
retrieving revision 1.1.4.14
diff -d -u -p -r1.1.4.14 tree-flow.h
--- tree-flow.h	17 Sep 2002 19:46:20 -0000	1.1.4.14
+++ tree-flow.h	18 Sep 2002 14:28:09 -0000
@@ -155,6 +162,11 @@ extern const HOST_WIDE_INT M_INDIRECT;
    In the above code fragment, we cannot assume that 'b' is assigned the
    value 5.  */
 extern const HOST_WIDE_INT M_VOLATILE;
+
+/* M_ADDRESSOF modifies a V_USE reference to indicate that the address of
+   the variable is needed.  This is not a memory load operation, just an
+   indication that we need the address of the variable being referenced.  */
+extern const HOST_WIDE_INT M_ADDRESSOF;
 
 
 /*---------------------------------------------------------------------------


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