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] Minor fixes/improvements


Andrew privately pointed out a case where we get PHI nodes with multiple
args from the same edge.  These were being created by the must-alias
code when we had PHI nodes where we had previously removed edges.

The code which allows us to re-run rewriting uses PHI_ARG_CAPACITY to 
determine if a PHI node has already been rewritten.  So anytime we
removed a PHI argumement we effectively told the rewriter that the
PHI node had not been rewritten and we ended up with multiple arguments
from the same edge.

The trivial fix is to update PHI_ARG_CAPACITY as we remove PHI arguments.
The downside is we get slightly incorrect memory consumption information.



The second change is a minor cleanup.  If the rewriter ends up iterating
we make two attempts to build the dominator tree.  That's just plain 
wasteful. 


Bootstrapped and regression tested.


        * tree-dfa.c (remove_phi_arg): Update PHI_ARG_CAPACITY.
  
        * tree-ssa.c (mark_def_sites): Do not build the dominator tree here.
        (rewrite_into_ssa): Do not depend on mark_def_sites to build the
        dominator tree.   Move computation of dominance frontiers out
        of main loop (even though it was only done once).  Free immediate
        dominator information as soon as we're done with it.

Andrew Index: tree-dfa.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-dfa.c,v
retrieving revision 1.1.4.130
diff -c -3 -p -r1.1.4.130 tree-dfa.c
*** tree-dfa.c	15 Jul 2003 19:15:24 -0000	1.1.4.130
--- tree-dfa.c	17 Jul 2003 22:45:10 -0000
*************** remove_phi_arg (tree phi, basic_block bl
*** 917,922 ****
--- 917,929 ----
  	{
  	  remove_phi_arg_num (phi, i);
  
+ 	  /* Apparently we also use PHI_ARG_CAPACITY to determine if we've
+ 	     already renamed PHI nodes.  So if we remove a PHI argument,
+ 	     then we must reduce its capacity so that we still know
+ 	     the PHI has been rewritten.  This means that any memory
+ 	     statistics for this PHI may be incorrect.  */
+ 	  PHI_ARG_CAPACITY (phi)--;
+ 
  	  /* If we removed the last PHI argument, then go ahead and
  	     remove the PHI node.  */
  	  if (PHI_NUM_ARGS (phi) == 0)
Index: tree-ssa.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-ssa.c,v
retrieving revision 1.1.4.104
diff -c -3 -p -r1.1.4.104 tree-ssa.c
*** tree-ssa.c	16 Jul 2003 19:26:52 -0000	1.1.4.104
--- tree-ssa.c	17 Jul 2003 22:45:12 -0000
*************** static sbitmap vars_to_rename;
*** 139,145 ****
  
  /* Local functions.  */
  static void delete_tree_ssa (tree);
! static void mark_def_sites (dominance_info, sbitmap);
  static void compute_global_livein (varray_type);
  static void set_def_block (tree, basic_block);
  static void set_livein_block (tree, basic_block);
--- 139,145 ----
  
  /* Local functions.  */
  static void delete_tree_ssa (tree);
! static void mark_def_sites (sbitmap);
  static void compute_global_livein (varray_type);
  static void set_def_block (tree, basic_block);
  static void set_livein_block (tree, basic_block);
*************** rewrite_into_ssa (tree fndecl, sbitmap v
*** 275,282 ****
    sbitmap globals;
    dominance_info idom;
    int i, rename_count;
-   bool compute_df;
    bool addr_expr_propagated_p;
    
    timevar_push (TV_TREE_SSA_OTHER);
  
--- 275,282 ----
    sbitmap globals;
    dominance_info idom;
    int i, rename_count;
    bool addr_expr_propagated_p;
+   basic_block bb;
    
    timevar_push (TV_TREE_SSA_OTHER);
  
*************** rewrite_into_ssa (tree fndecl, sbitmap v
*** 319,343 ****
    /* Compute immediate dominators.  */
    idom = calculate_dominance_info (CDI_DOMINATORS);
  
    /* Start the SSA rename process.  This may need to be repeated if the
       dominator optimizations exposed more symbols to rename by propagating
       ADDR_EXPR values into INDIRECT_REF expressions.  */
    rename_count = 0;
-   compute_df = true;
    addr_expr_propagated_p = false;
    do
      {
        /* Find variable references and mark definition sites.  */
!       mark_def_sites (idom, globals);
! 
!       /* Compute dominance frontiers (only once) and insert PHI nodes at
! 	 dominance frontiers of definition blocks.  */
!       if (compute_df)
! 	{
! 	  compute_dominance_frontiers (dfs, idom);
! 	  compute_df = false;
! 	}
  
        insert_phi_nodes (dfs, globals);
  
        /* Rewrite all the basic blocks in the program.  */
--- 319,349 ----
    /* Compute immediate dominators.  */
    idom = calculate_dominance_info (CDI_DOMINATORS);
  
+   /* Using the immediate dominators, build a dominator tree.  */
+   FOR_EACH_BB (bb)
+     {
+       /* Add BB to the set of dominator children of BB's immediate
+ 	 dominator.  */
+       basic_block idom_bb = get_immediate_dominator (idom, bb);
+       if (idom_bb)
+ 	add_dom_child (idom_bb, bb);
+     }
+   compute_dominance_frontiers (dfs, idom);
+ 
+   /* We're finished the the immediate dominator information.  */
+   free_dominance_info (idom);
+ 
    /* Start the SSA rename process.  This may need to be repeated if the
       dominator optimizations exposed more symbols to rename by propagating
       ADDR_EXPR values into INDIRECT_REF expressions.  */
    rename_count = 0;
    addr_expr_propagated_p = false;
    do
      {
        /* Find variable references and mark definition sites.  */
!       mark_def_sites (globals);
  
+       /* Insert PHI nodes at dominance frontiers of definition blocks.  */
        insert_phi_nodes (dfs, globals);
  
        /* Rewrite all the basic blocks in the program.  */
*************** rewrite_into_ssa (tree fndecl, sbitmap v
*** 382,388 ****
      BITMAP_XFREE (dfs[i]);
    free (dfs);
    free (globals);
-   free_dominance_info (idom);
    htab_delete (def_blocks);
    htab_delete (currdefs);
    if (vars == NULL)
--- 388,393 ----
*************** compute_global_livein (varray_type def_m
*** 502,518 ****
  /* Look for variable references in every block of the flowgraph, compute
     aliasing information and collect definition sites for every variable.
  
-    Also, compute the set of dominator children for each block in the
-    flowgraph.  This will be used by rewrite_block when traversing the
-    flowgraph.
- 
     Return a bitmap for the set of referenced variables which are
     "nonlocal", ie those which are live across block boundaries.
     This information is used to reduce the number of PHI nodes
     we create.  */
  
  static void
! mark_def_sites (dominance_info idom, sbitmap globals)
  {
    basic_block bb;
    block_stmt_iterator si;
--- 507,519 ----
  /* Look for variable references in every block of the flowgraph, compute
     aliasing information and collect definition sites for every variable.
  
     Return a bitmap for the set of referenced variables which are
     "nonlocal", ie those which are live across block boundaries.
     This information is used to reduce the number of PHI nodes
     we create.  */
  
  static void
! mark_def_sites (sbitmap globals)
  {
    basic_block bb;
    block_stmt_iterator si;
*************** mark_def_sites (dominance_info idom, sbi
*** 527,538 ****
       VARS_TO_RENAME bitmap.  */
    FOR_EACH_BB (bb)
      {
-       /* Add BB to the set of dominator children of BB's immediate
- 	 dominator.  */
-       basic_block idom_bb = get_immediate_dominator (idom, bb);
-       if (idom_bb)
- 	add_dom_child (idom_bb, bb);
- 
        sbitmap_zero (kills);
  
        for (si = bsi_start (bb); !bsi_end_p (si); bsi_next (&si))
--- 528,533 ----




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