diff options
Diffstat (limited to 'gcc/tree-ssa-strlen.c')
-rw-r--r-- | gcc/tree-ssa-strlen.c | 60 |
1 files changed, 37 insertions, 23 deletions
diff --git a/gcc/tree-ssa-strlen.c b/gcc/tree-ssa-strlen.c index 9c724dc..bea0c28 100644 --- a/gcc/tree-ssa-strlen.c +++ b/gcc/tree-ssa-strlen.c @@ -21,6 +21,7 @@ along with GCC; see the file COPYING3. If not see #include "config.h" #include "system.h" #include "coretypes.h" +#include "hash-table.h" #include "tree-flow.h" #include "tree-pass.h" #include "domwalk.h" @@ -111,9 +112,33 @@ struct decl_stridxlist_map struct stridxlist list; }; +/* stridxlist hashtable helpers. */ + +struct stridxlist_hasher : typed_noop_remove <decl_stridxlist_map> +{ + typedef decl_stridxlist_map value_type; + typedef decl_stridxlist_map compare_type; + static inline hashval_t hash (const value_type *); + static inline bool equal (const value_type *, const compare_type *); +}; + +/* Hash a from tree in a decl_stridxlist_map. */ + +inline hashval_t +stridxlist_hasher::hash (const value_type *item) +{ + return DECL_UID (item->base.from); +} + +inline bool +stridxlist_hasher::equal (const value_type *v, const compare_type *c) +{ + return tree_map_base_eq (&v->base, &c->base); +} + /* Hash table for mapping decls to a chained list of offset -> idx mappings. */ -static htab_t decl_to_stridxlist_htab; +static hash_table <stridxlist_hasher> decl_to_stridxlist_htab; /* Obstack for struct stridxlist and struct decl_stridxlist_map. */ static struct obstack stridx_obstack; @@ -128,14 +153,6 @@ struct laststmt_struct int stridx; } laststmt; -/* Hash a from tree in a decl_stridxlist_map. */ - -static unsigned int -decl_to_stridxlist_hash (const void *item) -{ - return DECL_UID (((const struct decl_stridxlist_map *) item)->base.from); -} - /* Helper function for get_stridx. */ static int @@ -146,7 +163,7 @@ get_addr_stridx (tree exp) struct stridxlist *list; tree base; - if (decl_to_stridxlist_htab == NULL) + if (!decl_to_stridxlist_htab.is_created ()) return 0; base = get_addr_base_and_unit_offset (exp, &off); @@ -154,8 +171,7 @@ get_addr_stridx (tree exp) return 0; ent.base.from = base; - e = (struct decl_stridxlist_map *) - htab_find_with_hash (decl_to_stridxlist_htab, &ent, DECL_UID (base)); + e = decl_to_stridxlist_htab.find_with_hash (&ent, DECL_UID (base)); if (e == NULL) return 0; @@ -234,7 +250,7 @@ unshare_strinfo_vec (void) static int * addr_stridxptr (tree exp) { - void **slot; + decl_stridxlist_map **slot; struct decl_stridxlist_map ent; struct stridxlist *list; HOST_WIDE_INT off; @@ -243,19 +259,18 @@ addr_stridxptr (tree exp) if (base == NULL_TREE || !DECL_P (base)) return NULL; - if (decl_to_stridxlist_htab == NULL) + if (!decl_to_stridxlist_htab.is_created ()) { - decl_to_stridxlist_htab - = htab_create (64, decl_to_stridxlist_hash, tree_map_base_eq, NULL); + decl_to_stridxlist_htab.create (64); gcc_obstack_init (&stridx_obstack); } ent.base.from = base; - slot = htab_find_slot_with_hash (decl_to_stridxlist_htab, &ent, - DECL_UID (base), INSERT); + slot = decl_to_stridxlist_htab.find_slot_with_hash (&ent, DECL_UID (base), + INSERT); if (*slot) { int i; - list = &((struct decl_stridxlist_map *)*slot)->list; + list = &(*slot)->list; for (i = 0; i < 16; i++) { if (list->offset == off) @@ -273,7 +288,7 @@ addr_stridxptr (tree exp) struct decl_stridxlist_map *e = XOBNEW (&stridx_obstack, struct decl_stridxlist_map); e->base.from = base; - *slot = (void *) e; + *slot = e; list = &e->list; } list->next = NULL; @@ -1985,11 +2000,10 @@ tree_ssa_strlen (void) ssa_ver_to_stridx.release (); free_alloc_pool (strinfo_pool); - if (decl_to_stridxlist_htab) + if (decl_to_stridxlist_htab.is_created ()) { obstack_free (&stridx_obstack, NULL); - htab_delete (decl_to_stridxlist_htab); - decl_to_stridxlist_htab = NULL; + decl_to_stridxlist_htab.dispose (); } laststmt.stmt = NULL; laststmt.len = NULL_TREE; |