diff options
author | Lawrence Crowl <crowl@google.com> | 2013-04-23 22:00:12 +0000 |
---|---|---|
committer | Lawrence Crowl <crowl@gcc.gnu.org> | 2013-04-23 22:00:12 +0000 |
commit | bf190e8df270025e2d0729858c031eb4ef7d49d2 (patch) | |
tree | fd9e547e6ac26ffd9c7200538fb2582c9ab2c3dc /gcc/statistics.c | |
parent | 4a8043c4e02c8c2517424722ba3055a159b93e87 (diff) | |
download | gcc-bf190e8df270025e2d0729858c031eb4ef7d49d2.zip gcc-bf190e8df270025e2d0729858c031eb4ef7d49d2.tar.gz gcc-bf190e8df270025e2d0729858c031eb4ef7d49d2.tar.bz2 |
This patch extracts approved portions of the hash_table patches to the...
This patch extracts approved portions of the hash_table patches to
the cxx-conversion branch for files not under gcc/config.
Update various hash tables from htab_t to hash_table.
Modify types and calls to match.
* tree-ssa-coalesce.c'coalesce_list_d.list from htab_t to hash_table.
Fold coalesce_pair_map_hash and coalesce_pair_map_eq into new
struct coalesce_pair_hasher.
Removed struct coalesce_pair_iterator, as did not meet the hash_table
iterator interface and it provided no significant code reduction.
This leads to a change in the implementation of FOR_EACH_PARTITION_PAIR.
* statistics.c'statistics_hashes
Fold hash_statistics_eq into new struct stats_counter_hasher.
* hash-table.h'hash_table
Add documentation.
Add nested class iterator and methods to hash_table.
Add FOR_EACH_HASH_TABLE_ELEMENT implemented with those iterators.
Change uses of FOR_EACH_HTAB_ELEMENT to FOR_EACH_HASH_TABLE_ELEMENT.
* tree-ssa-sccvn.c'vn_tables_s.nary
Fold vn_nary_op_hash, vn_nary_op_eq into new struct vn_nary_op_hasher.
Add typedef vn_nary_op_table_type.
Add typedef vn_nary_op_iterator_type.
* tree-ssa-sccvn.c'vn_tables_s.phis
Fold vn_phi_hash, free_phi into new struct vn_phi_hasher.
Add typedef vn_phi_table_type.
Add typedef vn_phi_iterator_type.
* tree-ssa-sccvn.c'vn_tables_s.references
Fold vn_reference_hash, vn_reference_op_eq, free_reference
into new struct vn_reference_hasher.
Add typedef vn_reference_table_type.
Add typedef vn_reference_iterator_type.
* tree-ssa-sccvn.c'constant_value_ids
Fold vn_constant_hash, vn_constant_eq into new struct vn_constant_hasher.
* tree-into-ssa.c'var_infos
Fold var_info_hash, var_info_eq into new struct var_info_hasher.
* tree-vectorizer.h'_loop_vec_info::peeling_htab
* tree-vectorizer.h
New struct peel_info_hasher.
* tree-vect-loop.c
Update dependent calls and types to match.
* tree-vect-data-refs.c
Fold vect_peeling_hash and vect_peeling_hash_eq into struct peel_info_hasher.
* tree-ssa-reassoc.c'undistribute_ops_list::ctable
Fold oecount_hash and oecount_eq into new struct oecount_hasher.
* tree-ssa-loop-im.c'memory_accesses.refs
Fold memref_hash and memref_eq into new struct mem_ref_hasher.
Tested on x86_64.
Index: gcc/ChangeLog
2013-04-23 Lawrence Crowl <crowl@google.com>
* Makefile.in: Update as needed below.
* hash-table.h (class hash_table):
Correct many methods with parameter types compare_type to the correct
value_type. (Correct code was unlikely to notice the change.)
(hash_table::elements_with_deleted) New.
(class hashtable::iterator): New.
(hashtable::begin()): New.
(hashtable::end()): New.
(FOR_EACH_HASH_TABLE_ELEMENT): New.
* statistics.c (statistics_hashes):
Change type to hash_table. Update dependent calls and types.
* tree-into-ssa.c (var_infos):
Change type to hash_table. Update dependent calls and types.
* tree-ssa-coalesce.c (struct coalesce_list_d.list):
Change type to hash_table. Update dependent calls and types.
* tree-ssa-loop-im.c (struct mem_ref.refs):
Change type to hash_table. Update dependent calls and types.
* tree-ssa-reassoc.c (undistribute_ops_list::ctable):
Change type to hash_table. Update dependent calls and types.
* tree-ssa-sccvn.c (vn_tables_s::nary):
Change type to hash_table. Update dependent calls and types.
(vn_tables_s::phis): Likewise.
(vn_tables_s::references): Likewise.
* tree-ssa-sccvn.h (vn_nary_op_eq): Update parameter and return types.
(vn_reference_eq): Update parameter and return types.
* tree-ssa-structalias.c (pointer_equiv_class_table):
Change type to hash_table. Update dependent calls and types.
(location_equiv_class_table): Likewise.
* tree-vect-data-refs.c: Consequential changes for making
peeling a hash_table.
* tree-vect-loop.c (new_loop_vec_info): Dependent hash_table update.
(destroy_loop_vec_info): Dependent hash_table update.
* tree-vectorizer.h (peeling_htab):
Change type to hash_table. Update dependent calls and types.
From-SVN: r198213
Diffstat (limited to 'gcc/statistics.c')
-rw-r--r-- | gcc/statistics.c | 105 |
1 files changed, 59 insertions, 46 deletions
diff --git a/gcc/statistics.c b/gcc/statistics.c index 3b9685d..3077cc0 100644 --- a/gcc/statistics.c +++ b/gcc/statistics.c @@ -24,7 +24,7 @@ along with GCC; see the file COPYING3. If not see #include "tree-pass.h" #include "tree-dump.h" #include "statistics.h" -#include "hashtab.h" +#include "hash-table.h" #include "function.h" static int statistics_dump_nr; @@ -42,42 +42,52 @@ typedef struct statistics_counter_s { unsigned HOST_WIDE_INT prev_dumped_count; } statistics_counter_t; -/* Array of statistic hashes, indexed by pass id. */ -static htab_t *statistics_hashes; -static unsigned nr_statistics_hashes; +/* Hashtable helpers. */ + +struct stats_counter_hasher +{ + typedef statistics_counter_t value_type; + typedef statistics_counter_t compare_type; + static inline hashval_t hash (const value_type *); + static inline bool equal (const value_type *, const compare_type *); + static inline void remove (value_type *); +}; /* Hash a statistic counter by its string ID. */ -static hashval_t -hash_statistics_hash (const void *p) +inline hashval_t +stats_counter_hasher::hash (const value_type *c) { - const statistics_counter_t *const c = (const statistics_counter_t *)p; return htab_hash_string (c->id) + c->val; } /* Compare two statistic counters by their string IDs. */ -static int -hash_statistics_eq (const void *p, const void *q) +inline bool +stats_counter_hasher::equal (const value_type *c1, const compare_type *c2) { - const statistics_counter_t *const c1 = (const statistics_counter_t *)p; - const statistics_counter_t *const c2 = (const statistics_counter_t *)q; return c1->val == c2->val && strcmp (c1->id, c2->id) == 0; } /* Free a statistics entry. */ -static void -hash_statistics_free (void *p) +inline void +stats_counter_hasher::remove (value_type *v) { - free (CONST_CAST(char *, ((statistics_counter_t *)p)->id)); - free (p); + free (CONST_CAST(char *, v->id)); + free (v); } +typedef hash_table <stats_counter_hasher> stats_counter_table_type; + +/* Array of statistic hashes, indexed by pass id. */ +static stats_counter_table_type *statistics_hashes; +static unsigned nr_statistics_hashes; + /* Return the current hashtable to be used for recording or printing statistics. */ -static htab_t +static stats_counter_table_type curr_statistics_hash (void) { unsigned idx; @@ -86,20 +96,20 @@ curr_statistics_hash (void) idx = current_pass->static_pass_number; if (idx < nr_statistics_hashes - && statistics_hashes[idx] != NULL) + && statistics_hashes[idx].is_created ()) return statistics_hashes[idx]; if (idx >= nr_statistics_hashes) { - statistics_hashes = XRESIZEVEC (struct htab *, statistics_hashes, idx+1); + statistics_hashes = XRESIZEVEC (stats_counter_table_type, + statistics_hashes, idx+1); memset (statistics_hashes + nr_statistics_hashes, 0, - (idx + 1 - nr_statistics_hashes) * sizeof (htab_t)); + (idx + 1 - nr_statistics_hashes) + * sizeof (stats_counter_table_type)); nr_statistics_hashes = idx + 1; } - statistics_hashes[idx] = htab_create (15, hash_statistics_hash, - hash_statistics_eq, - hash_statistics_free); + statistics_hashes[idx].create (15); return statistics_hashes[idx]; } @@ -107,10 +117,11 @@ curr_statistics_hash (void) /* Helper for statistics_fini_pass. Print the counter difference since the last dump for the pass dump files. */ -static int -statistics_fini_pass_1 (void **slot, void *data ATTRIBUTE_UNUSED) +int +statistics_fini_pass_1 (statistics_counter_t **slot, + void *data ATTRIBUTE_UNUSED) { - statistics_counter_t *counter = (statistics_counter_t *)*slot; + statistics_counter_t *counter = *slot; unsigned HOST_WIDE_INT count = counter->count - counter->prev_dumped_count; if (count == 0) return 1; @@ -127,10 +138,11 @@ statistics_fini_pass_1 (void **slot, void *data ATTRIBUTE_UNUSED) /* Helper for statistics_fini_pass. Print the counter difference since the last dump for the statistics dump. */ -static int -statistics_fini_pass_2 (void **slot, void *data ATTRIBUTE_UNUSED) +int +statistics_fini_pass_2 (statistics_counter_t **slot, + void *data ATTRIBUTE_UNUSED) { - statistics_counter_t *counter = (statistics_counter_t *)*slot; + statistics_counter_t *counter = *slot; unsigned HOST_WIDE_INT count = counter->count - counter->prev_dumped_count; if (count == 0) return 1; @@ -157,10 +169,11 @@ statistics_fini_pass_2 (void **slot, void *data ATTRIBUTE_UNUSED) /* Helper for statistics_fini_pass, reset the counters. */ -static int -statistics_fini_pass_3 (void **slot, void *data ATTRIBUTE_UNUSED) +int +statistics_fini_pass_3 (statistics_counter_t **slot, + void *data ATTRIBUTE_UNUSED) { - statistics_counter_t *counter = (statistics_counter_t *)*slot; + statistics_counter_t *counter = *slot; counter->prev_dumped_count = counter->count; return 1; } @@ -179,26 +192,25 @@ statistics_fini_pass (void) fprintf (dump_file, "\n"); fprintf (dump_file, "Pass statistics:\n"); fprintf (dump_file, "----------------\n"); - htab_traverse_noresize (curr_statistics_hash (), - statistics_fini_pass_1, NULL); + curr_statistics_hash () + .traverse_noresize <void *, statistics_fini_pass_1> (NULL); fprintf (dump_file, "\n"); } if (statistics_dump_file && !(statistics_dump_flags & TDF_STATS || statistics_dump_flags & TDF_DETAILS)) - htab_traverse_noresize (curr_statistics_hash (), - statistics_fini_pass_2, NULL); - htab_traverse_noresize (curr_statistics_hash (), - statistics_fini_pass_3, NULL); + curr_statistics_hash () + .traverse_noresize <void *, statistics_fini_pass_2> (NULL); + curr_statistics_hash () + .traverse_noresize <void *, statistics_fini_pass_3> (NULL); } /* Helper for printing summary information. */ -static int -statistics_fini_1 (void **slot, void *data) +int +statistics_fini_1 (statistics_counter_t **slot, opt_pass *pass) { - struct opt_pass *pass = (struct opt_pass *)data; - statistics_counter_t *counter = (statistics_counter_t *)*slot; + statistics_counter_t *counter = *slot; if (counter->count == 0) return 1; if (counter->histogram_p) @@ -230,10 +242,11 @@ statistics_fini (void) { unsigned i; for (i = 0; i < nr_statistics_hashes; ++i) - if (statistics_hashes[i] != NULL + if (statistics_hashes[i].is_created () && get_pass_for_id (i) != NULL) - htab_traverse_noresize (statistics_hashes[i], - statistics_fini_1, get_pass_for_id (i)); + statistics_hashes[i] + .traverse_noresize <opt_pass *, statistics_fini_1> + (get_pass_for_id (i)); } dump_end (statistics_dump_nr, statistics_dump_file); @@ -261,14 +274,14 @@ statistics_init (void) and HISTOGRAM_P. */ static statistics_counter_t * -lookup_or_add_counter (htab_t hash, const char *id, int val, +lookup_or_add_counter (stats_counter_table_type hash, const char *id, int val, bool histogram_p) { statistics_counter_t **counter; statistics_counter_t c; c.id = id; c.val = val; - counter = (statistics_counter_t **) htab_find_slot (hash, &c, INSERT); + counter = hash.find_slot (&c, INSERT); if (!*counter) { *counter = XNEW (struct statistics_counter_s); |