From eead34af3a6a0530a6d5da5b2221c7656c2e2d43 Mon Sep 17 00:00:00 2001 From: Nathan Sidwell Date: Tue, 10 Oct 2017 19:59:12 +0000 Subject: [PATCH] [C++ PATCH] Hash mangling alias https://gcc.gnu.org/ml/gcc-patches/2017-10/msg00618.html * decl2.c (struct mangled_decl_hash): New hash traits. (mangled_decls): Make hash_table. (generate_mangling_alias, record_mangling): Adjust. From-SVN: r253608 --- gcc/cp/ChangeLog | 6 ++++++ gcc/cp/decl2.c | 52 +++++++++++++++++++++++++++++++++++++----------- 2 files changed, 46 insertions(+), 12 deletions(-) diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 0baf3c73356..40c4c2f4184 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2017-10-10 Nathan Sidwell + + * decl2.c (struct mangled_decl_hash): New hash traits. + (mangled_decls): Make hash_table. + (generate_mangling_alias, record_mangling): Adjust. + 2017-10-10 Jason Merrill More delayed lambda capture fixes. diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c index 1cbd11dac45..3c93d5c7cf5 100644 --- a/gcc/cp/decl2.c +++ b/gcc/cp/decl2.c @@ -102,9 +102,35 @@ static GTY(()) vec *no_linkage_decls; is to be an alias for the former if the former is defined. */ static GTY(()) vec *mangling_aliases; -/* A hash table of mangled names to decls. Used to figure out if we - need compatibility aliases. */ -static GTY(()) hash_map *mangled_decls; +/* hash traits for declarations. Hashes single decls via + DECL_ASSEMBLER_NAME. */ + +struct mangled_decl_hash : ggc_remove +{ + typedef tree value_type; /* A DECL. */ + typedef tree compare_type; /* An identifier. */ + + static hashval_t hash (const value_type decl) + { + return IDENTIFIER_HASH_VALUE (DECL_ASSEMBLER_NAME (decl)); + } + static bool equal (const value_type existing, compare_type candidate) + { + tree name = DECL_ASSEMBLER_NAME (existing); + return candidate == name; + } + + static inline void mark_empty (value_type &p) {p = NULL_TREE;} + static inline bool is_empty (value_type p) {return !p;} + + /* Nothing is deletable. Everything is insertable. */ + static bool is_deleted (value_type) { return false; } + static void mark_deleted (value_type) { gcc_unreachable (); } +}; + +/* A hash table of decls keyed by mangled name. Used to figure out if + we need compatibility aliases. */ +static GTY(()) hash_table *mangled_decls; /* Nonzero if we're done parsing and into end-of-file activities. */ @@ -4304,12 +4330,13 @@ generate_mangling_alias (tree decl, tree id2) return; } - bool existed; - tree *slot = &mangled_decls->get_or_insert (id2, &existed); + tree *slot + = mangled_decls->find_slot_with_hash (id2, IDENTIFIER_HASH_VALUE (id2), + INSERT); /* If there's a declaration already using this mangled name, don't create a compatibility alias that conflicts. */ - if (existed) + if (*slot) return; tree alias = make_alias_for (decl, id2); @@ -4369,24 +4396,25 @@ void record_mangling (tree decl, bool need_warning) { if (!mangled_decls) - mangled_decls = hash_map::create_ggc (499); + mangled_decls = hash_table::create_ggc (499); gcc_checking_assert (DECL_ASSEMBLER_NAME_SET_P (decl)); tree id = DECL_ASSEMBLER_NAME (decl); - bool existed; - tree *slot = &mangled_decls->get_or_insert (id, &existed); + tree *slot + = mangled_decls->find_slot_with_hash (id, IDENTIFIER_HASH_VALUE (id), + INSERT); /* If this is already an alias, remove the alias, because the real decl takes precedence. */ - if (existed && DECL_ARTIFICIAL (*slot) && DECL_IGNORED_P (*slot)) + if (*slot && DECL_ARTIFICIAL (*slot) && DECL_IGNORED_P (*slot)) if (symtab_node *n = symtab_node::get (*slot)) if (n->cpp_implicit_alias) { n->remove (); - existed = false; + *slot = NULL_TREE; } - if (!existed) + if (!*slot) *slot = decl; else if (need_warning) { -- 2.30.2