aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorRichard Sandiford <richard.sandiford@arm.com>2015-06-25 17:16:23 +0000
committerRichard Sandiford <rsandifo@gcc.gnu.org>2015-06-25 17:16:23 +0000
commit20d2c372c21b9f92b30428d7b545af320d7d2303 (patch)
treeef11c0ce585dd35735de0a607dd716f3fa308d6e /gcc
parent84a98514b3d659ab6ca4b6bc624a1b7453fa0daa (diff)
downloadgcc-20d2c372c21b9f92b30428d7b545af320d7d2303.zip
gcc-20d2c372c21b9f92b30428d7b545af320d7d2303.tar.gz
gcc-20d2c372c21b9f92b30428d7b545af320d7d2303.tar.bz2
hash-traits.h (string_hash, [...]): New classes.
gcc/ * hash-traits.h (string_hash, nofree_string_hash): New classes. * genmatch.c (capture_id_map_hasher): Use nofree_string_hash. * passes.c (pass_registry_hasher): Likewise. * config/alpha/alpha.c (string_traits): Likewise. * config/i386/winnt.c (i386_find_on_wrapper_list): Likewise. * config/m32c/m32c.c (pragma_traits): Likewise. * config/mep/mep.c (pragma_traits): Likewise. gcc/java/ * jcf-io.c (memoized_class_lookups): Use nofree_string_hash. (find_class): Likewise. From-SVN: r224971
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog10
-rw-r--r--gcc/config/alpha/alpha.c8
-rw-r--r--gcc/config/i386/winnt.c27
-rw-r--r--gcc/config/m32c/m32c.c11
-rw-r--r--gcc/config/mep/mep.c10
-rw-r--r--gcc/genmatch.c21
-rw-r--r--gcc/hash-traits.h26
-rw-r--r--gcc/java/ChangeLog5
-rw-r--r--gcc/java/jcf-io.c28
-rw-r--r--gcc/passes.c24
10 files changed, 51 insertions, 119 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 6389191..33c3c0d 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,5 +1,15 @@
2015-06-25 Richard Sandiford <richard.sandiford@arm.com>
+ * hash-traits.h (string_hash, nofree_string_hash): New classes.
+ * genmatch.c (capture_id_map_hasher): Use nofree_string_hash.
+ * passes.c (pass_registry_hasher): Likewise.
+ * config/alpha/alpha.c (string_traits): Likewise.
+ * config/i386/winnt.c (i386_find_on_wrapper_list): Likewise.
+ * config/m32c/m32c.c (pragma_traits): Likewise.
+ * config/mep/mep.c (pragma_traits): Likewise.
+
+2015-06-25 Richard Sandiford <richard.sandiford@arm.com>
+
* tree-hash-traits.h (tree_hash): New class.
* except.c: Include tree-hash-traits.h.
(tree_hash_traits): Use tree_hash.
diff --git a/gcc/config/alpha/alpha.c b/gcc/config/alpha/alpha.c
index 122f586..3970278 100644
--- a/gcc/config/alpha/alpha.c
+++ b/gcc/config/alpha/alpha.c
@@ -4806,13 +4806,7 @@ alpha_multipass_dfa_lookahead (void)
struct GTY(()) alpha_links;
-struct string_traits : default_hashmap_traits
-{
- static bool equal_keys (const char *const &a, const char *const &b)
- {
- return strcmp (a, b) == 0;
- }
-};
+typedef simple_hashmap_traits <nofree_string_hash> string_traits;
struct GTY(()) machine_function
{
diff --git a/gcc/config/i386/winnt.c b/gcc/config/i386/winnt.c
index 47ea87a..a30215b 100644
--- a/gcc/config/i386/winnt.c
+++ b/gcc/config/i386/winnt.c
@@ -707,29 +707,6 @@ i386_pe_record_stub (const char *name)
#ifdef CXX_WRAP_SPEC_LIST
-/* Hashtable helpers. */
-
-struct wrapped_symbol_hasher : nofree_ptr_hash <const char>
-{
- static inline hashval_t hash (const char *);
- static inline bool equal (const char *, const char *);
- static inline void remove (const char *);
-};
-
-inline hashval_t
-wrapped_symbol_hasher::hash (const char *v)
-{
- return htab_hash_string (v);
-}
-
-/* Hash table equality helper function. */
-
-inline bool
-wrapped_symbol_hasher::equal (const char *x, const char *y)
-{
- return !strcmp (x, y);
-}
-
/* Search for a function named TARGET in the list of library wrappers
we are using, returning a pointer to it if found or NULL if not.
This function might be called on quite a few symbols, and we only
@@ -741,7 +718,7 @@ static const char *
i386_find_on_wrapper_list (const char *target)
{
static char first_time = 1;
- static hash_table<wrapped_symbol_hasher> *wrappers;
+ static hash_table<nofree_string_hash> *wrappers;
if (first_time)
{
@@ -754,7 +731,7 @@ i386_find_on_wrapper_list (const char *target)
char *bufptr;
/* Breaks up the char array into separated strings
strings and enter them into the hash table. */
- wrappers = new hash_table<wrapped_symbol_hasher> (8);
+ wrappers = new hash_table<nofree_string_hash> (8);
for (bufptr = wrapper_list_buffer; *bufptr; ++bufptr)
{
char *found = NULL;
diff --git a/gcc/config/m32c/m32c.c b/gcc/config/m32c/m32c.c
index 83209aa..7dd1753 100644
--- a/gcc/config/m32c/m32c.c
+++ b/gcc/config/m32c/m32c.c
@@ -3053,16 +3053,7 @@ m32c_insert_attributes (tree node ATTRIBUTE_UNUSED,
}
}
-
-struct pragma_traits : default_hashmap_traits
-{
- static hashval_t hash (const char *str) { return htab_hash_string (str); }
- static bool
- equal_keys (const char *a, const char *b)
- {
- return !strcmp (a, b);
- }
-};
+typedef simple_hashmap_traits<nofree_string_hash> pragma_traits;
/* Hash table of pragma info. */
static GTY(()) hash_map<const char *, unsigned, pragma_traits> *pragma_htab;
diff --git a/gcc/config/mep/mep.c b/gcc/config/mep/mep.c
index 5f710e2..3698bb0 100644
--- a/gcc/config/mep/mep.c
+++ b/gcc/config/mep/mep.c
@@ -4071,15 +4071,7 @@ struct GTY(()) pragma_entry {
int flag;
};
-struct pragma_traits : default_hashmap_traits
-{
- static hashval_t hash (const char *s) { return htab_hash_string (s); }
- static bool
- equal_keys (const char *a, const char *b)
- {
- return strcmp (a, b) == 0;
- }
-};
+typedef simple_hashmap_traits<nofree_string_hash> pragma_traits;
/* Hash table of farcall-tagged sections. */
static GTY(()) hash_map<const char *, pragma_entry, pragma_traits> *
diff --git a/gcc/genmatch.c b/gcc/genmatch.c
index 2652105..b0b9290 100644
--- a/gcc/genmatch.c
+++ b/gcc/genmatch.c
@@ -395,26 +395,7 @@ get_operator (const char *id)
return 0;
}
-
-/* Helper for the capture-id map. */
-
-struct capture_id_map_hasher : default_hashmap_traits
-{
- static inline hashval_t hash (const char *);
- static inline bool equal_keys (const char *, const char *);
-};
-
-inline hashval_t
-capture_id_map_hasher::hash (const char *id)
-{
- return htab_hash_string (id);
-}
-
-inline bool
-capture_id_map_hasher::equal_keys (const char *id1, const char *id2)
-{
- return strcmp (id1, id2) == 0;
-}
+typedef simple_hashmap_traits<nofree_string_hash> capture_id_map_hasher;
typedef hash_map<const char *, unsigned, capture_id_map_hasher> cid_map_t;
diff --git a/gcc/hash-traits.h b/gcc/hash-traits.h
index c580de9..8f97646 100644
--- a/gcc/hash-traits.h
+++ b/gcc/hash-traits.h
@@ -121,6 +121,27 @@ pointer_hash <Type>::is_empty (Type *e)
return e == NULL;
}
+/* Hasher for "const char *" strings, using string rather than pointer
+ equality. */
+
+struct string_hash : pointer_hash <const char>
+{
+ static inline hashval_t hash (const char *);
+ static inline bool equal (const char *, const char *);
+};
+
+inline hashval_t
+string_hash::hash (const char *id)
+{
+ return htab_hash_string (id);
+}
+
+inline bool
+string_hash::equal (const char *id1, const char *id2)
+{
+ return strcmp (id1, id2) == 0;
+}
+
/* Remover and marker for entries in gc memory. */
template<typename T>
@@ -190,6 +211,11 @@ struct ggc_ptr_hash : pointer_hash <T>, ggc_remove <T *> {};
template <typename T>
struct ggc_cache_ptr_hash : pointer_hash <T>, ggc_cache_remove <T *> {};
+/* Traits for string elements that should not be freed when an element
+ is deleted. */
+
+struct nofree_string_hash : string_hash, typed_noop_remove <const char *> {};
+
template <typename T> struct default_hash_traits;
template <typename T>
diff --git a/gcc/java/ChangeLog b/gcc/java/ChangeLog
index 6a93304..96a5c63 100644
--- a/gcc/java/ChangeLog
+++ b/gcc/java/ChangeLog
@@ -1,5 +1,10 @@
2015-06-25 Richard Sandiford <richard.sandiford@arm.com>
+ * jcf-io.c (memoized_class_lookups): Use nofree_string_hash.
+ (find_class): Likewise.
+
+2015-06-25 Richard Sandiford <richard.sandiford@arm.com>
+
* java-tree.h (treetreehasher): Inherit from ggc_ptr_hash
rather than ggc_hasher.
(ict_hasher, type_assertion_hasher): Likewise.
diff --git a/gcc/java/jcf-io.c b/gcc/java/jcf-io.c
index 91fe952..be251d4 100644
--- a/gcc/java/jcf-io.c
+++ b/gcc/java/jcf-io.c
@@ -272,33 +272,11 @@ find_classfile (char *filename, JCF *jcf, const char *dep_name)
return open_class (filename, jcf, fd, dep_name);
}
-
-/* Hash table helper. */
-
-struct charstar_hash : nofree_ptr_hash <const char>
-{
- static inline hashval_t hash (const char *candidate);
- static inline bool equal (const char *existing, const char *candidate);
-};
-
-inline hashval_t
-charstar_hash::hash (const char *candidate)
-{
- return htab_hash_string (candidate);
-}
-
-inline bool
-charstar_hash::equal (const char *existing, const char *candidate)
-{
- return strcmp (existing, candidate) == 0;
-}
-
-
/* A hash table keeping track of class names that were not found
during class lookup. (There is no need to cache the values
associated with names that were found; they are saved in
IDENTIFIER_CLASS_VALUE.) */
-static hash_table<charstar_hash> *memoized_class_lookups;
+static hash_table<nofree_string_hash> *memoized_class_lookups;
/* Returns a freshly malloc'd string with the fully qualified pathname
of the .class file for the class CLASSNAME. CLASSNAME must be
@@ -321,11 +299,11 @@ find_class (const char *classname, int classname_length, JCF *jcf)
/* Create the hash table, if it does not already exist. */
if (!memoized_class_lookups)
- memoized_class_lookups = new hash_table<charstar_hash> (37);
+ memoized_class_lookups = new hash_table<nofree_string_hash> (37);
/* Loop for this class in the hashtable. If it is present, we've
already looked for this class and failed to find it. */
- hash = charstar_hash::hash (classname);
+ hash = nofree_string_hash::hash (classname);
if (memoized_class_lookups->find_with_hash (classname, hash))
return NULL;
diff --git a/gcc/passes.c b/gcc/passes.c
index c66741e..c0a9006 100644
--- a/gcc/passes.c
+++ b/gcc/passes.c
@@ -858,29 +858,7 @@ pass_manager::register_dump_files (opt_pass *pass)
while (pass);
}
-/* Helper for pass_registry hash table. */
-
-struct pass_registry_hasher : default_hashmap_traits
-{
- 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 char *name)
-{
- return htab_hash_string (name);
-}
-
-/* Hash equal function */
-
-inline bool
-pass_registry_hasher::equal_keys (const char *s1, const char *s2)
-{
- return !strcmp (s1, s2);
-}
+typedef simple_hashmap_traits<nofree_string_hash> pass_registry_hasher;
static hash_map<const char *, opt_pass *, pass_registry_hasher>
*name_to_pass_map;