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][1/2] Remove referenced vars


This series aims at removing referenced vars.  It builds on the into-SSA
TLC series and the still to be posted removal of var-anns.

This first patch removes SRAs use of referenced vars.  Instead of
turning it upside-down the following simply adds a pass-local
"referenced" vars reverse lookup capability uid -> decl.

This was the last user of referenced_var ().

Bootstrapped and tested on x86_64-unknown-linux-gnu.

Richard.

2012-08-01  Richard Guenther  <rguenther@suse.de>

	* tree-flow-inline.h (referenced_var): Remove.
	* tree-ssa-coalesce.c (create_outofssa_var_map): Remove duplicate
	checking code.
	* tree-sra.c (candidates): New global hashtable.
	(candidate): New function.
	(sra_initialize): Initialize candidates.
	(sra_deinitialize): Free candidates.
	(disqualify_candidate): Remove candidate from candidates.
	(find_var_candidates): Walk over all local decls, add candidates
	to candidates hashtable.
	(find_param_candidates): Add candidates to candidates hashtable.
	(analyze_all_variable_accesses): Use candidate instead of
	referenced_var.

Index: gcc/tree-flow-inline.h
===================================================================
*** gcc/tree-flow-inline.h.orig	2012-08-01 11:06:15.000000000 +0200
--- gcc/tree-flow-inline.h	2012-08-01 11:16:46.398132279 +0200
*************** next_htab_element (htab_iterator *hti)
*** 98,113 ****
    return NULL;
  }
  
- /* Get the variable with uid UID from the list of referenced vars.  */
- 
- static inline tree
- referenced_var (unsigned int uid)
- {
-   tree var = referenced_var_lookup (cfun, uid);
-   gcc_assert (var || uid == 0);
-   return var;
- }
- 
  /* Initialize ITER to point to the first referenced variable in the
     referenced_vars hashtable, and return that variable.  */
  
--- 98,103 ----
Index: gcc/tree-ssa-coalesce.c
===================================================================
*** gcc/tree-ssa-coalesce.c.orig	2012-08-01 11:06:15.000000000 +0200
--- gcc/tree-ssa-coalesce.c	2012-08-01 11:16:46.399132279 +0200
*************** create_outofssa_var_map (coalesce_list_p
*** 983,996 ****
    int v1, v2, cost;
    unsigned i;
  
- #ifdef ENABLE_CHECKING
-   bitmap used_in_real_ops;
-   bitmap used_in_virtual_ops;
- 
-   used_in_real_ops = BITMAP_ALLOC (NULL);
-   used_in_virtual_ops = BITMAP_ALLOC (NULL);
- #endif
- 
    map = init_var_map (num_ssa_names);
  
    FOR_EACH_BB (bb)
--- 983,988 ----
*************** create_outofssa_var_map (coalesce_list_p
*** 1126,1142 ****
  	    default:
  	      break;
  	    }
- 
- #ifdef ENABLE_CHECKING
- 	  /* Mark real uses and defs.  */
- 	  FOR_EACH_SSA_TREE_OPERAND (var, stmt, iter, (SSA_OP_DEF|SSA_OP_USE))
- 	    bitmap_set_bit (used_in_real_ops, DECL_UID (SSA_NAME_VAR (var)));
- 
- 	  /* Validate that virtual ops don't get used in funny ways.  */
- 	  if (gimple_vuse (stmt))
- 	    bitmap_set_bit (used_in_virtual_ops,
- 			    DECL_UID (SSA_NAME_VAR (gimple_vuse (stmt))));
- #endif /* ENABLE_CHECKING */
  	}
      }
  
--- 1118,1123 ----
*************** create_outofssa_var_map (coalesce_list_p
*** 1173,1199 ****
  	}
      }
  
- #if defined ENABLE_CHECKING
-   {
-     unsigned i;
-     bitmap both = BITMAP_ALLOC (NULL);
-     bitmap_and (both, used_in_real_ops, used_in_virtual_ops);
-     if (!bitmap_empty_p (both))
-       {
- 	bitmap_iterator bi;
- 
- 	EXECUTE_IF_SET_IN_BITMAP (both, 0, i, bi)
- 	  fprintf (stderr, "Variable %s used in real and virtual operands\n",
- 		   get_name (referenced_var (i)));
- 	internal_error ("SSA corruption");
-       }
- 
-     BITMAP_FREE (used_in_real_ops);
-     BITMAP_FREE (used_in_virtual_ops);
-     BITMAP_FREE (both);
-   }
- #endif
- 
    return map;
  }
  
--- 1154,1159 ----
Index: gcc/tree-sra.c
===================================================================
*** gcc/tree-sra.c.orig	2012-08-01 11:16:45.000000000 +0200
--- gcc/tree-sra.c	2012-08-01 11:21:58.917121453 +0200
*************** struct access
*** 224,232 ****
       BIT_FIELD_REF?  */
    unsigned grp_partial_lhs : 1;
  
!   /* Set when a scalar replacement should be created for this variable.  We do
!      the decision and creation at different places because create_tmp_var
!      cannot be called from within FOR_EACH_REFERENCED_VAR. */
    unsigned grp_to_be_replaced : 1;
  
    /* Should TREE_NO_WARNING of a replacement be set?  */
--- 224,230 ----
       BIT_FIELD_REF?  */
    unsigned grp_partial_lhs : 1;
  
!   /* Set when a scalar replacement should be created for this variable.  */
    unsigned grp_to_be_replaced : 1;
  
    /* Should TREE_NO_WARNING of a replacement be set?  */
*************** static alloc_pool link_pool;
*** 269,276 ****
  /* Base (tree) -> Vector (VEC(access_p,heap) *) map.  */
  static struct pointer_map_t *base_access_vec;
  
! /* Bitmap of candidates.  */
  static bitmap candidate_bitmap;
  
  /* Bitmap of candidates which we should try to entirely scalarize away and
     those which cannot be (because they are and need be used as a whole).  */
--- 267,285 ----
  /* Base (tree) -> Vector (VEC(access_p,heap) *) map.  */
  static struct pointer_map_t *base_access_vec;
  
! /* Set of candidates.  */
  static bitmap candidate_bitmap;
+ static htab_t candidates;
+ 
+ /* For a candidate UID return the candidates decl.  */
+ 
+ static inline tree
+ candidate (unsigned uid)
+ {
+  struct tree_decl_minimal t;
+  t.uid = uid;
+  return (tree) htab_find_with_hash (candidates, &t, uid);
+ }
  
  /* Bitmap of candidates which we should try to entirely scalarize away and
     those which cannot be (because they are and need be used as a whole).  */
*************** static void
*** 600,605 ****
--- 609,616 ----
  sra_initialize (void)
  {
    candidate_bitmap = BITMAP_ALLOC (NULL);
+   candidates = htab_create (VEC_length (tree, cfun->local_decls) / 2,
+ 			    uid_decl_map_hash, uid_decl_map_eq, NULL);
    should_scalarize_away_bitmap = BITMAP_ALLOC (NULL);
    cannot_scalarize_away_bitmap = BITMAP_ALLOC (NULL);
    gcc_obstack_init (&name_obstack);
*************** static void
*** 631,636 ****
--- 642,648 ----
  sra_deinitialize (void)
  {
    BITMAP_FREE (candidate_bitmap);
+   htab_delete (candidates);
    BITMAP_FREE (should_scalarize_away_bitmap);
    BITMAP_FREE (cannot_scalarize_away_bitmap);
    free_alloc_pool (access_pool);
*************** sra_deinitialize (void)
*** 646,652 ****
  static void
  disqualify_candidate (tree decl, const char *reason)
  {
!   bitmap_clear_bit (candidate_bitmap, DECL_UID (decl));
  
    if (dump_file && (dump_flags & TDF_DETAILS))
      {
--- 658,667 ----
  static void
  disqualify_candidate (tree decl, const char *reason)
  {
!   if (bitmap_clear_bit (candidate_bitmap, DECL_UID (decl)))
!     htab_clear_slot (candidates,
! 		     htab_find_slot_with_hash (candidates, decl,
! 					       DECL_UID (decl), NO_INSERT));
  
    if (dump_file && (dump_flags & TDF_DETAILS))
      {
*************** static bool
*** 1639,1649 ****
  find_var_candidates (void)
  {
    tree var, type;
!   referenced_var_iterator rvi;
    bool ret = false;
    const char *msg;
  
!   FOR_EACH_REFERENCED_VAR (cfun, var, rvi)
      {
        if (TREE_CODE (var) != VAR_DECL && TREE_CODE (var) != PARM_DECL)
          continue;
--- 1654,1665 ----
  find_var_candidates (void)
  {
    tree var, type;
!   unsigned int i;
    bool ret = false;
    const char *msg;
+   void **slot;
  
!   FOR_EACH_LOCAL_DECL (cfun, i, var)
      {
        if (TREE_CODE (var) != VAR_DECL && TREE_CODE (var) != PARM_DECL)
          continue;
*************** find_var_candidates (void)
*** 1695,1700 ****
--- 1711,1718 ----
  	}
  
        bitmap_set_bit (candidate_bitmap, DECL_UID (var));
+       slot = htab_find_slot_with_hash (candidates, var, DECL_UID (var), INSERT);
+       *slot = (void *) var;
  
        if (dump_file && (dump_flags & TDF_DETAILS))
  	{
*************** analyze_all_variable_accesses (void)
*** 2335,2341 ****
      if (bitmap_bit_p (should_scalarize_away_bitmap, i)
  	&& !bitmap_bit_p (cannot_scalarize_away_bitmap, i))
        {
! 	tree var = referenced_var (i);
  
  	if (TREE_CODE (var) == VAR_DECL
  	    && type_consists_of_records_p (TREE_TYPE (var)))
--- 2353,2359 ----
      if (bitmap_bit_p (should_scalarize_away_bitmap, i)
  	&& !bitmap_bit_p (cannot_scalarize_away_bitmap, i))
        {
! 	tree var = candidate (i);
  
  	if (TREE_CODE (var) == VAR_DECL
  	    && type_consists_of_records_p (TREE_TYPE (var)))
*************** analyze_all_variable_accesses (void)
*** 2363,2369 ****
    bitmap_copy (tmp, candidate_bitmap);
    EXECUTE_IF_SET_IN_BITMAP (tmp, 0, i, bi)
      {
!       tree var = referenced_var (i);
        struct access *access;
  
        access = sort_and_splice_var_accesses (var);
--- 2381,2387 ----
    bitmap_copy (tmp, candidate_bitmap);
    EXECUTE_IF_SET_IN_BITMAP (tmp, 0, i, bi)
      {
!       tree var = candidate (i);
        struct access *access;
  
        access = sort_and_splice_var_accesses (var);
*************** analyze_all_variable_accesses (void)
*** 2377,2383 ****
    bitmap_copy (tmp, candidate_bitmap);
    EXECUTE_IF_SET_IN_BITMAP (tmp, 0, i, bi)
      {
!       tree var = referenced_var (i);
        struct access *access = get_first_repr_for_decl (var);
  
        if (analyze_access_trees (access))
--- 2395,2401 ----
    bitmap_copy (tmp, candidate_bitmap);
    EXECUTE_IF_SET_IN_BITMAP (tmp, 0, i, bi)
      {
!       tree var = candidate (i);
        struct access *access = get_first_repr_for_decl (var);
  
        if (analyze_access_trees (access))
*************** find_param_candidates (void)
*** 3424,3429 ****
--- 3442,3448 ----
         parm = DECL_CHAIN (parm))
      {
        tree type = TREE_TYPE (parm);
+       void **slot;
  
        count++;
  
*************** find_param_candidates (void)
*** 3462,3467 ****
--- 3481,3490 ----
  	continue;
  
        bitmap_set_bit (candidate_bitmap, DECL_UID (parm));
+       slot = htab_find_slot_with_hash (candidates, parm,
+ 				       DECL_UID (parm), INSERT);
+       *slot = (void *) parm;
+ 
        ret = true;
        if (dump_file && (dump_flags & TDF_DETAILS))
  	{


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