diff options
author | Lawrence Crowl <crowl@google.com> | 2013-04-26 00:28:35 +0000 |
---|---|---|
committer | Lawrence Crowl <crowl@gcc.gnu.org> | 2013-04-26 00:28:35 +0000 |
commit | 4a8fb1a1de7c34fc788ccca21f3a15980bbce093 (patch) | |
tree | 5115f0a81b7cea52ab7997ce3322160f2baf2374 /gcc/ggc-common.c | |
parent | 11dae3ad79feec9dda4610f1f9adbc742a2b3661 (diff) | |
download | gcc-4a8fb1a1de7c34fc788ccca21f3a15980bbce093.zip gcc-4a8fb1a1de7c34fc788ccca21f3a15980bbce093.tar.gz gcc-4a8fb1a1de7c34fc788ccca21f3a15980bbce093.tar.bz2 |
This patch is the main part of a consolodation of the hash_table patches to the...
This patch is the main part of a consolodation 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-parloops.c'reduction
* tree-parloops.c'name_to_copy
Fold reduction_info_hash and reduction_info_eq into new struct
reduction_hasher. Fold name_to_copy_elt_eq and name_to_copy_elt_hash
into new struct name_to_copy_hasher.
* trans-mem.c'tm_log
Fold tm_log_hash, tm_log_eq, tm_log_free into new struct log_entry_hasher.
* trans-mem.c'tm_memopt_value_numbers
Fold tm_memop_hash, tm_memop_eq into new struct tm_memop_hasher.
* tree-ssa-strlen.c'decl_to_stridxlist_htab
Fold decl_to_stridxlist_hash into new struct stridxlist_hasher.
* tree-ssa-loop-ivopts.c'ivopts_data::inv_expr_tab
Fold htab_inv_expr_hash and htab_inv_expr_eq into new struct
iv_inv_expr_hasher.
* tree-ssa-uncprop.c'equiv
Equiv renamed to val_ssa_equiv because of name ambiguity with local variables.
Fold equiv_hash, equiv_eq and equiv_free into new struct val_ssa_equiv_hasher.
Renamed variables equiv_hash_elt to an_equiv_elt because of name ambiguity
with struct type. Changed equiv_hash_elt_p to an_equiv_elt_p to match.
* tree-ssa-phiopt.c'seen_ssa_names
Fold name_to_bb_hash and name_to_bb_eq into new struct ssa_names_hasher.
* tree-ssa-structalias.c'pointer_equiv_class_table
* tree-ssa-structalias.c'location_equiv_class_table
Fold equiv_class_label_hash and equiv_class_label_eq into new
struct equiv_class_hasher.
* tree-ssa-structalias.c'shared_bitmap_table
Fold shared_bitmap_hash and shared_bitmap_eq into new struct
shared_bitmap_hasher.
* tree-ssa-live.c'var_map_base_init::tree_to_index
New struct tree_int_map_hasher.
* tree-sra.c'candidates
Fold uid_decl_map_hash and uid_decl_map_eq into new struct
uid_decl_hasher. This change moves the definitions from tree-ssa.c
into tree-sra.c and removes the declarations from tree-flow.h
tree-browser.c
Remove stale declaration of removed TB_parent_eq.
Fix template parameter for base class to match value_type.
gimple.h
Use gimplify_hasher::hash rather than gimple_tree_hash in the
assertion check.
Change return values to match return type. (I.e. no conversions.)
* graphite-clast-to-gimple.c'ivs_params::newivs_index
* graphite-clast-to-gimple.c'ivs_params::params_index
* graphite-clast-to-gimple.c'print_generated_program::params_index
* graphite-clast-to-gimple.c'gloog::newivs_index
* graphite-clast-to-gimple.c'gloog::params_index
* graphite.c graphite_transform_loops::bb_pbb_mapping
* sese.c copy_bb_and_scalar_dependences::rename_map
Move hash table declarations to a new graphite-htab.h, because they
are used in few places.
Remove unused:
htab_t scop::original_pddrs
SCOP_ORIGINAL_PDDRS
Remove unused:
insert_loop_close_phis
insert_guard_phis
debug_ivtype_map
ivtype_map_elt_info
new_ivtype_map_elt
* gimplify.c'gimplify_ctx::temp_htab
Move struct gimple_temp_hash_elt and struct gimplify_ctx to a new
gimplify-ctx.h, because they are used few places.
* cselib.c'cselib_hash_table
* gcse.c'pre_ldst_table
* gimple-ssa-strength-reduction.c'base_cand_map
* haifa-sched.c'delay_htab
* haifa-sched.c'delay_htab_i2
* ira-color.c'allocno_hard_regs_htab
* ira-costs.c'cost_classes_htab
* loop-invariant.c'merge_identical_invariants::eq
* loop-iv.c'bivs
* loop-unroll.c'opt_info::insns_to_split
* loop-unroll.c'opt_info::insns_with_var_to_expand
* passes.c'name_to_pass_map
* plugin.c'event_tab
* postreload-gcse.c'expr_table
* store-motion.c'store_motion_mems_table
* tree-cfg.c'discriminator_per_locus
* tree-scalar-evolution.c'resolve_mixers::cache
* tree-ssa-dom.c'avail_exprs
Remove unused:
dse.c bitmap clear_alias_sets
dse.c bitmap disqualified_clear_alias_sets
dse.c alloc_pool clear_alias_mode_pool
dse.c dse_step2_spill
dse.c dse_step5_spill
graphds.h htab_t graph::indices
* attribs.c'scoped_attributes::attribute_hash
* bitmap.c'bitmap_desc_hash
* dwarf2cfi.c'trace_index
* dwarf2out.c'break_out_includes::cu_hash_table
* dwarf2out.c'copy_decls_for_unworthy_types::decl_table
* dwarf2out.c'optimize_external_refs::map
* dwarf2out.c'output_comp_unit::extern_map
* dwarf2out.c'output_comdat_type_unit::extern_map
* dwarf2out.c'output_macinfo::macinfo_htab
* dwarf2out.c'optimize_location_lists::htab
* dwarf2out.c'dwarf2out_finish::comdat_type_table
* except.c'ehspec_hash_type
* except.c'assign_filter_values::ttypes
* except.c'assign_filter_values::ehspec
* except.c'sjlj_assign_call_site_values::ar_hash
* except.c'convert_to_eh_region_ranges::ar_hash
* trans-mem.c'tm_new_mem_hash
* tree-browser.c'TB_up_ht
* tree-eh.c'finally_tree
Move the declaration of hash_table <alloc_pool_hasher> alloc_pool_hash
in alloc-pool.c to after the method definitions for its parameter
class.
* ggc-common.c'loc_hash
* ggc-common.c'ptr_hash
Add a new hash_table method elements_with_deleted to meet the needs of
gcc-common.c.
Correct many methods with parameter types compare_type to the correct
value_type. (Correct code was unlikely to notice the change, but
incorrect code will.)
* tree-complex.c'complex_variable_components
* tree-parloops.c'eliminate_local_variables_stmt::decl_address
* tree-parloops.c'separate_decls_in_region::decl_copies
Move hash table declarations to a new tree-hasher.h, to resolve
compilation dependences and because they are used in few places.
* lto-streamer.h'output_block::string_hash_table
* lto-streamer-in.c'file_name_hash_table
* lto-streamer.c'tree_htab
The struct string_slot moves from data-streamer.h to lto-streamer.h to
resolve compilation dependences.
Tested on x86_64.
Index: gcc/ChangeLog
2013-04-25 Lawrence Crowl <crowl@google.com>
* Makefile.in: Update as needed below.
* alloc-pool.c (static hash_table <alloc_pool_hasher> alloc_pool_hash):
Move declaration to after the type's method definitons.
* attribs.c (htab_t scoped_attributes::attribute_hash):
Change type to hash_table. Update dependent calls and types.
* bitmap.c (htab_t bitmap_desc_hash):
Change type to hash_table. Update dependent calls and types.
* cselib.c (htab_t cselib_hash_table):
Change type to hash_table. Update dependent calls and types.
* data-streamer.h (struct string_slot): Move to lto-streamer.h.
(hash_string_slot_node): Move implementation into lto-streamer.h
struct string_slot_hasher.
(eq_string_slot_node): Likewise.
* data-streamer-out.c: Update output_block::string_hash_table
dependent calls and types.
* dwarf2cfi.c (htab_t trace_index):
Change type to hash_table. Update dependent calls and types.
* dwarf2out.c (htab_t break_out_includes::cu_hash_table):
Change type to hash_table. Update dependent calls and types.
(htab_t copy_decls_for_unworthy_types::decl_table): Likewise.
(htab_t optimize_external_refs::map): Likewise.
(htab_t output_comp_unit::extern_map): Likewise.
(htab_t output_comdat_type_unit::extern_map): Likewise.
(htab_t output_macinfo::macinfo_htab): Likewise.
(htab_t optimize_location_lists::htab): Likewise.
(htab_t dwarf2out_finish::comdat_type_table): Likewise.
* except.c (htab_t ehspec_hash_type):
Change type to hash_table. Update dependent calls and types.
(assign_filter_values::ttypes): Likewise.
(assign_filter_values::ehspec): Likewise.
(sjlj_assign_call_site_values::ar_hash): Likewise.
(convert_to_eh_region_ranges::ar_hash): Likewise.
* gcse.c (htab_t pre_ldst_table):
Change type to hash_table. Update dependent calls and types.
* ggc-common.c (htab_t saving_htab):
Change type to hash_table. Update dependent calls and types.
(htab_t loc_hash): Likewise.
(htab_t ptr_hash): Likewise.
(call_count): Rename ggc_call_count.
(call_alloc): Rename ggc_call_alloc.
(loc_descriptor): Rename make_loc_descriptor.
(add_statistics): Rename ggc_add_statistics.
* ggc-common.c (saving_htab):
Change type to hash_table. Update dependent calls and types.
* gimple.h (struct gimplify_ctx): Move to gimplify-ctx.h.
(push_gimplify_context): Likewise.
(pop_gimplify_context): Likewise.
(struct gimple_temp_hash_elt): Added.
(struct gimplify_hasher): Likewise.
(struct gimplify_ctx.temp_htab):
Change type to hash_table. Update dependent calls and types.
* gimple-fold.c: Include gimplify-ctx.h.
* gimple-ssa-strength-reduction.c (htab_t base_cand_map):
Change type to hash_table. Update dependent calls and types.
(base_cand_dump_callback): Rename to ssa_base_cand_dump_callback to
avoid potential global name collision.
* gimplify.c: Include gimplify-ctx.h.
(struct gimple_temp_hash_elt): Move to gimplify-ctx.h.
(htab_t gimplify_ctx::temp_htab):
Update dependent calls and types for new type hash_table.
(gimple_tree_hash): Move into gimplify_hasher in gimplify-ctx.h.
(gimple_tree_eq): Move into gimplify_hasher in gimplify-ctx.h.
* gimplify-ctx.h: New.
(struct gimple_temp_hash_elt): Move from gimplify.c.
(class gimplify_hasher): New.
(struct gimplify_ctx): Move from gimple.h.
(htab_t gimplify_ctx::temp_htab):
Change type to hash_table. Update dependent calls and types.
* graphite-clast-to-gimple.c: Include graphite-htab.h.
(htab_t ivs_params::newivs_index):
Change type to hash_table. Update dependent calls and types.
(htab_t ivs_params::params_index): Likewise.
(htab_t print_generated_program::params_index): Likewise.
(htab_t gloog::newivs_index): Likewise.
(htab_t gloog::params_index): Likewise.
* graphite.c: Include graphite-htab.h.
4htab_t graphite_transform_loops::bb_pbb_mapping):
Change type to hash_table. Update dependent calls and types.
* graphite-clast-to-gimple.h: (extern gloog) Move to graphite-htab.h.
(bb_pbb_map_hash): Fold into bb_pbb_htab_type in graphite-htab.h.
(eq_bb_pbb_map): Fold into bb_pbb_htab_type in graphite-htab.h.
* graphite-dependences.c: Include graphite-htab.h.
(loop_is_parallel_p): Change hash table type of parameter.
* graphite-htab.h: New.
(typedef hash_table <bb_pbb_hasher> bb_pbb_htab_type): New.
(extern find_pbb_via_hash): Move from graphite-poly.h.
(extern loop_is_parallel_p): Move from graphite-poly.h.
(extern get_loop_body_pbbs): Move from graphite-poly.h.
* graphite-poly.h (extern find_pbb_via_hash): Move to graphite-htab.h.
(extern loop_is_parallel_p): Move to graphite-htab.h.
(extern get_loop_body_pbbs): Move to graphite-htab.h.
* haifa-sched.c (htab_t delay_htab):
Change type to hash_table. Update dependent calls and types.
(htab_t delay_htab_i2): Likewise.
* ira-color.c (htab_t allocno_hard_regs_htab):
Change type to hash_table. Update dependent calls and types.
* ira-costs.c (htab_t cost_classes_htab):
Change type to hash_table. Update dependent calls and types.
* loop-invariant.c (htab_t merge_identical_invariants::eq):
Change type to hash_table. Update dependent calls and types.
* loop-iv.c (htab_t bivs):
Change type to hash_table. Update dependent calls and types.
* loop-unroll.c (htab_t opt_info::insns_to_split):
Change type to hash_table. Update dependent calls and types.
(htab_t opt_info::insns_with_var_to_expand): Likewise.
* lto-streamer.h (struct string_slot): Move from data-streamer.h
(struct string_slot_hasher): New.
(htab_t output_block::string_hash_table):
Change type to hash_table. Update dependent calls and types.
* lto-streamer-in.c (freeing_string_slot_hasher): New.
(htab_t file_name_hash_table):
Change type to hash_table. Update dependent calls and types.
* lto-streamer-out.c: Update output_block::string_hash_table dependent
calls and types.
* lto-streamer.c (htab_t tree_htab):
Change type to hash_table. Update dependent calls and types.
* omp-low.c: Include gimplify-ctx.h.
* passes.c (htab_t name_to_pass_map):
Change type to hash_table. Update dependent calls and types.
(pass_traverse): Rename to passes_pass_traverse.
* plugin.c (htab_t event_tab):
Change type to hash_table. Update dependent calls and types.
* postreload-gcse.c (htab_t expr_table):
Change type to hash_table. Update dependent calls and types.
(dump_hash_table_entry): Rename dump_expr_hash_table_entry.
* sese.c (debug_rename_map_1): Make extern.
(htab_t copy_bb_and_scalar_dependences::rename_map):
Change type to hash_table. Update dependent calls and types.
* sese.h (extern debug_rename_map): Move to .c file.
* store-motion.c (htab_t store_motion_mems_table):
Change type to hash_table. Update dependent calls and types.
* trans-mem.c (htab_t tm_new_mem_hash):
Change type to hash_table. Update dependent calls and types.
* tree-browser.c (htab_t TB_up_ht):
Change type to hash_table. Update dependent calls and types.
* tree-cfg.c (htab_t discriminator_per_locus):
Change type to hash_table. Update dependent calls and types.
* tree-complex.c: Include tree-hasher.h
(htab_t complex_variable_components):
Change type to hash_table. Update dependent calls and types.
* tree-eh.c (htab_t finally_tree):
Change type to hash_table. Update dependent calls and types.
* tree-flow.h (extern int_tree_map_hash): Moved into tree-hasher
struct int_tree_hasher.
(extern int_tree_map_eq): Likewise.
(uid_decl_map_hash): Removed.
(extern decl_tree_map_eq): Likewise.
* tree-hasher.h: New.
(struct int_tree_hasher): New.
(typedef int_tree_htab_type): New.
* tree-inline.c: Include gimplify-ctx.h.
* tree-mudflap.c: Include gimplify-ctx.h.
* tree-parloops.c: Include tree-hasher.h.
(htab_t eliminate_local_variables_stmt::decl_address):
Change type to hash_table. Update dependent calls and types.
(htab_t separate_decls_in_region::decl_copies): Likewise.
* tree-scalar-evolution.c (htab_t resolve_mixers::cache):
Change type to hash_table. Update dependent calls and types.
* tree-sra.c (candidates):
Change type to hash_table. Update dependent calls and types.
* tree-ssa.c (int_tree_map_eq): Moved into struct int_tree_hasher
in tree-flow.h.
(int_tree_map_hash): Likewise.
* tree-ssa-dom.c (htab_t avail_exprs):
Change type to hash_table. Update dependent calls and types.
* tree-ssa-live.c (var_map_base_init::tree_to_index):
Change type to hash_table. Update dependent calls and types.
* tree-ssa-loop-ivopts.c (struct ivopts_data.inv_expr_tab):
Change type to hash_table. Update dependent calls and types.
* tree-ssa-phiopt.c (seen_ssa_names):
Change type to hash_table. Update dependent calls and types.
* tree-ssa-strlen.c (decl_to_stridxlist_htab):
Change type to hash_table. Update dependent calls and types.
* tree-ssa-uncprop.c (equiv):
Change type to hash_table. Update dependent calls and types.
From-SVN: r198329
Diffstat (limited to 'gcc/ggc-common.c')
-rw-r--r-- | gcc/ggc-common.c | 175 |
1 files changed, 93 insertions, 82 deletions
diff --git a/gcc/ggc-common.c b/gcc/ggc-common.c index 91c8249..0bb2eb1 100644 --- a/gcc/ggc-common.c +++ b/gcc/ggc-common.c @@ -23,7 +23,7 @@ along with GCC; see the file COPYING3. If not see #include "config.h" #include "system.h" #include "coretypes.h" -#include "hashtab.h" +#include "hash-table.h" #include "ggc.h" #include "ggc-internal.h" #include "diagnostic-core.h" @@ -46,10 +46,6 @@ static ggc_statistics *ggc_stats; struct traversal_state; static int ggc_htab_delete (void **, void *); -static hashval_t saving_htab_hash (const void *); -static int saving_htab_eq (const void *, const void *); -static int call_count (void **, void *); -static int call_alloc (void **, void *); static int compare_ptr_data (const void *, const void *); static void relocate_ptrs (void *, void *); static void write_pch_globals (const struct ggc_root_tab * const *tab, @@ -289,8 +285,6 @@ ggc_print_common_statistics (FILE *stream ATTRIBUTE_UNUSED, /* Functions for saving and restoring GCable memory to disk. */ -static htab_t saving_htab; - struct ptr_data { void *obj; @@ -303,6 +297,30 @@ struct ptr_data #define POINTER_HASH(x) (hashval_t)((intptr_t)x >> 3) +/* Helper for hashing saving_htab. */ + +struct saving_hasher : typed_free_remove <ptr_data> +{ + typedef ptr_data value_type; + typedef void compare_type; + static inline hashval_t hash (const value_type *); + static inline bool equal (const value_type *, const compare_type *); +}; + +inline hashval_t +saving_hasher::hash (const value_type *p) +{ + return POINTER_HASH (p->obj); +} + +inline bool +saving_hasher::equal (const value_type *p1, const compare_type *p2) +{ + return p1->obj == p2; +} + +static hash_table <saving_hasher> saving_htab; + /* Register an object in the hash table. */ int @@ -315,8 +333,7 @@ gt_pch_note_object (void *obj, void *note_ptr_cookie, return 0; slot = (struct ptr_data **) - htab_find_slot_with_hash (saving_htab, obj, POINTER_HASH (obj), - INSERT); + saving_htab.find_slot_with_hash (obj, POINTER_HASH (obj), INSERT); if (*slot != NULL) { gcc_assert ((*slot)->note_ptr_fn == note_ptr_fn @@ -347,26 +364,12 @@ gt_pch_note_reorder (void *obj, void *note_ptr_cookie, return; data = (struct ptr_data *) - htab_find_with_hash (saving_htab, obj, POINTER_HASH (obj)); + saving_htab.find_with_hash (obj, POINTER_HASH (obj)); gcc_assert (data && data->note_ptr_cookie == note_ptr_cookie); data->reorder_fn = reorder_fn; } -/* Hash and equality functions for saving_htab, callbacks for htab_create. */ - -static hashval_t -saving_htab_hash (const void *p) -{ - return POINTER_HASH (((const struct ptr_data *)p)->obj); -} - -static int -saving_htab_eq (const void *p1, const void *p2) -{ - return ((const struct ptr_data *)p1)->obj == p2; -} - /* Handy state for the traversal functions. */ struct traversal_state @@ -380,11 +383,10 @@ struct traversal_state /* Callbacks for htab_traverse. */ -static int -call_count (void **slot, void *state_p) +int +ggc_call_count (ptr_data **slot, traversal_state *state) { - struct ptr_data *d = (struct ptr_data *)*slot; - struct traversal_state *state = (struct traversal_state *)state_p; + struct ptr_data *d = *slot; ggc_pch_count_object (state->d, d->obj, d->size, d->note_ptr_fn == gt_pch_p_S); @@ -392,11 +394,10 @@ call_count (void **slot, void *state_p) return 1; } -static int -call_alloc (void **slot, void *state_p) +int +ggc_call_alloc (ptr_data **slot, traversal_state *state) { - struct ptr_data *d = (struct ptr_data *)*slot; - struct traversal_state *state = (struct traversal_state *)state_p; + struct ptr_data *d = *slot; d->new_addr = ggc_pch_alloc_object (state->d, d->obj, d->size, d->note_ptr_fn == gt_pch_p_S); @@ -429,7 +430,7 @@ relocate_ptrs (void *ptr_p, void *state_p) return; result = (struct ptr_data *) - htab_find_with_hash (saving_htab, *ptr, POINTER_HASH (*ptr)); + saving_htab.find_with_hash (*ptr, POINTER_HASH (*ptr)); gcc_assert (result); *ptr = result->new_addr; } @@ -458,7 +459,7 @@ write_pch_globals (const struct ggc_root_tab * const *tab, else { new_ptr = (struct ptr_data *) - htab_find_with_hash (saving_htab, ptr, POINTER_HASH (ptr)); + saving_htab.find_with_hash (ptr, POINTER_HASH (ptr)); if (fwrite (&new_ptr->new_addr, sizeof (void *), 1, state->f) != 1) fatal_error ("can%'t write PCH file: %m"); @@ -492,7 +493,7 @@ gt_pch_save (FILE *f) gt_pch_save_stringpool (); timevar_push (TV_PCH_PTR_REALLOC); - saving_htab = htab_create (50000, saving_htab_hash, saving_htab_eq, free); + saving_htab.create (50000); for (rt = gt_ggc_rtab; *rt; rt++) for (rti = *rt; rti->base != NULL; rti++) @@ -508,7 +509,7 @@ gt_pch_save (FILE *f) state.f = f; state.d = init_ggc_pch (); state.count = 0; - htab_traverse (saving_htab, call_count, &state); + saving_htab.traverse <traversal_state *, ggc_call_count> (&state); mmi.size = ggc_pch_total_size (state.d); @@ -524,7 +525,7 @@ gt_pch_save (FILE *f) state.ptrs = XNEWVEC (struct ptr_data *, state.count); state.ptrs_i = 0; - htab_traverse (saving_htab, call_alloc, &state); + saving_htab.traverse <traversal_state *, ggc_call_alloc> (&state); timevar_pop (TV_PCH_PTR_REALLOC); timevar_push (TV_PCH_PTR_SORT); @@ -653,7 +654,7 @@ gt_pch_save (FILE *f) XDELETE (state.ptrs); XDELETE (this_object); - htab_delete (saving_htab); + saving_htab.dispose (); } /* Read the state of the compiler back in from F. */ @@ -913,30 +914,32 @@ struct loc_descriptor size_t collected; }; -/* Hashtable used for statistics. */ -static htab_t loc_hash; +/* Hash table helper. */ -/* Hash table helpers functions. */ -static hashval_t -hash_descriptor (const void *p) +struct loc_desc_hasher : typed_noop_remove <loc_descriptor> { - const struct loc_descriptor *const d = (const struct loc_descriptor *) p; + typedef loc_descriptor value_type; + typedef loc_descriptor compare_type; + static inline hashval_t hash (const value_type *); + static inline bool equal (const value_type *, const compare_type *); +}; +inline hashval_t +loc_desc_hasher::hash (const value_type *d) +{ return htab_hash_pointer (d->function) | d->line; } -static int -eq_descriptor (const void *p1, const void *p2) +inline bool +loc_desc_hasher::equal (const value_type *d, const compare_type *d2) { - const struct loc_descriptor *const d = (const struct loc_descriptor *) p1; - const struct loc_descriptor *const d2 = (const struct loc_descriptor *) p2; - return (d->file == d2->file && d->line == d2->line && d->function == d2->function); } -/* Hashtable converting address of allocated field to loc descriptor. */ -static htab_t ptr_hash; +/* Hashtable used for statistics. */ +static hash_table <loc_desc_hasher> loc_hash; + struct ptr_hash_entry { void *ptr; @@ -944,26 +947,34 @@ struct ptr_hash_entry size_t size; }; -/* Hash table helpers functions. */ -static hashval_t -hash_ptr (const void *p) +/* Helper for ptr_hash table. */ + +struct ptr_hash_hasher : typed_noop_remove <ptr_hash_entry> { - const struct ptr_hash_entry *const d = (const struct ptr_hash_entry *) p; + typedef ptr_hash_entry value_type; + typedef void compare_type; + static inline hashval_t hash (const value_type *); + static inline bool equal (const value_type *, const compare_type *); +}; +inline hashval_t +ptr_hash_hasher::hash (const value_type *d) +{ return htab_hash_pointer (d->ptr); } -static int -eq_ptr (const void *p1, const void *p2) +inline bool +ptr_hash_hasher::equal (const value_type *p, const compare_type *p2) { - const struct ptr_hash_entry *const p = (const struct ptr_hash_entry *) p1; - return (p->ptr == p2); } +/* Hashtable converting address of allocated field to loc descriptor. */ +static hash_table <ptr_hash_hasher> ptr_hash; + /* Return descriptor for given call site, create new one if needed. */ static struct loc_descriptor * -loc_descriptor (const char *name, int line, const char *function) +make_loc_descriptor (const char *name, int line, const char *function) { struct loc_descriptor loc; struct loc_descriptor **slot; @@ -971,10 +982,10 @@ loc_descriptor (const char *name, int line, const char *function) loc.file = name; loc.line = line; loc.function = function; - if (!loc_hash) - loc_hash = htab_create (10, hash_descriptor, eq_descriptor, NULL); + if (!loc_hash.is_created ()) + loc_hash.create (10); - slot = (struct loc_descriptor **) htab_find_slot (loc_hash, &loc, INSERT); + slot = loc_hash.find_slot (&loc, INSERT); if (*slot) return *slot; *slot = XCNEW (struct loc_descriptor); @@ -989,16 +1000,16 @@ void ggc_record_overhead (size_t allocated, size_t overhead, void *ptr, const char *name, int line, const char *function) { - struct loc_descriptor *loc = loc_descriptor (name, line, function); + struct loc_descriptor *loc = make_loc_descriptor (name, line, function); struct ptr_hash_entry *p = XNEW (struct ptr_hash_entry); - PTR *slot; + ptr_hash_entry **slot; p->ptr = ptr; p->loc = loc; p->size = allocated + overhead; - if (!ptr_hash) - ptr_hash = htab_create (10, hash_ptr, eq_ptr, NULL); - slot = htab_find_slot_with_hash (ptr_hash, ptr, htab_hash_pointer (ptr), INSERT); + if (!ptr_hash.is_created ()) + ptr_hash.create (10); + slot = ptr_hash.find_slot_with_hash (ptr, htab_hash_pointer (ptr), INSERT); gcc_assert (!*slot); *slot = p; @@ -1009,14 +1020,14 @@ ggc_record_overhead (size_t allocated, size_t overhead, void *ptr, /* Helper function for prune_overhead_list. See if SLOT is still marked and remove it from hashtable if it is not. */ -static int -ggc_prune_ptr (void **slot, void *b ATTRIBUTE_UNUSED) +int +ggc_prune_ptr (ptr_hash_entry **slot, void *b ATTRIBUTE_UNUSED) { - struct ptr_hash_entry *p = (struct ptr_hash_entry *) *slot; + struct ptr_hash_entry *p = *slot; if (!ggc_marked_p (p->ptr)) { p->loc->collected += p->size; - htab_clear_slot (ptr_hash, slot); + ptr_hash.clear_slot (slot); free (p); } return 1; @@ -1027,15 +1038,15 @@ ggc_prune_ptr (void **slot, void *b ATTRIBUTE_UNUSED) void ggc_prune_overhead_list (void) { - htab_traverse (ptr_hash, ggc_prune_ptr, NULL); + ptr_hash.traverse <void *, ggc_prune_ptr> (NULL); } /* Notice that the pointer has been freed. */ void ggc_free_overhead (void *ptr) { - PTR *slot = htab_find_slot_with_hash (ptr_hash, ptr, htab_hash_pointer (ptr), - NO_INSERT); + ptr_hash_entry **slot; + slot = ptr_hash.find_slot_with_hash (ptr, htab_hash_pointer (ptr), NO_INSERT); struct ptr_hash_entry *p; /* The pointer might be not found if a PCH read happened between allocation and ggc_free () call. FIXME: account memory properly in the presence of @@ -1044,7 +1055,7 @@ ggc_free_overhead (void *ptr) return; p = (struct ptr_hash_entry *) *slot; p->loc->freed += p->size; - htab_clear_slot (ptr_hash, slot); + ptr_hash.clear_slot (slot); free (p); } @@ -1083,11 +1094,10 @@ cmp_statistic (const void *loc1, const void *loc2) /* Collect array of the descriptors from hashtable. */ static struct loc_descriptor **loc_array; -static int -add_statistics (void **slot, void *b) +int +ggc_add_statistics (loc_descriptor **slot, int *n) { - int *n = (int *)b; - loc_array[*n] = (struct loc_descriptor *) *slot; + loc_array[*n] = *slot; (*n)++; return 1; } @@ -1108,12 +1118,13 @@ dump_ggc_loc_statistics (bool final) ggc_force_collect = true; ggc_collect (); - loc_array = XCNEWVEC (struct loc_descriptor *, loc_hash->n_elements); + loc_array = XCNEWVEC (struct loc_descriptor *, + loc_hash.elements_with_deleted ()); fprintf (stderr, "-------------------------------------------------------\n"); fprintf (stderr, "\n%-48s %10s %10s %10s %10s %10s\n", "source location", "Garbage", "Freed", "Leak", "Overhead", "Times"); fprintf (stderr, "-------------------------------------------------------\n"); - htab_traverse (loc_hash, add_statistics, &nentries); + loc_hash.traverse <int *, ggc_add_statistics> (&nentries); qsort (loc_array, nentries, sizeof (*loc_array), final ? final_cmp_statistic : cmp_statistic); for (i = 0; i < nentries; i++) |