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]

Re: [patch] tree-phinodes.c: Speed up PHI node allocation/resizing.


Hi Diego,

> > -  memset (phi, 0, size);
> > +  memset (phi, 0, sizeof (struct tree_phi_node) - sizeof (struct phi_arg_d));
> >    TREE_SET_CODE (phi, PHI_NODE);
> >
> Add comment clarifying why it's safe not to clear the whole thing. 
> Otherwise, OK.

Thanks.  This is the final patch that I committed.

Kazu Hirata

2004-10-29  Kazu Hirata  <kazu@cs.umass.edu>

	* tree-phinodes.c (make_phi_node, resize_phi_node): Don't zero
	the whole PHI node.
	* tree.h (tree_phi_node): Tell the garbage collector to chase
	num_args arguments.

Index: tree-phinodes.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-phinodes.c,v
retrieving revision 2.12
diff -u -d -p -r2.12 tree-phinodes.c
--- tree-phinodes.c	29 Oct 2004 00:48:00 -0000	2.12
+++ tree-phinodes.c	29 Oct 2004 14:04:07 -0000
@@ -199,7 +199,12 @@ make_phi_node (tree var, int len)
 
     }
 
-  memset (phi, 0, size);
+  /* We do not have to clear a part of the PHI node that stores PHI
+     arguments, which is safe because we tell the garbage collector to
+     scan up to num_args elements in the array of PHI arguments.  In
+     other words, the garbage collector will not follow garbage
+     pointers in the unused portion of the array.  */
+  memset (phi, 0, sizeof (struct tree_phi_node) - sizeof (struct phi_arg_d));
   TREE_SET_CODE (phi, PHI_NODE);
   PHI_ARG_CAPACITY (phi) = len;
   TREE_TYPE (phi) = TREE_TYPE (var);
@@ -234,7 +239,7 @@ resize_phi_node (tree *phi, int len)
 {
   int size, old_size;
   tree new_phi;
-  int i, old_len, bucket = NUM_BUCKETS - 2;
+  int bucket = NUM_BUCKETS - 2;
 
   gcc_assert (len >= PHI_ARG_CAPACITY (*phi));
 
@@ -271,16 +276,8 @@ resize_phi_node (tree *phi, int len)
 
   memcpy (new_phi, *phi, old_size);
 
-  old_len = PHI_ARG_CAPACITY (new_phi);
   PHI_ARG_CAPACITY (new_phi) = len;
 
-  for (i = old_len; i < len; i++)
-    {
-      SET_PHI_ARG_DEF (new_phi, i, NULL_TREE);
-      PHI_ARG_EDGE (new_phi, i) = NULL;
-      PHI_ARG_NONZERO (new_phi, i) = false;
-    }
-
   *phi = new_phi;
 }
 
Index: tree.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree.h,v
retrieving revision 1.642
diff -u -d -p -r1.642 tree.h
--- tree.h	29 Oct 2004 12:28:25 -0000	1.642
+++ tree.h	29 Oct 2004 14:04:08 -0000
@@ -1405,7 +1405,7 @@ struct tree_phi_node GTY(())
   /* Dataflow information.  */
   struct dataflow_d *df;
 
-  struct phi_arg_d GTY ((length ("((tree)&%h)->phi.capacity"))) a[1];
+  struct phi_arg_d GTY ((length ("((tree)&%h)->phi.num_args"))) a[1];
 };
 
 


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