This is the mail archive of the gcc@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: [tree-ssa] How to increase PHI capacity?


Op ma 04-08-2003, om 22:34 schreef Diego Novillo:
> On Mon, 2003-08-04 at 16:28, Steven Bosscher wrote:
> 
> > Yes.  But I need a phi with increased capacity.  Inserting a whole new
> > phi is childs play.
> > 
> I don't understand.  What's the problem, then?  Remove the old PHI node
> from the phi_nodes() list, ggc_realloc it and put it back in
> phi_nodes().

If that's OK with you, it's OK with me :)  I just think it would be
cleaner to have the ability to adjust the phi arg vector without
reallocating the whole phi.  But it's not a big deal now anyway.
> 
> Oh, you also need to adjust SSA_NAME_DEF_STMT for PHI_RESULT of the new
> PHI node.

Thanks, I hadn't thought of that.  

Does this look OK?  Bootstrapped and regtested, but obviously no-one
uses the resize code at this point (and I haven't tried yet).

Gr.
Steven

2003-08-04  Steven Bosscher  <steven@gcc.gnu.org>

	* tree-dfa.c (add_phi_arg): Allow PHI capacity to grow.
	* tree-flow.h  (add_phi_arg): Adjust prototype.
	* tree-ssa-pre.c (code_motion): Adjust call.
	* tree-ssa.c (rewrite_block): Likewise.
	* tree.c (resize_phi_node): New function.
	* tree.h (resize_phi_node): Add prototype.


Index: tree-dfa.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-dfa.c,v
retrieving revision 1.1.4.138
diff -c -3 -p -r1.1.4.138 tree-dfa.c
*** tree-dfa.c	31 Jul 2003 16:33:26 -0000	1.1.4.138
--- tree-dfa.c	4 Aug 2003 21:52:56 -0000
*************** create_phi_node (tree var, basic_block b
*** 865,893 ****
  
  /* Add a new argument to PHI node PHI.  DEF is the incoming reaching
     definition and E is the edge through which DEF reaches PHI.  The new
!    argument is added at the end of the argument list.  */
  
  void
! add_phi_arg (tree phi, tree def, edge e)
  {
!   int i = PHI_NUM_ARGS (phi);
  
! #if defined ENABLE_CHECKING
!   if (i >= PHI_ARG_CAPACITY (phi))
!     abort ();
! #endif
  
    /* Copy propagation needs to know what object occur in abnormal
       PHI nodes.  This is a convenient place to record such information.  */
    if (e->flags & EDGE_ABNORMAL)
      {
        SSA_NAME_OCCURS_IN_ABNORMAL_PHI (def) = 1;
!       SSA_NAME_OCCURS_IN_ABNORMAL_PHI (PHI_RESULT (phi)) = 1;
      }
  
!   PHI_ARG_DEF (phi, i) = def;
!   PHI_ARG_EDGE (phi, i) = e;
!   PHI_NUM_ARGS (phi)++;
  }
  
  
--- 865,919 ----
  
  /* Add a new argument to PHI node PHI.  DEF is the incoming reaching
     definition and E is the edge through which DEF reaches PHI.  The new
!    argument is added at the end of the argument list.
!    If PHI has reached its maximum capacity, add a few slots.  In this case,
!    PHI points to the reallocated phi node when we return.  */
  
  void
! add_phi_arg (tree *phi, tree def, edge e)
  {
!   int i = PHI_NUM_ARGS (*phi);
  
!   if (i >= PHI_ARG_CAPACITY (*phi))
!     {
!       /* Resize the phi.  Unfortunately, this also relocates it...  */
!       bb_ann_t ann = bb_ann (e->dest);
!       tree old_phi = *phi;
! 
!       resize_phi_node (phi, i + 4);
! 
!       /* The result of the phi is defined by this phi node.  */
!       SSA_NAME_DEF_STMT (PHI_RESULT (*phi)) = *phi;
! 
!       /* Update the list head if replacing the first listed phi.  */
!       if (ann->phi_nodes == old_phi)
! 	ann->phi_nodes = *phi;
!       else
! 	{
!           /* Traverse the list looking for the phi node to chain to.  */
! 	  tree p;
! 	  for (p = ann->phi_nodes;
! 	       p && TREE_CHAIN (p) != old_phi;
! 	       p = TREE_CHAIN (p));
! 
! 	  if (!p)
! 	    abort ();
! 
! 	  TREE_CHAIN (p) = *phi;
! 	}
!     }
  
    /* Copy propagation needs to know what object occur in abnormal
       PHI nodes.  This is a convenient place to record such information.  */
    if (e->flags & EDGE_ABNORMAL)
      {
        SSA_NAME_OCCURS_IN_ABNORMAL_PHI (def) = 1;
!       SSA_NAME_OCCURS_IN_ABNORMAL_PHI (PHI_RESULT (*phi)) = 1;
      }
  
!   PHI_ARG_DEF (*phi, i) = def;
!   PHI_ARG_EDGE (*phi, i) = e;
!   PHI_NUM_ARGS (*phi)++;
  }
  
  
Index: tree-flow.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-flow.h,v
retrieving revision 1.1.4.99
diff -c -3 -p -r1.1.4.99 tree-flow.h
*** tree-flow.h	4 Aug 2003 18:44:02 -0000	1.1.4.99
--- tree-flow.h	4 Aug 2003 21:52:56 -0000
*************** extern void get_stmt_operands (tree);
*** 416,422 ****
  extern var_ann_t create_var_ann (tree);
  extern stmt_ann_t create_stmt_ann (tree);
  extern tree create_phi_node (tree, basic_block);
! extern void add_phi_arg (tree, tree, edge);
  extern void remove_phi_arg (tree, basic_block);
  extern void remove_phi_arg_num (tree, int);
  extern void remove_phi_node (tree, tree, basic_block);
--- 416,422 ----
  extern var_ann_t create_var_ann (tree);
  extern stmt_ann_t create_stmt_ann (tree);
  extern tree create_phi_node (tree, basic_block);
! extern void add_phi_arg (tree *, tree, edge);
  extern void remove_phi_arg (tree, basic_block);
  extern void remove_phi_arg_num (tree, int);
  extern void remove_phi_node (tree, tree, basic_block);
Index: tree-ssa-pre.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-ssa-pre.c,v
retrieving revision 1.1.4.70
diff -c -3 -p -r1.1.4.70 tree-ssa-pre.c
*** tree-ssa-pre.c	30 Jul 2003 20:37:26 -0000	1.1.4.70
--- tree-ssa-pre.c	4 Aug 2003 21:53:02 -0000
*************** code_motion (struct expr_info *ei)
*** 2535,2541 ****
  				     NULL_TREE);
  	      if (!rdef)
  	        abort();
! 	      add_phi_arg (newtemp, rdef, EPHI_ARG_EDGE (use, i));
  	    }
  
  	  /* Associate BB to the PHI node.  */
--- 2536,2542 ----
  				     NULL_TREE);
  	      if (!rdef)
  	        abort();
! 	      add_phi_arg (&newtemp, rdef, EPHI_ARG_EDGE (use, i));
  	    }
  
  	  /* Associate BB to the PHI node.  */
Index: tree-ssa.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-ssa.c,v
retrieving revision 1.1.4.113
diff -c -3 -p -r1.1.4.113 tree-ssa.c
*** tree-ssa.c	31 Jul 2003 12:10:46 -0000	1.1.4.113
--- tree-ssa.c	4 Aug 2003 21:53:06 -0000
*************** rewrite_block (basic_block bb)
*** 806,812 ****
  	    continue;
  
  	  currdef = get_reaching_def (SSA_NAME_VAR (PHI_RESULT (phi)));
! 	  add_phi_arg (phi, currdef, e);
  	}
      }
  
--- 806,812 ----
  	    continue;
  
  	  currdef = get_reaching_def (SSA_NAME_VAR (PHI_RESULT (phi)));
! 	  add_phi_arg (&phi, currdef, e);
  	}
      }
  
Index: tree.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree.c,v
retrieving revision 1.263.2.43
diff -c -3 -p -r1.263.2.43 tree.c
*** tree.c	27 Jul 2003 18:40:12 -0000	1.263.2.43
--- tree.c	4 Aug 2003 21:53:14 -0000
*************** make_phi_node (tree var, int len)
*** 5022,5027 ****
--- 5022,5049 ----
  }
  
  
+ /* Resize an existing PHI node.  The only way is up.  Return the
+    possibly relocated phi.  */
+ 
+ void
+ resize_phi_node (tree *phi, int len)
+ {
+   int size;
+   tree Phi;
+ 
+ #ifdef ENABLE_CHECKING
+   if (len < PHI_ARG_CAPACITY (*phi))
+     abort ();
+ #endif
+ 
+   size = sizeof (struct tree_phi_node) + (len - 1) * sizeof (struct phi_arg_d);
+   Phi = ggc_realloc (*phi, size);
+   PHI_ARG_CAPACITY (Phi) = len;
+ 
+   *phi = Phi;
+ }
+ 
+ 
  /* Return an SSA_NAME node for variable VAR defined in statement STMT.
     STMT may be an empty statement for artificial references (e.g., default
     definitions created when a variable is used without a preceding
Index: tree.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree.h,v
retrieving revision 1.342.2.86
diff -c -3 -p -r1.342.2.86 tree.h
*** tree.h	31 Jul 2003 16:33:27 -0000	1.342.2.86
--- tree.h	4 Aug 2003 21:53:22 -0000
*************** extern tree make_tree_vec (int);
*** 2382,2387 ****
--- 2382,2388 ----
  /* Tree nodes for SSA analysis.  */
  
  extern tree make_phi_node (tree, int);
+ extern void resize_phi_node (tree *, int);
  extern tree make_ssa_name (tree, tree);
  extern tree build_vdef_expr (tree);
  

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