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] Optimize the default_defs hashtable


Just like the referenced_vars, we can avoid creating the uid, tree tuples.

Bootstrapped and tested on x86_64-unknown-linux-gnu, I will apply this
later together with the other patch.

Richard.

2007-10-18  Richard Guenther  <rguenther@suse.de>

	* tree-ssa.c (uid_ssaname_map_eq): New function.
	(uid_ssaname_map_has): Likewise.
	(init_tree_ssa): Allocate default_defs as uid_ssaname map.
	* tree-flow.h (struct gimple_df): Make default_defs a
	uid_ssaname map.
	* tree-dfa.c (gimple_default_def): Deal with it.
	(set_default_def): Likewise.

Index: pointer_plus/gcc/tree-dfa.c
===================================================================
*** pointer_plus.orig/gcc/tree-dfa.c	2007-10-18 11:52:17.000000000 +0200
--- pointer_plus/gcc/tree-dfa.c	2007-10-18 12:08:34.000000000 +0200
*************** referenced_var_check_and_insert (tree to
*** 675,689 ****
  tree 
  gimple_default_def (struct function *fn, tree var)
  {
!   struct int_tree_map *h, in;
    gcc_assert (SSA_VAR_P (var));
!   in.uid = DECL_UID (var);
!   h = (struct int_tree_map *) htab_find_with_hash (DEFAULT_DEFS (fn),
! 						   &in,
!                                                    DECL_UID (var));
!   if (h)
!     return h->to;
!   return NULL_TREE;
  }
  
  /* Insert the pair VAR's UID, DEF into the default_defs hashtable.  */
--- 675,686 ----
  tree 
  gimple_default_def (struct function *fn, tree var)
  {
!   struct tree_decl_minimal ind;
!   struct tree_ssa_name in;
    gcc_assert (SSA_VAR_P (var));
!   in.var = (tree)&ind;
!   ind.uid = DECL_UID (var);
!   return (tree) htab_find_with_hash (DEFAULT_DEFS (fn), &in, DECL_UID (var));
  }
  
  /* Insert the pair VAR's UID, DEF into the default_defs hashtable.  */
*************** gimple_default_def (struct function *fn,
*** 691,727 ****
  void
  set_default_def (tree var, tree def)
  { 
!   struct int_tree_map in;
!   struct int_tree_map *h;
    void **loc;
  
    gcc_assert (SSA_VAR_P (var));
!   in.uid = DECL_UID (var);
!   if (!def && gimple_default_def (cfun, var))
      {
        loc = htab_find_slot_with_hash (DEFAULT_DEFS (cfun), &in,
              DECL_UID (var), INSERT);
        htab_remove_elt (DEFAULT_DEFS (cfun), *loc);
        return;
      }
!   gcc_assert (!def || TREE_CODE (def) == SSA_NAME);
    loc = htab_find_slot_with_hash (DEFAULT_DEFS (cfun), &in,
                                    DECL_UID (var), INSERT);
  
    /* Default definition might be changed by tail call optimization.  */
!   if (!*loc)
!     {
!       h = GGC_NEW (struct int_tree_map);
!       h->uid = DECL_UID (var);
!       h->to = def;
!       *(struct int_tree_map **)  loc = h;
!     }
!    else
!     {
!       h = (struct int_tree_map *) *loc;
!       SSA_NAME_IS_DEFAULT_DEF (h->to) = false;
!       h->to = def;
!     }
  
     /* Mark DEF as the default definition for VAR.  */
     SSA_NAME_IS_DEFAULT_DEF (def) = true;
--- 688,716 ----
  void
  set_default_def (tree var, tree def)
  { 
!   struct tree_decl_minimal ind;
!   struct tree_ssa_name in;
    void **loc;
  
    gcc_assert (SSA_VAR_P (var));
!   in.var = (tree)&ind;
!   ind.uid = DECL_UID (var);
!   if (!def)
      {
        loc = htab_find_slot_with_hash (DEFAULT_DEFS (cfun), &in,
              DECL_UID (var), INSERT);
+       gcc_assert (*loc);
        htab_remove_elt (DEFAULT_DEFS (cfun), *loc);
        return;
      }
!   gcc_assert (TREE_CODE (def) == SSA_NAME && SSA_NAME_VAR (def) == var);
    loc = htab_find_slot_with_hash (DEFAULT_DEFS (cfun), &in,
                                    DECL_UID (var), INSERT);
  
    /* Default definition might be changed by tail call optimization.  */
!   if (*loc)
!     SSA_NAME_IS_DEFAULT_DEF (*(tree *) loc) = false;
!   *(tree *) loc = def;
  
     /* Mark DEF as the default definition for VAR.  */
     SSA_NAME_IS_DEFAULT_DEF (def) = true;
Index: pointer_plus/gcc/tree-flow.h
===================================================================
*** pointer_plus.orig/gcc/tree-flow.h	2007-10-18 11:44:51.000000000 +0200
--- pointer_plus/gcc/tree-flow.h	2007-10-18 12:02:59.000000000 +0200
*************** struct gimple_df GTY(())
*** 159,165 ****
       means that the first reference to this variable in the function is a
       USE or a VUSE.  In those cases, the SSA renamer creates an SSA name
       for this variable with an empty defining statement.  */
!   htab_t GTY((param_is (struct int_tree_map))) default_defs;
  
    /* 'true' after aliases have been computed (see compute_may_aliases).  */
    unsigned int aliases_computed_p : 1;
--- 159,165 ----
       means that the first reference to this variable in the function is a
       USE or a VUSE.  In those cases, the SSA renamer creates an SSA name
       for this variable with an empty defining statement.  */
!   htab_t GTY((param_is (union tree_node))) default_defs;
  
    /* 'true' after aliases have been computed (see compute_may_aliases).  */
    unsigned int aliases_computed_p : 1;
Index: pointer_plus/gcc/tree-ssa.c
===================================================================
*** pointer_plus.orig/gcc/tree-ssa.c	2007-10-18 11:44:51.000000000 +0200
--- pointer_plus/gcc/tree-ssa.c	2007-10-18 12:07:24.000000000 +0200
*************** var_ann_hash (const void *item)
*** 810,815 ****
--- 810,833 ----
    return ((const struct static_var_ann_d *)item)->uid;
  }
  
+ /* Return true if the DECL_UID in both trees are equal.  */
+ 
+ static int
+ uid_ssaname_map_eq (const void *va, const void *vb)
+ {
+   const_tree a = (const_tree) va;
+   const_tree b = (const_tree) vb;
+   return (a->ssa_name.var->decl_minimal.uid == b->ssa_name.var->decl_minimal.uid);
+ }
+ 
+ /* Hash a tree in a uid_decl_map.  */
+ 
+ static unsigned int
+ uid_ssaname_map_hash (const void *item)
+ {
+   return ((const_tree)item)->ssa_name.var->decl_minimal.uid;
+ }
+ 
  
  /* Initialize global DFA and SSA structures.  */
  
*************** init_tree_ssa (void)
*** 819,826 ****
    cfun->gimple_df = GGC_CNEW (struct gimple_df);
    cfun->gimple_df->referenced_vars = htab_create_ggc (20, uid_decl_map_hash, 
  				     		      uid_decl_map_eq, NULL);
!   cfun->gimple_df->default_defs = htab_create_ggc (20, int_tree_map_hash, 
! 				                   int_tree_map_eq, NULL);
    cfun->gimple_df->var_anns = htab_create_ggc (20, var_ann_hash, 
  					       var_ann_eq, NULL);
    cfun->gimple_df->call_clobbered_vars = BITMAP_GGC_ALLOC ();
--- 837,844 ----
    cfun->gimple_df = GGC_CNEW (struct gimple_df);
    cfun->gimple_df->referenced_vars = htab_create_ggc (20, uid_decl_map_hash, 
  				     		      uid_decl_map_eq, NULL);
!   cfun->gimple_df->default_defs = htab_create_ggc (20, uid_ssaname_map_hash, 
! 				                   uid_ssaname_map_eq, NULL);
    cfun->gimple_df->var_anns = htab_create_ggc (20, var_ann_hash, 
  					       var_ann_eq, NULL);
    cfun->gimple_df->call_clobbered_vars = BITMAP_GGC_ALLOC ();


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