From patchwork Tue Oct 10 19:58:21 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 824042 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-463894-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="cjvZOS1b"; 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 3yBSbc1wPyz9t5s for ; Wed, 11 Oct 2017 06:58:36 +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=nasHmlBxTAAsX5RIFLlh4PNokVFXw1xyTAyMelcsu2ktv23fkF tW5R1hC0V+MX3lOZeGuMzk0jr90fQPWlXSBQzAp7A6cn24IPKiT4XmoZKtkUAoNr /2CS1ElnoDnpmU1CsuN4qz5cFyD2DywNw+Kr5/V4iwbAnWLLEQ3h8YO4A= 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=YruRuDH1gEhrbHSF4NQvXFZLLiw=; b=cjvZOS1bopons9WYjFKs x9c64cRJK6aLlEFJIi6Wgdxxq1AtiYCc1Pnu+DAdXBcUr2pfkUJaIFlVYlmGSnN0 3nNjiUODHb+VJNyOcwfgOlSzh3tHXWQ2e++SttWIVlh0rCgbgqPsyfmU9wzwTTnC obs2EWPbqrrvVpX/oy71cd0= Received: (qmail 81934 invoked by alias); 10 Oct 2017 19:58:27 -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 81924 invoked by uid 89); 10 Oct 2017 19:58:26 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-12.1 required=5.0 tests=BAYES_00, FREEMAIL_FROM, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_LOW, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mail-qt0-f182.google.com Received: from mail-qt0-f182.google.com (HELO mail-qt0-f182.google.com) (209.85.216.182) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 10 Oct 2017 19:58:25 +0000 Received: by mail-qt0-f182.google.com with SMTP id n61so26918363qte.10 for ; Tue, 10 Oct 2017 12:58:24 -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=nMB/lBqv8sjHmjJXMRj/Nszl7q1ZqEOTidmOckXC+Qw=; b=SEtQBaYFs5my8arBSqSi77Y8uMFl9rdkca51HvHI3f7MFOsu+Zec3ZM8exLATawjtL JjmDwf4W1W61jaCHxPKTbilrd900txPJK1WW2c/y+iUlDuGYb4iavNqyQvVhAjY2hy/0 pHLI3yHycr+gqyZJ2d9NujjsWDde1oZmun28hqS1MIje5DGmQIUP4HeqpR0pcBOKNTvJ S3GkkCoTYa2k0CBWCd9TkqEMFTLZckolipUXMOzMMSn0pXSuVu4F+9e7kM6lJvLEmYv2 31B3rNfpEtmuY4JAoVVq1u0M5Rkh2QX1YDH2L8w3XacSrF0lx15Vxeoj2kYSOdEFYUtn W7xQ== X-Gm-Message-State: AMCzsaV9JFUT+qwV7xRAnOANDOsi0tsETKIfkqElUHIsr4fj4XcsFGBm OAAG1Ez+JcREA6U2cu8GeLQ= X-Google-Smtp-Source: AOwi7QBQyd7ro1ub87u/NwJpNQsYiZmjaRZ/k8lpK9n6YfR+sxehgTi6lX5dwGRK/XUNLDv+VelVUw== X-Received: by 10.129.175.83 with SMTP id x19mr2871742ywj.289.1507665503440; Tue, 10 Oct 2017 12:58:23 -0700 (PDT) Received: from ?IPv6:2620:10d:c0a3:20fb:7500:e7fb:4a6f:2254? ([2620:10d:c091:200::3:9bf7]) by smtp.googlemail.com with ESMTPSA id g2sm4203385ywa.94.2017.10.10.12.58.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 10 Oct 2017 12:58:22 -0700 (PDT) To: GCC Patches From: Nathan Sidwell Subject: [C++ PATCH] Hash mangling alias Message-ID: Date: Tue, 10 Oct 2017 15:58:21 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 This patch changes the mangling alias hash_map to a hash_table, hashing by DECL_ASSEMBLER_NAME. Thus halving its size. It continues to use DECL_ASSEMBLER_NAME, not the new DECL_ASSEMBLER_NAME_RAW I posted earlier today. When (if) that gets the ok, I'll adjust this fragment too. Applying to trunk. nathan 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. Index: decl2.c =================================================================== --- decl2.c (revision 253605) +++ decl2.c (working copy) @@ -102,9 +102,35 @@ static GTY(()) vec *no_link 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 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) {