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]

[PATCH] Remove SSA name value_handle field


This removes the value_handle field from struct tree_ssa_name by
using a VEC in DOM / jump threading.

Bootstrapped and tested on x86_64-unknown-linux-gnu.  I'll apply this
tomorrow if there are no complaints.

Richard.

2009-04-27  Richard Guenther  <rguenther@suse.de>

	* tree.h (SSA_NAME_VALUE): Remove.
	(struct tree_ssa_name): Remove value_handle member.
	* tree-vrp.c (execute_vrp): Initialize/free the value-handle
	array for jump threading.
	* tree-ssa-propagate.c (ssa_prop_init): Do not initialize
	SSA_NAME_VALUEs.
	* print-tree.c (print_node): Do not dump SSA_NAME_VALUEs.
	* tree-flow.h (threadedge_initialize_values): Declare.
	(threadedge_finalize_values): Likewise.
	* tree-ssa-threadedge.c (ssa_name_values): New global variable.
	(SSA_NAME_VALUE): Define.
	(threadedge_initialize_values): New function.
	(threadedge_finalize_values): Likewise.
	* tree-ssa-dom.c (ssa_name_values): New global variable.
	(SSA_NAME_VALUE): Define.
	(tree_ssa_dominator_optimize): Initialize/free the value-handle
	array.

Index: gcc/tree.h
===================================================================
*** gcc/tree.h.orig	2009-04-27 13:13:57.000000000 +0200
--- gcc/tree.h	2009-04-27 13:33:51.000000000 +0200
*************** struct GTY(()) tree_exp {
*** 1854,1863 ****
  #define SSA_NAME_PTR_INFO(N) \
      SSA_NAME_CHECK (N)->ssa_name.ptr_info
  
- /* Get the value of this SSA_NAME, if available.  */
- #define SSA_NAME_VALUE(N) \
-    SSA_NAME_CHECK (N)->ssa_name.value_handle
- 
  #ifndef _TREE_FLOW_H
  struct ptr_info_def;
  #endif
--- 1854,1859 ----
*************** struct GTY(()) tree_ssa_name {
*** 1896,1908 ****
    /* Pointer attributes used for alias analysis.  */
    struct ptr_info_def *ptr_info;
  
-   /* Value for SSA name used by various passes.
- 
-      Right now only invariants are allowed to persist beyond a pass in
-      this field; in the future we will allow VALUE_HANDLEs to persist
-      as well.  */
-   tree value_handle;
- 
    /* Immediate uses list for this SSA_NAME.  */
    struct ssa_use_operand_d imm_uses;
  };
--- 1892,1897 ----
Index: gcc/tree-vrp.c
===================================================================
*** gcc/tree-vrp.c.orig	2009-04-27 13:13:57.000000000 +0200
--- gcc/tree-vrp.c	2009-04-27 13:33:51.000000000 +0200
*************** execute_vrp (void)
*** 7277,7282 ****
--- 7277,7283 ----
  
    to_remove_edges = VEC_alloc (edge, heap, 10);
    to_update_switch_stmts = VEC_alloc (switch_update, heap, 5);
+   threadedge_initialize_values ();
  
    vrp_initialize ();
    ssa_propagate (vrp_visit_stmt, vrp_visit_phi_node);
*************** execute_vrp (void)
*** 7322,7327 ****
--- 7323,7329 ----
  
    VEC_free (edge, heap, to_remove_edges);
    VEC_free (switch_update, heap, to_update_switch_stmts);
+   threadedge_finalize_values ();
  
    scev_finalize ();
    loop_optimizer_finalize ();
Index: gcc/tree-ssa-propagate.c
===================================================================
*** gcc/tree-ssa-propagate.c.orig	2009-04-27 13:13:57.000000000 +0200
--- gcc/tree-ssa-propagate.c	2009-04-27 13:33:51.000000000 +0200
*************** ssa_prop_init (void)
*** 487,493 ****
    edge e;
    edge_iterator ei;
    basic_block bb;
-   size_t i;
  
    /* Worklists of SSA edges.  */
    interesting_ssa_edges = VEC_alloc (gimple, gc, 20);
--- 487,492 ----
*************** ssa_prop_init (void)
*** 505,515 ****
    cfg_blocks = VEC_alloc (basic_block, heap, 20);
    VEC_safe_grow (basic_block, heap, cfg_blocks, 20);
  
-   /* Initialize the values for every SSA_NAME.  */
-   for (i = 1; i < num_ssa_names; i++)
-     if (ssa_name (i))
-       SSA_NAME_VALUE (ssa_name (i)) = NULL_TREE;
- 
    /* Initially assume that every edge in the CFG is not executable.
       (including the edges coming out of ENTRY_BLOCK_PTR).  */
    FOR_ALL_BB (bb)
--- 504,509 ----
Index: gcc/print-tree.c
===================================================================
*** gcc/print-tree.c.orig	2009-04-27 13:13:57.000000000 +0200
--- gcc/print-tree.c	2009-04-27 13:33:51.000000000 +0200
*************** print_node (FILE *file, const char *pref
*** 896,909 ****
  	  if (SSA_NAME_IN_FREE_LIST (node))
  	    fprintf (file, " in-free-list");
  
! 	  if (SSA_NAME_PTR_INFO (node)
! 	      || SSA_NAME_VALUE (node))
  	    {
  	      indent_to (file, indent + 3);
  	      if (SSA_NAME_PTR_INFO (node))
  		dump_addr (file, " ptr-info ", SSA_NAME_PTR_INFO (node));
- 	      if (SSA_NAME_VALUE (node))
- 		dump_addr (file, " value ", SSA_NAME_VALUE (node));
  	    }
  	  break;
  
--- 896,906 ----
  	  if (SSA_NAME_IN_FREE_LIST (node))
  	    fprintf (file, " in-free-list");
  
! 	  if (SSA_NAME_PTR_INFO (node))
  	    {
  	      indent_to (file, indent + 3);
  	      if (SSA_NAME_PTR_INFO (node))
  		dump_addr (file, " ptr-info ", SSA_NAME_PTR_INFO (node));
  	    }
  	  break;
  
Index: gcc/tree-flow.h
===================================================================
*** gcc/tree-flow.h.orig	2009-04-27 13:13:57.000000000 +0200
--- gcc/tree-flow.h	2009-04-27 15:52:52.000000000 +0200
*************** bool stmt_dominates_stmt_p (gimple, gimp
*** 803,808 ****
--- 803,816 ----
  void mark_virtual_ops_for_renaming (gimple);
  
  /* In tree-ssa-threadedge.c */
+ extern void threadedge_initialize_values (void);
+ extern void threadedge_finalize_values (void);
+ extern VEC(tree,heap) *ssa_name_values;
+ #define SSA_NAME_VALUE(x) \
+     (SSA_NAME_VERSION(x) < VEC_length(tree, ssa_name_values) \
+      ? VEC_index(tree, ssa_name_values, SSA_NAME_VERSION(x)) \
+      : NULL_TREE)
+ extern void set_ssa_name_value (tree, tree);
  extern bool potentially_threadable_block (basic_block);
  extern void thread_across_edge (gimple, edge, bool,
  				VEC(tree, heap) **, tree (*) (gimple, gimple));
Index: gcc/tree-ssa-threadedge.c
===================================================================
*** gcc/tree-ssa-threadedge.c.orig	2009-04-27 13:13:57.000000000 +0200
--- gcc/tree-ssa-threadedge.c	2009-04-27 15:55:10.000000000 +0200
*************** along with GCC; see the file COPYING3.
*** 49,54 ****
--- 49,83 ----
     to copy as part of the jump threading process.  */
  static int stmt_count;
  
+ /* Array to record value-handles per SSA_NAME.  */
+ VEC(tree,heap) *ssa_name_values;
+ 
+ /* Set the value for the SSA name NAME to VALUE.  */
+ 
+ void
+ set_ssa_name_value (tree name, tree value)
+ {
+   if (SSA_NAME_VERSION (name) >= VEC_length (tree, ssa_name_values))
+     VEC_safe_grow_cleared (tree, heap, ssa_name_values,
+ 			   SSA_NAME_VERSION (name) + 1);
+   VEC_replace (tree, ssa_name_values, SSA_NAME_VERSION (name), value);
+ }
+ 
+ /* Initialize the per SSA_NAME value-handles array.  Returns it.  */
+ void
+ threadedge_initialize_values (void)
+ {
+   gcc_assert (ssa_name_values == NULL);
+   ssa_name_values = VEC_alloc(tree, heap, num_ssa_names);
+ }
+ 
+ /* Free the per SSA_NAME value-handle array.  */
+ void
+ threadedge_finalize_values (void)
+ {
+   VEC_free(tree, heap, ssa_name_values);
+ }
+ 
  /* Return TRUE if we may be able to thread an incoming edge into
     BB to an outgoing edge from BB.  Return FALSE otherwise.  */
  
*************** remove_temporary_equivalences (VEC(tree,
*** 126,132 ****
  	break;
  
        prev_value = VEC_pop (tree, *stack);
!       SSA_NAME_VALUE (dest) = prev_value;
      }
  }
  
--- 155,161 ----
  	break;
  
        prev_value = VEC_pop (tree, *stack);
!       set_ssa_name_value (dest, prev_value);
      }
  }
  
*************** record_temporary_equivalence (tree x, tr
*** 145,151 ****
        y = tmp ? tmp : y;
      }
  
!   SSA_NAME_VALUE (x) = y;
    VEC_reserve (tree, heap, *stack, 2);
    VEC_quick_push (tree, *stack, prev_x);
    VEC_quick_push (tree, *stack, x);
--- 174,180 ----
        y = tmp ? tmp : y;
      }
  
!   set_ssa_name_value (x, y);
    VEC_reserve (tree, heap, *stack, 2);
    VEC_quick_push (tree, *stack, prev_x);
    VEC_quick_push (tree, *stack, x);
Index: gcc/tree-ssa-dom.c
===================================================================
*** gcc/tree-ssa-dom.c.orig	2009-04-27 13:13:57.000000000 +0200
--- gcc/tree-ssa-dom.c	2009-04-27 15:55:25.000000000 +0200
*************** static unsigned int
*** 619,625 ****
  tree_ssa_dominator_optimize (void)
  {
    struct dom_walk_data walk_data;
-   unsigned int i;
  
    memset (&opt_stats, 0, sizeof (opt_stats));
  
--- 619,624 ----
*************** tree_ssa_dominator_optimize (void)
*** 659,664 ****
--- 658,666 ----
       that we update the loop info.  */
    loop_optimizer_init (LOOPS_HAVE_SIMPLE_LATCHES);
  
+   /* Initialize the value-handle array.  */
+   threadedge_initialize_values ();
+ 
    /* We need accurate information regarding back edges in the CFG
       for jump threading; this may include back edges that are not part of
       a single loop.  */
*************** tree_ssa_dominator_optimize (void)
*** 716,738 ****
        bitmap_zero (need_eh_cleanup);
      }
  
-   /* Finally, remove everything except invariants in SSA_NAME_VALUE.
- 
-      Long term we will be able to let everything in SSA_NAME_VALUE
-      persist.  However, for now, we know this is the safe thing to do.  */
-   for (i = 0; i < num_ssa_names; i++)
-    {
-       tree name = ssa_name (i);
-       tree value;
- 
-       if (!name)
-         continue;
- 
-       value = SSA_NAME_VALUE (name);
-       if (value && !is_gimple_min_invariant (value))
- 	SSA_NAME_VALUE (name) = NULL;
-     }
- 
    statistics_counter_event (cfun, "Redundant expressions eliminated",
  			    opt_stats.num_re);
    statistics_counter_event (cfun, "Constants propagated",
--- 718,723 ----
*************** tree_ssa_dominator_optimize (void)
*** 759,764 ****
--- 744,753 ----
    VEC_free (tree, heap, const_and_copies_stack);
    VEC_free (gimple_p, heap, stmts_to_rescan);
    
+   /* Free the value-handle array.  */
+   threadedge_finalize_values ();
+   ssa_name_values = NULL;
+ 
    return 0;
  }
  
*************** restore_vars_to_original_value (void)
*** 912,918 ****
  	}
  
        prev_value = VEC_pop (tree, const_and_copies_stack);
!       SSA_NAME_VALUE (dest) =  prev_value;
      }
  }
  
--- 901,907 ----
  	}
  
        prev_value = VEC_pop (tree, const_and_copies_stack);
!       set_ssa_name_value (dest, prev_value);
      }
  }
  
*************** record_equivalences_from_phis (basic_blo
*** 1124,1130 ****
  	 inferred from a comparison.  All uses of this ssa name are dominated
  	 by this assignment, so unwinding just costs time and space.  */
        if (i == gimple_phi_num_args (phi) && may_propagate_copy (lhs, rhs))
! 	SSA_NAME_VALUE (lhs) = rhs;
      }
  }
  
--- 1113,1119 ----
  	 inferred from a comparison.  All uses of this ssa name are dominated
  	 by this assignment, so unwinding just costs time and space.  */
        if (i == gimple_phi_num_args (phi) && may_propagate_copy (lhs, rhs))
! 	set_ssa_name_value (lhs, rhs);
      }
  }
  
*************** record_conditions (struct edge_info *edg
*** 1437,1443 ****
  static void
  record_const_or_copy_1 (tree x, tree y, tree prev_x)
  {
!   SSA_NAME_VALUE (x) = y;
  
    if (dump_file && (dump_flags & TDF_DETAILS))
      {
--- 1426,1432 ----
  static void
  record_const_or_copy_1 (tree x, tree y, tree prev_x)
  {
!   set_ssa_name_value (x, y);
  
    if (dump_file && (dump_flags & TDF_DETAILS))
      {
*************** record_equivalences_from_stmt (gimple st
*** 1956,1962 ****
  	    fprintf (dump_file, "\n");
  	  }
  
! 	SSA_NAME_VALUE (lhs) = rhs;
        }
      }
  
--- 1945,1951 ----
  	    fprintf (dump_file, "\n");
  	  }
  
! 	set_ssa_name_value (lhs, rhs);
        }
      }
  


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