Re: [PATCH] convert some hash_table to hash_map
On Tue, Jul 8, 2014 at 5:01 AM, tsaund...@mozilla.com wrote: From: Trevor Saunders tsaund...@mozilla.com Hi, just $subject bootstrapped + regtested on x86_64-unknown-linux-gnu, ok? Ok. Thanks, Richard. Trev gcc/ * graphite-htab.h: Use hash_map instead of hash_table. * graphite-clast-to-gimple.c: Adjust. * passes.c: Use hash_map instead of hash_table. * sese.c: Likewise. * sese.h: Remove now unused code. diff --git a/gcc/graphite-clast-to-gimple.c b/gcc/graphite-clast-to-gimple.c index 71507a0..296b893 100644 --- a/gcc/graphite-clast-to-gimple.c +++ b/gcc/graphite-clast-to-gimple.c @@ -1012,34 +1012,16 @@ build_iv_mapping (vectree iv_map, struct clast_user_stmt *user_stmt, mpz_clear (bound_two); } -/* Construct bb_pbb_def with BB and PBB. */ - -static bb_pbb_def * -new_bb_pbb_def (basic_block bb, poly_bb_p pbb) -{ - bb_pbb_def *bb_pbb_p; - - bb_pbb_p = XNEW (bb_pbb_def); - bb_pbb_p-bb = bb; - bb_pbb_p-pbb = pbb; - - return bb_pbb_p; -} - /* Mark BB with it's relevant PBB via hashing table BB_PBB_MAPPING. */ static void mark_bb_with_pbb (poly_bb_p pbb, basic_block bb, bb_pbb_htab_type *bb_pbb_mapping) { - bb_pbb_def tmp; - bb_pbb_def **x; - - tmp.bb = bb; - x = bb_pbb_mapping-find_slot (tmp, INSERT); - - if (x !*x) -*x = new_bb_pbb_def (bb, pbb); + bool existed; + poly_bb_p e = bb_pbb_mapping-get_or_insert (bb, existed); + if (!existed) +e = pbb; } /* Find BB's related poly_bb_p in hash table BB_PBB_MAPPING. */ @@ -1047,14 +1029,9 @@ mark_bb_with_pbb (poly_bb_p pbb, basic_block bb, poly_bb_p find_pbb_via_hash (bb_pbb_htab_type *bb_pbb_mapping, basic_block bb) { - bb_pbb_def tmp; - bb_pbb_def **slot; - - tmp.bb = bb; - slot = bb_pbb_mapping-find_slot (tmp, NO_INSERT); - - if (slot *slot) -return ((bb_pbb_def *) *slot)-pbb; + poly_bb_p *pbb = bb_pbb_mapping-get (bb); + if (pbb) +return *pbb; return NULL; } diff --git a/gcc/graphite-htab.h b/gcc/graphite-htab.h index 69fd05a..b1fd81e 100644 --- a/gcc/graphite-htab.h +++ b/gcc/graphite-htab.h @@ -21,43 +21,33 @@ along with GCC; see the file COPYING3. If not see #ifndef GCC_GRAPHITE_HTAB_H #define GCC_GRAPHITE_HTAB_H -#include hash-table.h - -/* Stores BB's related PBB. */ - -struct bb_pbb_def -{ - basic_block bb; - poly_bb_p pbb; -}; +#include hash-map.h /* Hashtable helpers. */ -struct bb_pbb_hasher : typed_free_remove bb_pbb_def +struct bb_pbb_hasher : default_hashmap_traits { - typedef bb_pbb_def value_type; - typedef bb_pbb_def compare_type; - static inline hashval_t hash (const value_type *); - static inline bool equal (const value_type *, const compare_type *); + static inline hashval_t hash (const basic_block); + static inline bool equal_keys (const basic_block, const basic_block); }; -/* Hash function for data base element BB_PBB. */ +/* Hash function. */ inline hashval_t -bb_pbb_hasher::hash (const value_type *bb_pbb) +bb_pbb_hasher::hash (const basic_block bb) { - return (hashval_t)(bb_pbb-bb-index); + return (hashval_t)(bb-index); } /* Compare data base element PB1 and PB2. */ inline bool -bb_pbb_hasher::equal (const value_type *bp1, const compare_type *bp2) +bb_pbb_hasher::equal_keys (const basic_block a, const basic_block b) { - return (bp1-bb-index == bp2-bb-index); + return (a-index == b-index); } -typedef hash_tablebb_pbb_hasher bb_pbb_htab_type; +typedef hash_mapbasic_block, poly_bb_p, bb_pbb_hasher bb_pbb_htab_type; poly_bb_p find_pbb_via_hash (bb_pbb_htab_type *, basic_block); bool loop_is_parallel_p (loop_p, bb_pbb_htab_type *, int); diff --git a/gcc/passes.c b/gcc/passes.c index 91b644e..0533687 100644 --- a/gcc/passes.c +++ b/gcc/passes.c @@ -84,6 +84,7 @@ along with GCC; see the file COPYING3. If not see #include pass_manager.h #include tree-ssa-live.h /* For remove_unused_locals. */ #include tree-cfgcleanup.h +#include hash-map.h using namespace gcc; @@ -687,64 +688,47 @@ pass_manager::register_dump_files (opt_pass *pass) while (pass); } -struct pass_registry -{ - const char* unique_name; - opt_pass *pass; -}; - /* Helper for pass_registry hash table. */ -struct pass_registry_hasher : typed_noop_remove pass_registry +struct pass_registry_hasher : default_hashmap_traits { - typedef pass_registry value_type; - typedef pass_registry compare_type; - static inline hashval_t hash (const value_type *); - static inline bool equal (const value_type *, const compare_type *); + static inline hashval_t hash (const char *); + static inline bool equal_keys (const char *, const char *); }; /* Pass registry hash function. */ inline hashval_t -pass_registry_hasher::hash (const value_type *s) +pass_registry_hasher::hash (const char *name) { - return htab_hash_string (s-unique_name); + return
[PATCH] convert some hash_table to hash_map
From: Trevor Saunders tsaund...@mozilla.com Hi, just $subject bootstrapped + regtested on x86_64-unknown-linux-gnu, ok? Trev gcc/ * graphite-htab.h: Use hash_map instead of hash_table. * graphite-clast-to-gimple.c: Adjust. * passes.c: Use hash_map instead of hash_table. * sese.c: Likewise. * sese.h: Remove now unused code. diff --git a/gcc/graphite-clast-to-gimple.c b/gcc/graphite-clast-to-gimple.c index 71507a0..296b893 100644 --- a/gcc/graphite-clast-to-gimple.c +++ b/gcc/graphite-clast-to-gimple.c @@ -1012,34 +1012,16 @@ build_iv_mapping (vectree iv_map, struct clast_user_stmt *user_stmt, mpz_clear (bound_two); } -/* Construct bb_pbb_def with BB and PBB. */ - -static bb_pbb_def * -new_bb_pbb_def (basic_block bb, poly_bb_p pbb) -{ - bb_pbb_def *bb_pbb_p; - - bb_pbb_p = XNEW (bb_pbb_def); - bb_pbb_p-bb = bb; - bb_pbb_p-pbb = pbb; - - return bb_pbb_p; -} - /* Mark BB with it's relevant PBB via hashing table BB_PBB_MAPPING. */ static void mark_bb_with_pbb (poly_bb_p pbb, basic_block bb, bb_pbb_htab_type *bb_pbb_mapping) { - bb_pbb_def tmp; - bb_pbb_def **x; - - tmp.bb = bb; - x = bb_pbb_mapping-find_slot (tmp, INSERT); - - if (x !*x) -*x = new_bb_pbb_def (bb, pbb); + bool existed; + poly_bb_p e = bb_pbb_mapping-get_or_insert (bb, existed); + if (!existed) +e = pbb; } /* Find BB's related poly_bb_p in hash table BB_PBB_MAPPING. */ @@ -1047,14 +1029,9 @@ mark_bb_with_pbb (poly_bb_p pbb, basic_block bb, poly_bb_p find_pbb_via_hash (bb_pbb_htab_type *bb_pbb_mapping, basic_block bb) { - bb_pbb_def tmp; - bb_pbb_def **slot; - - tmp.bb = bb; - slot = bb_pbb_mapping-find_slot (tmp, NO_INSERT); - - if (slot *slot) -return ((bb_pbb_def *) *slot)-pbb; + poly_bb_p *pbb = bb_pbb_mapping-get (bb); + if (pbb) +return *pbb; return NULL; } diff --git a/gcc/graphite-htab.h b/gcc/graphite-htab.h index 69fd05a..b1fd81e 100644 --- a/gcc/graphite-htab.h +++ b/gcc/graphite-htab.h @@ -21,43 +21,33 @@ along with GCC; see the file COPYING3. If not see #ifndef GCC_GRAPHITE_HTAB_H #define GCC_GRAPHITE_HTAB_H -#include hash-table.h - -/* Stores BB's related PBB. */ - -struct bb_pbb_def -{ - basic_block bb; - poly_bb_p pbb; -}; +#include hash-map.h /* Hashtable helpers. */ -struct bb_pbb_hasher : typed_free_remove bb_pbb_def +struct bb_pbb_hasher : default_hashmap_traits { - typedef bb_pbb_def value_type; - typedef bb_pbb_def compare_type; - static inline hashval_t hash (const value_type *); - static inline bool equal (const value_type *, const compare_type *); + static inline hashval_t hash (const basic_block); + static inline bool equal_keys (const basic_block, const basic_block); }; -/* Hash function for data base element BB_PBB. */ +/* Hash function. */ inline hashval_t -bb_pbb_hasher::hash (const value_type *bb_pbb) +bb_pbb_hasher::hash (const basic_block bb) { - return (hashval_t)(bb_pbb-bb-index); + return (hashval_t)(bb-index); } /* Compare data base element PB1 and PB2. */ inline bool -bb_pbb_hasher::equal (const value_type *bp1, const compare_type *bp2) +bb_pbb_hasher::equal_keys (const basic_block a, const basic_block b) { - return (bp1-bb-index == bp2-bb-index); + return (a-index == b-index); } -typedef hash_tablebb_pbb_hasher bb_pbb_htab_type; +typedef hash_mapbasic_block, poly_bb_p, bb_pbb_hasher bb_pbb_htab_type; poly_bb_p find_pbb_via_hash (bb_pbb_htab_type *, basic_block); bool loop_is_parallel_p (loop_p, bb_pbb_htab_type *, int); diff --git a/gcc/passes.c b/gcc/passes.c index 91b644e..0533687 100644 --- a/gcc/passes.c +++ b/gcc/passes.c @@ -84,6 +84,7 @@ along with GCC; see the file COPYING3. If not see #include pass_manager.h #include tree-ssa-live.h /* For remove_unused_locals. */ #include tree-cfgcleanup.h +#include hash-map.h using namespace gcc; @@ -687,64 +688,47 @@ pass_manager::register_dump_files (opt_pass *pass) while (pass); } -struct pass_registry -{ - const char* unique_name; - opt_pass *pass; -}; - /* Helper for pass_registry hash table. */ -struct pass_registry_hasher : typed_noop_remove pass_registry +struct pass_registry_hasher : default_hashmap_traits { - typedef pass_registry value_type; - typedef pass_registry compare_type; - static inline hashval_t hash (const value_type *); - static inline bool equal (const value_type *, const compare_type *); + static inline hashval_t hash (const char *); + static inline bool equal_keys (const char *, const char *); }; /* Pass registry hash function. */ inline hashval_t -pass_registry_hasher::hash (const value_type *s) +pass_registry_hasher::hash (const char *name) { - return htab_hash_string (s-unique_name); + return htab_hash_string (name); } /* Hash equal function */ inline bool -pass_registry_hasher::equal (const value_type *s1, const compare_type *s2) +pass_registry_hasher::equal_keys (const char *s1, const char *s2) { - return