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 a few more ggc htabs


From: Trevor Saunders <tsaunders@mozilla.com>

Hi,

$subject

bootstrapped + regtested x86_64-unknown-linux-gnu, ok?

Trev

gcc/

	* ipa-utils.c, lto-section-in.c, lto-streamer.h,
	tree-scalar-evolution.c: Replace htab with hash_table.

lto/

	* lto.c: Replace htab with hash_table.


diff --git a/gcc/ipa-utils.c b/gcc/ipa-utils.c
index 22900cc..7613205 100644
--- a/gcc/ipa-utils.c
+++ b/gcc/ipa-utils.c
@@ -438,17 +438,17 @@ ipa_merge_profiles (struct cgraph_node *dst,
      temporarily inconsistent.  */
   if (src->decl == dst->decl)
     {
-      void **slot;
       struct lto_in_decl_state temp;
       struct lto_in_decl_state *state;
 
       /* We are going to move the decl, we want to remove its file decl data.
 	 and link these with the new decl. */
       temp.fn_decl = src->decl;
-      slot = htab_find_slot (src->lto_file_data->function_decl_states,
-			     &temp, NO_INSERT);
-      state = (lto_in_decl_state *)*slot;
-      htab_clear_slot (src->lto_file_data->function_decl_states, slot);
+      lto_in_decl_state **slot
+	= src->lto_file_data->function_decl_states->find_slot (&temp,
+							       NO_INSERT);
+      state = *slot;
+      src->lto_file_data->function_decl_states->clear_slot (slot);
       gcc_assert (state);
 
       /* Duplicate the decl and be sure it does not link into body of DST.  */
@@ -461,8 +461,8 @@ ipa_merge_profiles (struct cgraph_node *dst,
       /* Associate the decl state with new declaration, so LTO streamer
  	 can look it up.  */
       state->fn_decl = src->decl;
-      slot = htab_find_slot (src->lto_file_data->function_decl_states,
-			     state, INSERT);
+      slot
+	= src->lto_file_data->function_decl_states->find_slot (state, INSERT);
       gcc_assert (!*slot);
       *slot = state;
     }
diff --git a/gcc/lto-section-in.c b/gcc/lto-section-in.c
index 75f394d..b9d742a 100644
--- a/gcc/lto-section-in.c
+++ b/gcc/lto-section-in.c
@@ -383,29 +383,6 @@ lto_delete_in_decl_state (struct lto_in_decl_state *state)
   ggc_free (state);
 }
 
-/* Hashtable helpers. lto_in_decl_states are hash by their function decls. */
-
-hashval_t
-lto_hash_in_decl_state (const void *p)
-{
-  const struct lto_in_decl_state *state = (const struct lto_in_decl_state *) p;
-  return htab_hash_pointer (state->fn_decl);
-}
-
-/* Return true if the fn_decl field of the lto_in_decl_state pointed to by
-   P1 equals to the function decl P2. */
-
-int
-lto_eq_in_decl_state (const void *p1, const void *p2)
-{
-  const struct lto_in_decl_state *state1 =
-   (const struct lto_in_decl_state *) p1;
-  const struct lto_in_decl_state *state2 =
-   (const struct lto_in_decl_state *) p2;
-  return state1->fn_decl == state2->fn_decl;
-}
-
-
 /* Search the in-decl state of a function FUNC contained in the file
    associated with FILE_DATA.  Return NULL if not found.  */
 
@@ -414,11 +391,11 @@ lto_get_function_in_decl_state (struct lto_file_decl_data *file_data,
 				tree func)
 {
   struct lto_in_decl_state temp;
-  void **slot;
+  lto_in_decl_state **slot;
 
   temp.fn_decl = func;
-  slot = htab_find_slot (file_data->function_decl_states, &temp, NO_INSERT);
-  return slot? ((struct lto_in_decl_state*) *slot) : NULL;
+  slot = file_data->function_decl_states->find_slot (&temp, NO_INSERT);
+  return slot? *slot : NULL;
 }
 
 /* Free decl_states.  */
@@ -439,19 +416,18 @@ void
 lto_free_function_in_decl_state_for_node (symtab_node *node)
 {
   struct lto_in_decl_state temp;
-  void **slot;
+  lto_in_decl_state **slot;
 
   if (!node->lto_file_data)
     return;
 
   temp.fn_decl = node->decl;
-  slot = htab_find_slot (node->lto_file_data->function_decl_states,
-			 &temp, NO_INSERT);
+  slot
+    = node->lto_file_data->function_decl_states->find_slot (&temp, NO_INSERT);
   if (slot && *slot)
     {
-      lto_free_function_in_decl_state ((struct lto_in_decl_state*) *slot);
-      htab_clear_slot (node->lto_file_data->function_decl_states,
-		       slot);
+      lto_free_function_in_decl_state (*slot);
+      node->lto_file_data->function_decl_states->clear_slot (slot);
     }
   node->lto_file_data = NULL;
 }
diff --git a/gcc/lto-streamer.h b/gcc/lto-streamer.h
index 9d6d7a0..ee2c7e3 100644
--- a/gcc/lto-streamer.h
+++ b/gcc/lto-streamer.h
@@ -429,7 +429,7 @@ struct lto_tree_ref_encoder
 
 
 /* Structure to hold states of input scope.  */
-struct GTY(()) lto_in_decl_state
+struct GTY((for_user)) lto_in_decl_state
 {
   /* Array of lto_in_decl_buffers to store type and decls streams. */
   vec<tree, va_gc> *streams[LTO_N_DECL_STREAMS];
@@ -441,6 +441,20 @@ struct GTY(()) lto_in_decl_state
 
 typedef struct lto_in_decl_state *lto_in_decl_state_ptr;
 
+struct decl_state_hasher : ggc_hasher<lto_in_decl_state *>
+{
+  static hashval_t
+  hash (lto_in_decl_state *s)
+  {
+    return htab_hash_pointer (s->fn_decl);
+  }
+
+  static bool
+  equal (lto_in_decl_state *a, lto_in_decl_state *b)
+  {
+    return a->fn_decl == b->fn_decl;
+  }
+};
 
 /* The structure that holds all of the vectors of global types,
    decls and cgraph nodes used in the serialization of this file.  */
@@ -487,7 +501,7 @@ struct GTY(()) lto_file_decl_data
   lto_symtab_encoder_t GTY((skip)) symtab_node_encoder;
 
   /* Hash table maps lto-related section names to location in file.  */
-  htab_t GTY((param_is (struct lto_in_decl_state))) function_decl_states;
+  hash_table<decl_state_hasher> *function_decl_states;
 
   /* The .o file that these offsets relate to.  */
   const char *GTY((skip)) file_name;
@@ -686,8 +700,6 @@ extern const char *lto_get_decl_name_mapping (struct lto_file_decl_data *,
 					      const char *);
 extern struct lto_in_decl_state *lto_new_in_decl_state (void);
 extern void lto_delete_in_decl_state (struct lto_in_decl_state *);
-extern hashval_t lto_hash_in_decl_state (const void *);
-extern int lto_eq_in_decl_state (const void *, const void *);
 extern struct lto_in_decl_state *lto_get_function_in_decl_state (
 				      struct lto_file_decl_data *, tree);
 extern void lto_free_function_in_decl_state (struct lto_in_decl_state *);
diff --git a/gcc/lto/lto.c b/gcc/lto/lto.c
index cdd2331..b5dd28b 100644
--- a/gcc/lto/lto.c
+++ b/gcc/lto/lto.c
@@ -1988,15 +1988,15 @@ lto_read_decls (struct lto_file_decl_data *decl_data, const void *data,
 
   /* Read in per-function decl states and enter them in hash table.  */
   decl_data->function_decl_states =
-    htab_create_ggc (37, lto_hash_in_decl_state, lto_eq_in_decl_state, NULL);
+    hash_table<decl_state_hasher>::create_ggc (37);
 
   for (i = 1; i < num_decl_states; i++)
     {
       struct lto_in_decl_state *state = lto_new_in_decl_state ();
-      void **slot;
 
       data_ptr = lto_read_in_decl_state (data_in, data_ptr, state);
-      slot = htab_find_slot (decl_data->function_decl_states, state, INSERT);
+      lto_in_decl_state **slot
+	= decl_data->function_decl_states->find_slot (state, INSERT);
       gcc_assert (*slot == NULL);
       *slot = state;
     }
@@ -2825,17 +2825,6 @@ lto_fixup_state (struct lto_in_decl_state *state)
     }
 }
 
-/* A callback of htab_traverse. Just extracts a state from SLOT
-   and calls lto_fixup_state. */
-
-static int
-lto_fixup_state_aux (void **slot, void *aux ATTRIBUTE_UNUSED)
-{
-  struct lto_in_decl_state *state = (struct lto_in_decl_state *) *slot;
-  lto_fixup_state (state);
-  return 1;
-}
-
 /* Fix the decls from all FILES. Replaces each decl with the corresponding
    prevailing one.  */
 
@@ -2855,7 +2844,11 @@ lto_fixup_decls (struct lto_file_decl_data **files)
       struct lto_in_decl_state *state = file->global_decl_state;
       lto_fixup_state (state);
 
-      htab_traverse (file->function_decl_states, lto_fixup_state_aux, NULL);
+      hash_table<decl_state_hasher>::iterator iter;
+      lto_in_decl_state *elt;
+      FOR_EACH_HASH_TABLE_ELEMENT (*file->function_decl_states, elt,
+				   lto_in_decl_state *, iter)
+	lto_fixup_state (elt);
     }
 }
 
diff --git a/gcc/tree-scalar-evolution.c b/gcc/tree-scalar-evolution.c
index 4d03896..b8bdaf5 100644
--- a/gcc/tree-scalar-evolution.c
+++ b/gcc/tree-scalar-evolution.c
@@ -307,7 +307,7 @@ static tree analyze_scalar_evolution_for_address_of (struct loop *loop,
    claiming that below basic block with index INSTANTIATED_BELOW, the
    value of the SSA name can be expressed as CHREC.  */
 
-struct GTY(()) scev_info_str {
+struct GTY((for_user)) scev_info_str {
   unsigned int name_version;
   int instantiated_below;
   tree chrec;
@@ -332,7 +332,13 @@ tree chrec_dont_know;
    happen, then it qualifies it with chrec_known.  */
 tree chrec_known;
 
-static GTY ((param_is (struct scev_info_str))) htab_t scalar_evolution_info;
+struct scev_info_hasher : ggc_hasher<scev_info_str *>
+{
+  static hashval_t hash (scev_info_str *i);
+  static bool equal (const scev_info_str *a, const scev_info_str *b);
+};
+
+static GTY (()) hash_table<scev_info_hasher> *scalar_evolution_info;
 
 
 /* Constructs a new SCEV_INFO_STR structure for VAR and INSTANTIATED_BELOW.  */
@@ -352,34 +358,21 @@ new_scev_info_str (basic_block instantiated_below, tree var)
 
 /* Computes a hash function for database element ELT.  */
 
-static inline hashval_t
-hash_scev_info (const void *elt_)
+hashval_t
+scev_info_hasher::hash (scev_info_str *elt)
 {
-  const struct scev_info_str *elt = (const struct scev_info_str *) elt_;
   return elt->name_version ^ elt->instantiated_below;
 }
 
 /* Compares database elements E1 and E2.  */
 
-static inline int
-eq_scev_info (const void *e1, const void *e2)
+bool
+scev_info_hasher::equal (const scev_info_str *elt1, const scev_info_str *elt2)
 {
-  const struct scev_info_str *elt1 = (const struct scev_info_str *) e1;
-  const struct scev_info_str *elt2 = (const struct scev_info_str *) e2;
-
   return (elt1->name_version == elt2->name_version
 	  && elt1->instantiated_below == elt2->instantiated_below);
 }
 
-/* Deletes database element E.  */
-
-static void
-del_scev_info (void *e)
-{
-  ggc_free (e);
-}
-
-
 /* Get the scalar evolution of VAR for INSTANTIATED_BELOW basic block.
    A first query on VAR returns chrec_not_analyzed_yet.  */
 
@@ -388,15 +381,14 @@ find_var_scev_info (basic_block instantiated_below, tree var)
 {
   struct scev_info_str *res;
   struct scev_info_str tmp;
-  PTR *slot;
 
   tmp.name_version = SSA_NAME_VERSION (var);
   tmp.instantiated_below = instantiated_below->index;
-  slot = htab_find_slot (scalar_evolution_info, &tmp, INSERT);
+  scev_info_str **slot = scalar_evolution_info->find_slot (&tmp, INSERT);
 
   if (!*slot)
     *slot = new_scev_info_str (instantiated_below, var);
-  res = (struct scev_info_str *) *slot;
+  res = *slot;
 
   return &res->chrec;
 }
@@ -2201,7 +2193,7 @@ static inline hashval_t
 hash_idx_scev_info (const void *elt_)
 {
   unsigned idx = ((size_t) elt_) - 2;
-  return hash_scev_info (&global_cache->entries[idx]);
+  return scev_info_hasher::hash (&global_cache->entries[idx]);
 }
 
 /* Compares database elements E1 and E2.  */
@@ -2210,7 +2202,8 @@ static inline int
 eq_idx_scev_info (const void *e1, const void *e2)
 {
   unsigned idx1 = ((size_t) e1) - 2;
-  return eq_scev_info (&global_cache->entries[idx1], e2);
+  return scev_info_hasher::equal (&global_cache->entries[idx1],
+				  (const scev_info_str *) e2);
 }
 
 /* Returns from CACHE the slot number of the cached chrec for NAME.  */
@@ -2229,7 +2222,7 @@ get_instantiated_value_entry (instantiate_cache_type &cache,
   e.name_version = SSA_NAME_VERSION (name);
   e.instantiated_below = instantiate_below->index;
   void **slot = htab_find_slot_with_hash (cache.map, &e,
-					  hash_scev_info (&e), INSERT);
+					  scev_info_hasher::hash (&e), INSERT);
   if (!*slot)
     {
       e.chrec = chrec_not_analyzed_yet;
@@ -3044,7 +3037,7 @@ dump_chrecs_stats (FILE *file, struct chrec_stats *stats)
 	   stats->nb_undetermined);
   fprintf (file, "-----------------------------------------\n");
   fprintf (file, "%d\tchrecs in the scev database\n",
-	   (int) htab_elements (scalar_evolution_info));
+	   (int) scalar_evolution_info->elements ());
   fprintf (file, "%d\tsets in the scev database\n", nb_set_scev);
   fprintf (file, "%d\tgets in the scev database\n", nb_get_scev);
   fprintf (file, "-----------------------------------------\n");
@@ -3110,19 +3103,6 @@ gather_chrec_stats (tree chrec, struct chrec_stats *stats)
     fprintf (dump_file, ")\n");
 }
 
-/* Callback for htab_traverse, gathers information on chrecs in the
-   hashtable.  */
-
-static int
-gather_stats_on_scev_database_1 (void **slot, void *stats)
-{
-  struct scev_info_str *entry = (struct scev_info_str *) *slot;
-
-  gather_chrec_stats (entry->chrec, (struct chrec_stats *) stats);
-
-  return 1;
-}
-
 /* Classify the chrecs of the whole database.  */
 
 void
@@ -3135,8 +3115,11 @@ gather_stats_on_scev_database (void)
 
   reset_chrecs_counters (&stats);
 
-  htab_traverse (scalar_evolution_info, gather_stats_on_scev_database_1,
-		 &stats);
+  hash_table<scev_info_hasher>::iterator iter;
+  scev_info_str *elt;
+  FOR_EACH_HASH_TABLE_ELEMENT (*scalar_evolution_info, elt, scev_info_str *,
+			       iter)
+    gather_chrec_stats (elt->chrec, &stats);
 
   dump_chrecs_stats (dump_file, &stats);
 }
@@ -3166,8 +3149,7 @@ scev_initialize (void)
 {
   struct loop *loop;
 
-  scalar_evolution_info = htab_create_ggc (100, hash_scev_info, eq_scev_info,
-					   del_scev_info);
+  scalar_evolution_info = hash_table<scev_info_hasher>::create_ggc (100);
 
   initialize_scalar_evolutions_analyzer ();
 
@@ -3194,7 +3176,7 @@ scev_reset_htab (void)
   if (!scalar_evolution_info)
     return;
 
-  htab_empty (scalar_evolution_info);
+  scalar_evolution_info->empty ();
 }
 
 /* Cleans up the information cached by the scalar evolutions analysis
@@ -3289,7 +3271,7 @@ scev_finalize (void)
 {
   if (!scalar_evolution_info)
     return;
-  htab_delete (scalar_evolution_info);
+  scalar_evolution_info->empty ();
   scalar_evolution_info = NULL;
 }
 
-- 
2.1.3


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