Commit 5831a5f0 by Lawrence Crowl Committed by Lawrence Crowl

Change hash_table to support a comparator type different from the value type…

Change hash_table to support a comparator type different from the value type stored in the hash table.

Change hash_table to support a comparator type different from the
value type stored in the hash table.  The 'find' functions now may
take a different type from the value type.  This requires introducing
a second typedef into the Descriptor conceptual type.  Change the
Descriptor concept to use typedefs value_type and compare_type instead
of T.  Change all users to match.

Add usage documentation to hash-table.h.

Tested on x86-64.


Index: gcc/ChangeLog

2012-10-25  Lawrence Crowl  <crowl@google.com>

	* hash-table.h: Add usage documentation.
	(template struct typed_free_remove): Clarify documentation. 
	Rename template parameter.
	(struct typed_noop_remove): Likewise.
	(descriptor concept): Change typedef T to value_type.
	Add typedef compare_type.  Use more precise template parameter name,
	Descriptor instead of Descr.  Update users to match.
	(struct hash_table): Change 'find' parameters to use compare_type
	instead of the value type.

From-SVN: r192823
parent 2257bc19
2012-10-25 Lawrence Crowl <crowl@google.com>
* hash-table.h: Add usage documentation.
(template struct typed_free_remove): Clarify documentation.
Rename template parameter.
(struct typed_noop_remove): Likewise.
(descriptor concept): Change typedef T to value_type.
Add typedef compare_type. Use more precise template parameter name,
Descriptor instead of Descr. Update users to match.
(struct hash_table): Change 'find' parameters to use compare_type
instead of the value type.
2012-10-25 Jan Hubicka <jh@suse.cz>
* ipa-cp.c (ipcp_discover_new_direct_edges): If something was turned
......@@ -22,7 +22,7 @@ along with GCC; see the file COPYING3. If not see
#include "config.h"
#include "system.h"
#include "alloc-pool.h"
#include "hashtab.h"
#include "hash-table.h"
#define align_eight(x) (((x+7) >> 3) << 3)
......@@ -83,38 +83,42 @@ struct alloc_pool_descriptor
int elt_size;
};
struct alloc_pool_hasher : typed_noop_remove <alloc_pool_descriptor>
{
typedef alloc_pool_descriptor value_type;
typedef char compare_type;
static inline hashval_t hash (const alloc_pool_descriptor *);
static inline bool equal (const value_type *, const compare_type *);
};
/* Hashtable mapping alloc_pool names to descriptors. */
static htab_t alloc_pool_hash;
static hash_table <alloc_pool_hasher> alloc_pool_hash;
/* Hashtable helpers. */
static hashval_t
hash_descriptor (const void *p)
inline hashval_t
alloc_pool_hasher::hash (const value_type *d)
{
const struct alloc_pool_descriptor *const d =
(const struct alloc_pool_descriptor * )p;
return htab_hash_pointer (d->name);
}
static int
eq_descriptor (const void *p1, const void *p2)
inline bool
alloc_pool_hasher::equal (const value_type *d,
const compare_type *p2)
{
const struct alloc_pool_descriptor *const d =
(const struct alloc_pool_descriptor *) p1;
return d->name == p2;
}
/* For given name, return descriptor, create new if needed. */
static struct alloc_pool_descriptor *
alloc_pool_descriptor (const char *name)
allocate_pool_descriptor (const char *name)
{
struct alloc_pool_descriptor **slot;
if (!alloc_pool_hash)
alloc_pool_hash = htab_create (10, hash_descriptor, eq_descriptor, NULL);
if (!alloc_pool_hash.is_created ())
alloc_pool_hash.create (10);
slot = (struct alloc_pool_descriptor **)
htab_find_slot_with_hash (alloc_pool_hash, name,
htab_hash_pointer (name),
INSERT);
slot = alloc_pool_hash.find_slot_with_hash (name,
htab_hash_pointer (name), INSERT);
if (*slot)
return *slot;
*slot = XCNEW (struct alloc_pool_descriptor);
......@@ -158,7 +162,7 @@ create_alloc_pool (const char *name, size_t size, size_t num)
if (GATHER_STATISTICS)
{
struct alloc_pool_descriptor *desc = alloc_pool_descriptor (name);
struct alloc_pool_descriptor *desc = allocate_pool_descriptor (name);
desc->elt_size = size;
desc->created++;
}
......@@ -205,7 +209,7 @@ empty_alloc_pool (alloc_pool pool)
if (GATHER_STATISTICS)
{
struct alloc_pool_descriptor *desc = alloc_pool_descriptor (pool->name);
struct alloc_pool_descriptor *desc = allocate_pool_descriptor (pool->name);
desc->current -= (pool->elts_allocated - pool->elts_free) * pool->elt_size;
}
......@@ -253,7 +257,7 @@ pool_alloc (alloc_pool pool)
if (GATHER_STATISTICS)
{
struct alloc_pool_descriptor *desc = alloc_pool_descriptor (pool->name);
struct alloc_pool_descriptor *desc = allocate_pool_descriptor (pool->name);
desc->allocated += pool->elt_size;
desc->current += pool->elt_size;
......@@ -357,7 +361,7 @@ pool_free (alloc_pool pool, void *ptr)
if (GATHER_STATISTICS)
{
struct alloc_pool_descriptor *desc = alloc_pool_descriptor (pool->name);
struct alloc_pool_descriptor *desc = allocate_pool_descriptor (pool->name);
desc->current -= pool->elt_size;
}
}
......@@ -371,19 +375,20 @@ struct output_info
unsigned long total_allocated;
};
/* Called via htab_traverse. Output alloc_pool descriptor pointed out by SLOT
and update statistics. */
static int
print_statistics (void **slot, void *b)
/* Called via hash_table.traverse. Output alloc_pool descriptor pointed out by
SLOT and update statistics. */
int
print_alloc_pool_statistics (alloc_pool_descriptor **slot,
struct output_info *i)
{
struct alloc_pool_descriptor *d = (struct alloc_pool_descriptor *) *slot;
struct output_info *i = (struct output_info *) b;
struct alloc_pool_descriptor *d = *slot;
if (d->allocated)
{
fprintf (stderr, "%-22s %6d %10lu %10lu(%10lu) %10lu(%10lu) %10lu(%10lu)\n", d->name,
d->elt_size, d->created, d->allocated, d->allocated / d->elt_size,
d->peak, d->peak / d->elt_size,
fprintf (stderr,
"%-22s %6d %10lu %10lu(%10lu) %10lu(%10lu) %10lu(%10lu)\n",
d->name, d->elt_size, d->created, d->allocated,
d->allocated / d->elt_size, d->peak, d->peak / d->elt_size,
d->current, d->current / d->elt_size);
i->total_allocated += d->allocated;
i->total_created += d->created;
......@@ -400,14 +405,15 @@ dump_alloc_pool_statistics (void)
if (! GATHER_STATISTICS)
return;
if (!alloc_pool_hash)
if (!alloc_pool_hash.is_created ())
return;
fprintf (stderr, "\nAlloc-pool Kind Elt size Pools Allocated (elts) Peak (elts) Leak (elts)\n");
fprintf (stderr, "--------------------------------------------------------------------------------------------------------------\n");
info.total_created = 0;
info.total_allocated = 0;
htab_traverse (alloc_pool_hash, print_statistics, &info);
alloc_pool_hash.traverse <struct output_info *,
print_alloc_pool_statistics> (&info);
fprintf (stderr, "--------------------------------------------------------------------------------------------------------------\n");
fprintf (stderr, "%-22s %7lu %10lu\n",
"Total", info.total_created, info.total_allocated);
......
......@@ -988,19 +988,21 @@ struct htab_bb_copy_original_entry
struct bb_copy_hasher : typed_noop_remove <htab_bb_copy_original_entry>
{
typedef htab_bb_copy_original_entry T;
static inline hashval_t hash (const T *);
static inline bool equal (const T *existing, const T * candidate);
typedef htab_bb_copy_original_entry value_type;
typedef htab_bb_copy_original_entry compare_type;
static inline hashval_t hash (const value_type *);
static inline bool equal (const value_type *existing,
const compare_type * candidate);
};
inline hashval_t
bb_copy_hasher::hash (const T *data)
bb_copy_hasher::hash (const value_type *data)
{
return data->index1;
}
inline bool
bb_copy_hasher::equal (const T *data, const T *data2)
bb_copy_hasher::equal (const value_type *data, const compare_type *data2)
{
return data->index1 == data2->index1;
}
......
......@@ -79,10 +79,11 @@ typedef struct counts_entry
struct gcov_ctr_summary summary;
/* hash_table support. */
typedef counts_entry T;
static inline hashval_t hash (const counts_entry *);
static int equal (const counts_entry *, const counts_entry *);
static void remove (counts_entry *);
typedef counts_entry value_type;
typedef counts_entry compare_type;
static inline hashval_t hash (const value_type *);
static int equal (const value_type *, const compare_type *);
static void remove (value_type *);
} counts_entry_t;
static GTY(()) struct coverage_data *functions_head = 0;
......@@ -150,20 +151,20 @@ get_gcov_unsigned_t (void)
}
inline hashval_t
counts_entry::hash (const counts_entry_t *entry)
counts_entry::hash (const value_type *entry)
{
return entry->ident * GCOV_COUNTERS + entry->ctr;
}
inline int
counts_entry::equal (const counts_entry_t *entry1,
const counts_entry_t *entry2)
counts_entry::equal (const value_type *entry1,
const compare_type *entry2)
{
return entry1->ident == entry2->ident && entry1->ctr == entry2->ctr;
}
inline void
counts_entry::remove (counts_entry_t *entry)
counts_entry::remove (value_type *entry)
{
free (entry->counts);
free (entry);
......
......@@ -654,19 +654,21 @@ clear_alias_set_lookup (alias_set_type alias_set)
struct invariant_group_base_hasher : typed_noop_remove <group_info>
{
typedef group_info T;
static inline hashval_t hash (const T *);
static inline bool equal (const T *, const T *);
typedef group_info value_type;
typedef group_info compare_type;
static inline hashval_t hash (const value_type *);
static inline bool equal (const value_type *, const compare_type *);
};
inline bool
invariant_group_base_hasher::equal (const T *gi1, const T *gi2)
invariant_group_base_hasher::equal (const value_type *gi1,
const compare_type *gi2)
{
return rtx_equal_p (gi1->rtx_base, gi2->rtx_base);
}
inline hashval_t
invariant_group_base_hasher::hash (const T *gi)
invariant_group_base_hasher::hash (const value_type *gi)
{
int do_not_record;
return hash_rtx (gi->rtx_base, Pmode, &do_not_record, NULL, false);
......
......@@ -276,19 +276,21 @@ find_classfile (char *filename, JCF *jcf, const char *dep_name)
struct charstar_hash : typed_noop_remove <char>
{
typedef const char T;
static inline hashval_t hash (const T *candidate);
static inline bool equal (const T *existing, const T *candidate);
typedef const char value_type;
typedef const char compare_type;
static inline hashval_t hash (const value_type *candidate);
static inline bool equal (const value_type *existing,
const compare_type *candidate);
};
inline hashval_t
charstar_hash::hash (const T *candidate)
charstar_hash::hash (const value_type *candidate)
{
return htab_hash_string (candidate);
}
inline bool
charstar_hash::equal (const T *existing, const T *candidate)
charstar_hash::equal (const value_type *existing, const compare_type *candidate)
{
return strcmp (existing, candidate) == 0;
}
......
......@@ -3827,19 +3827,20 @@ objc_get_class_ivars (tree class_name)
struct decl_name_hash : typed_noop_remove <tree_node>
{
typedef tree_node T;
static inline hashval_t hash (const T *);
static inline bool equal (const T *, const T *);
typedef tree_node value_type;
typedef tree_node compare_type;
static inline hashval_t hash (const value_type *);
static inline bool equal (const value_type *, const compare_type *);
};
inline hashval_t
decl_name_hash::hash (const T *q)
decl_name_hash::hash (const value_type *q)
{
return (hashval_t) ((intptr_t)(DECL_NAME (q)) >> 3);
}
inline bool
decl_name_hash::equal (const T *a, const T *b)
decl_name_hash::equal (const value_type *a, const compare_type *b)
{
return DECL_NAME (a) == DECL_NAME (b);
}
......
......@@ -1261,9 +1261,10 @@ coalesce_partitions (var_map map, ssa_conflicts_p graph, coalesce_list_p cl,
struct ssa_name_var_hash : typed_noop_remove <union tree_node>
{
typedef union tree_node T;
static inline hashval_t hash (const_tree);
static inline int equal (const_tree, const_tree);
typedef union tree_node value_type;
typedef union tree_node compare_type;
static inline hashval_t hash (const value_type *);
static inline int equal (const value_type *, const compare_type *);
};
inline hashval_t
......@@ -1273,7 +1274,7 @@ ssa_name_var_hash::hash (const_tree n)
}
inline int
ssa_name_var_hash::equal (const_tree n1, const_tree n2)
ssa_name_var_hash::equal (const value_type *n1, const compare_type *n2)
{
return SSA_NAME_VAR (n1) == SSA_NAME_VAR (n2);
}
......
......@@ -173,7 +173,8 @@ typedef struct pre_expr_d : typed_noop_remove <pre_expr_d>
pre_expr_union u;
/* hash_table support. */
typedef pre_expr_d T;
typedef pre_expr_d value_type;
typedef pre_expr_d compare_type;
static inline hashval_t hash (const pre_expr_d *);
static inline int equal (const pre_expr_d *, const pre_expr_d *);
} *pre_expr;
......@@ -186,7 +187,7 @@ typedef struct pre_expr_d : typed_noop_remove <pre_expr_d>
/* Compare E1 and E1 for equality. */
inline int
pre_expr_d::equal (const struct pre_expr_d *e1, const struct pre_expr_d *e2)
pre_expr_d::equal (const value_type *e1, const compare_type *e2)
{
if (e1->kind != e2->kind)
return false;
......@@ -211,7 +212,7 @@ pre_expr_d::equal (const struct pre_expr_d *e1, const struct pre_expr_d *e2)
/* Hash E. */
inline hashval_t
pre_expr_d::hash (const struct pre_expr_d *e)
pre_expr_d::hash (const value_type *e)
{
switch (e->kind)
{
......@@ -499,9 +500,10 @@ typedef struct expr_pred_trans_d : typed_free_remove<expr_pred_trans_d>
hashval_t hashcode;
/* hash_table support. */
typedef expr_pred_trans_d T;
static inline hashval_t hash (const expr_pred_trans_d *);
static inline int equal (const expr_pred_trans_d *, const expr_pred_trans_d *);
typedef expr_pred_trans_d value_type;
typedef expr_pred_trans_d compare_type;
static inline hashval_t hash (const value_type *);
static inline int equal (const value_type *, const compare_type *);
} *expr_pred_trans_t;
typedef const struct expr_pred_trans_d *const_expr_pred_trans_t;
......@@ -512,8 +514,8 @@ expr_pred_trans_d::hash (const expr_pred_trans_d *e)
}
inline int
expr_pred_trans_d::equal (const expr_pred_trans_d *ve1,
const expr_pred_trans_d *ve2)
expr_pred_trans_d::equal (const value_type *ve1,
const compare_type *ve2)
{
basic_block b1 = ve1->pred;
basic_block b2 = ve2->pred;
......
......@@ -226,10 +226,11 @@ struct same_succ_def
hashval_t hashval;
/* hash_table support. */
typedef same_succ_def T;
static inline hashval_t hash (const same_succ_def *);
static int equal (const same_succ_def *, const same_succ_def *);
static void remove (same_succ_def *);
typedef same_succ_def value_type;
typedef same_succ_def compare_type;
static inline hashval_t hash (const value_type *);
static int equal (const value_type *, const compare_type *);
static void remove (value_type *);
};
typedef struct same_succ_def *same_succ;
typedef const struct same_succ_def *const_same_succ;
......@@ -237,7 +238,7 @@ typedef const struct same_succ_def *const_same_succ;
/* hash routine for hash_table support, returns hashval of E. */
inline hashval_t
same_succ_def::hash (const same_succ_def *e)
same_succ_def::hash (const value_type *e)
{
return e->hashval;
}
......@@ -528,7 +529,7 @@ inverse_flags (const_same_succ e1, const_same_succ e2)
/* Compares SAME_SUCCs E1 and E2. */
int
same_succ_def::equal (const_same_succ e1, const_same_succ e2)
same_succ_def::equal (const value_type *e1, const compare_type *e2)
{
unsigned int i, first1, first2;
gimple_stmt_iterator gsi1, gsi2;
......
......@@ -127,20 +127,21 @@ struct redirection_data : typed_free_remove<redirection_data>
struct el *incoming_edges;
/* hash_table support. */
typedef redirection_data T;
static inline hashval_t hash (const redirection_data *);
static inline int equal (const redirection_data *, const redirection_data *);
typedef redirection_data value_type;
typedef redirection_data compare_type;
static inline hashval_t hash (const value_type *);
static inline int equal (const value_type *, const compare_type *);
};
inline hashval_t
redirection_data::hash (const redirection_data *p)
redirection_data::hash (const value_type *p)
{
edge e = p->outgoing_edge;
return e->dest->index;
}
inline int
redirection_data::equal (const redirection_data *p1, const redirection_data *p2)
redirection_data::equal (const value_type *p1, const compare_type *p2)
{
edge e1 = p1->outgoing_edge;
edge e2 = p2->outgoing_edge;
......
......@@ -46,32 +46,33 @@ struct dead_debug_global_entry
struct dead_debug_hash_descr
{
/* The hash table contains pointers to entries of this type. */
typedef struct dead_debug_global_entry T;
typedef struct dead_debug_global_entry value_type;
typedef struct dead_debug_global_entry compare_type;
/* Hash on the pseudo number. */
static inline hashval_t hash (T const *my);
static inline hashval_t hash (const value_type *my);
/* Entries are identical if they refer to the same pseudo. */
static inline bool equal (T const *my, T const *other);
static inline bool equal (const value_type *my, const compare_type *other);
/* Release entries when they're removed. */
static inline void remove (T *p);
static inline void remove (value_type *p);
};
/* Hash on the pseudo number. */
inline hashval_t
dead_debug_hash_descr::hash (T const *my)
dead_debug_hash_descr::hash (const value_type *my)
{
return REGNO (my->reg);
}
/* Entries are identical if they refer to the same pseudo. */
inline bool
dead_debug_hash_descr::equal (T const *my, T const *other)
dead_debug_hash_descr::equal (const value_type *my, const compare_type *other)
{
return my->reg == other->reg;
}
/* Release entries when they're removed. */
inline void
dead_debug_hash_descr::remove (T *p)
dead_debug_hash_descr::remove (value_type *p)
{
XDELETE (p);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment