From patchwork Fri Oct 6 13:13:52 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 822405 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-463640-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="WBN0sjhd"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3y7qpp0Qv2z9t34 for ; Sat, 7 Oct 2017 00:14:08 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=oVYr/gm3O3H/uT968BhgAmEWKAYsxLZ+vhRLiVcfjMImgWDjFN pFTvXB74v+wZOxczqnKivEnacQomdwHl+UY4eHk+oBX2Ls/0nxLiRqFpOLoWDqjc 5Tvy+hq4RWmLgMLd4y0kup9tKWzYu7fBqKJ/MNj3zSEp9q0ofjrfmYf94= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; s= default; bh=4Z/zW8WK+lyq3H8xcEeR3wdN4xk=; b=WBN0sjhdVcHkb7Gq9cLw inXb801pW9x1xM9IILE99izFpgxY+M4ZR+xWh69g4KBBxJxNpwWQFnREylr+jcio I0AQMkUfATcJ9CofpSXOrZ0hpjpxSSr6Sg0VDSsfobGSHcAwjP1/F/59yxaI46+q LrG9Pdjdsj7ojMjy2aVbnpY= Received: (qmail 103196 invoked by alias); 6 Oct 2017 13:13:59 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 103186 invoked by uid 89); 6 Oct 2017 13:13:59 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-10.6 required=5.0 tests=BAYES_00, FREEMAIL_FROM, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mail-qt0-f174.google.com Received: from mail-qt0-f174.google.com (HELO mail-qt0-f174.google.com) (209.85.216.174) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 06 Oct 2017 13:13:57 +0000 Received: by mail-qt0-f174.google.com with SMTP id n61so3302314qte.10 for ; Fri, 06 Oct 2017 06:13:56 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:to:from:subject:message-id:date :user-agent:mime-version:content-language; bh=q+fEFhEnQk9d/yhdmnXlEetophzQ9iyD/1lx/GrwA6M=; b=CmarwjjAIB4t93OsqNCleasf4R2exDYY0v8IbwGAvbDzVkekdEwvKCjZvURQFeFjXm q7p3T48XtR4zSKhytt9GHkoGApbF7lFOsQJQ+YLRvY/AdA/rAkNhUPl577x5+7i1fehM xTjs7UaduQ9ozP4F6TLRY089tJ4j3Xsv+Sfm+XFTqR5VAUuYn6oOlOewu2/VrwXWZofG vR2hUeMcIaU1IqacPSguXqwITXlF8c5ha+AlQt1GE0pq/XvmeZGyP8lhtH/ZkjfBU8nB 6G6bM0YZylYLaFxtMrwh3T4fAt9BR64hc+ubggV5Zftg9Er/kKe4Ya7STI7UP2YksNbQ f4xQ== X-Gm-Message-State: AMCzsaWSJfu2LD+12Z0xJj69OBHP7mijKOR/z21znc5bBQka8jmkQxCx MlZHI3xAKc/rfG63MaOzziI= X-Google-Smtp-Source: AOwi7QBCY7l3wCpBASOD/5wbnp6rAwMcJS837WEZ0VEnpN/nqQk8AT83OXyIOO9iKs96TSZuBFQ4oA== X-Received: by 10.37.248.26 with SMTP id u26mr1520163ybd.137.1507295635104; Fri, 06 Oct 2017 06:13:55 -0700 (PDT) Received: from ?IPv6:2620:10d:c0a3:20fb:7500:e7fb:4a6f:2254? ([2620:10d:c091:200::2:a03f]) by smtp.googlemail.com with ESMTPSA id m8sm551461ywd.27.2017.10.06.06.13.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 06 Oct 2017 06:13:54 -0700 (PDT) To: GCC Patches From: Nathan Sidwell Subject: [C++ PATCH] use hash-table for namespace contents Message-ID: Date: Fri, 6 Oct 2017 09:13:52 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 The one remaining case of us pushing things into a namespace using not-their-name is the anonymous namespace. If we can fix that, then we don't need a hash-map, but can just use a hash-table, which is half the size. This patch does both -- it's simpler than doing this change in two steps. We have a new named_decl_hash trait, that hashes decls (or overloads) by DECL_NAME. The changes to use that are then trivial, and indeed simpler than the hash-map, as we have an INSERT/NO_INSERT arg available to find_namespace_slot. The changes for the anonymous namespace are to give it a NULL name and then set DECL_ASSEMBLER_NAME to the special name it has. do_pushdecl has to be tweaked to allow pushing such decls. We really shouldn't be trying to push (other) unnamed things, and I expect I'll encounter issues there when progressing with the modules stuff. There are still some users of the default_hash_traits specialization, but I'll be nuking them shortly and killing that specialization. Applying to trunk. nathan 2017-10-06 Nathan Sidwell Use hash_table for namespace bindings * cp-tree.h (struct named_decl_hash): New. (lang_decl_ns): Change type of bindings field. * lex.c (maybe_add_lang_decl_raw): Adjust. * name-lookup.c (find_namespace_slot): Adjust. (do_pushdecl): Push NULL-named namespace. (do_push_nested_namespace): Adjust. (push_namespace): Push anonymous namespace as NULL name. Index: cp-tree.h =================================================================== --- cp-tree.h (revision 253485) +++ cp-tree.h (working copy) @@ -828,6 +828,25 @@ class lkp_iterator : public ovl_iterator } }; +/* hash traits for declarations. Hashes potential overload sets via + DECL_NAME. */ + +struct named_decl_hash : ggc_remove +{ + typedef tree value_type; /* A DECL or OVERLOAD */ + typedef tree compare_type; /* An identifier. */ + + inline static hashval_t hash (const value_type decl); + inline static bool equal (const value_type existing, compare_type candidate); + + 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 (); } +}; + struct GTY(()) tree_template_decl { struct tree_decl_common common; tree arguments; @@ -2548,10 +2567,10 @@ struct GTY(()) lang_decl_ns { vec *usings; vec *inlinees; - /* Map from IDENTIFIER nodes to DECLS. It'd be nice to have this - inline, but as the hash_map has a dtor, we can't then put this - struct into a union (until moving to c++11). */ - hash_map *bindings; + /* Hash table of bound decls. It'd be nice to have this inline, but + as the hash_map has a dtor, we can't then put this struct into a + union (until moving to c++11). */ + hash_table *bindings; }; /* DECL_LANG_SPECIFIC for parameters. */ @@ -7370,6 +7389,20 @@ type_unknown_p (const_tree expr) return TREE_TYPE (expr) == unknown_type_node; } +inline hashval_t +named_decl_hash::hash (const value_type decl) +{ + tree name = OVL_NAME (decl); + return name ? IDENTIFIER_HASH_VALUE (name) : 0; +} + +inline bool +named_decl_hash::equal (const value_type existing, compare_type candidate) +{ + tree name = OVL_NAME (existing); + return candidate == name; +} + /* -- end of C++ */ #endif /* ! GCC_CP_TREE_H */ Index: lex.c =================================================================== --- lex.c (revision 253485) +++ lex.c (working copy) @@ -651,7 +651,7 @@ maybe_add_lang_decl_raw (tree t, bool de if (sel == lds_ns) /* Who'd create a namespace, only to put nothing in it? */ - ld->u.ns.bindings = hash_map::create_ggc (499); + ld->u.ns.bindings = hash_table::create_ggc (499); if (GATHER_STATISTICS) { Index: name-lookup.c =================================================================== --- name-lookup.c (revision 253485) +++ name-lookup.c (working copy) @@ -86,17 +86,9 @@ create_local_binding (cp_binding_level * static tree * find_namespace_slot (tree ns, tree name, bool create_p = false) { - tree *slot; - - if (create_p) - { - bool existed; - slot = &DECL_NAMESPACE_BINDINGS (ns)->get_or_insert (name, &existed); - if (!existed) - *slot = NULL_TREE; - } - else - slot = DECL_NAMESPACE_BINDINGS (ns)->get (name); + tree *slot = DECL_NAMESPACE_BINDINGS (ns) + ->find_slot_with_hash (name, name ? IDENTIFIER_HASH_VALUE (name) : 0, + create_p ? INSERT : NO_INSERT); return slot; } @@ -2950,7 +2942,10 @@ do_pushdecl (tree decl, bool is_friend) while (level->kind == sk_class) level = level->level_chain; - if (tree name = DECL_NAME (decl)) + /* An anonymous namespace has a NULL DECL_NAME, but we still want to + insert it. Other NULL-named decls, not so much. */ + tree name = DECL_NAME (decl); + if (name || TREE_CODE (decl) == NAMESPACE_DECL) { cxx_binding *binding = NULL; /* Local scope binding. */ tree ns = NULL_TREE; /* Searched namespace. */ @@ -6615,9 +6610,7 @@ do_push_nested_namespace (tree ns) { do_push_nested_namespace (CP_DECL_CONTEXT (ns)); gcc_checking_assert - (find_namespace_value (current_namespace, - DECL_NAME (ns) ? DECL_NAME (ns) - : anon_identifier) == ns); + (find_namespace_value (current_namespace, DECL_NAME (ns)) == ns); resume_scope (NAMESPACE_LEVEL (ns)); current_namespace = ns; } @@ -6775,10 +6768,7 @@ push_namespace (tree name, bool make_inl /* We should not get here if the global_namespace is not yet constructed nor if NAME designates the global namespace: The global scope is constructed elsewhere. */ - gcc_assert (global_namespace != NULL && name != global_identifier); - - if (!name) - name = anon_identifier; + gcc_checking_assert (global_namespace != NULL && name != global_identifier); tree ns = NULL_TREE; { @@ -6824,11 +6814,9 @@ push_namespace (tree name, bool make_inl ns = NULL_TREE; else { - if (name == anon_identifier) + if (!name) { - /* Clear DECL_NAME for the benefit of debugging back ends. */ - SET_DECL_ASSEMBLER_NAME (ns, name); - DECL_NAME (ns) = NULL_TREE; + SET_DECL_ASSEMBLER_NAME (ns, anon_identifier); if (!make_inline) add_using_namespace (DECL_NAMESPACE_USING (current_namespace), @@ -6843,7 +6831,7 @@ push_namespace (tree name, bool make_inl vec_safe_push (DECL_NAMESPACE_INLINEES (current_namespace), ns); } - if (name == anon_identifier || make_inline) + if (!name || make_inline) emit_debug_info_using_namespace (current_namespace, ns, true); } }