From patchwork Fri Oct 6 14:18:36 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 822476 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-463651-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="fWoQwWmq"; 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 3y7sFR4ZYcz9t2M for ; Sat, 7 Oct 2017 01:18:49 +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=OoTwRty/uNnsrpuFBRoQn+2jYfoMkQNkKVzG6UDFbBLycXnk0M qXxm2QMCIOM2QkeiQAt4+Y9hUlUNhhxppGRzFRhw2ynDV6IqEcxVmz71nf+bAv6O rWEf4iilg5EsX29Bk5cT0IrlLLVzWlcgZHHdYF1bQuEbOw0GM/dNYD13g= 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=+xwvO3V3ngrCGufuI+jg/GblZ18=; b=fWoQwWmqRXdRCLQ3Z6+M L7CbpamAK7UTNSqk9JnBnIkzp2EwwCikG2vuKLoeaOKCbCByLWh6z+Lpa9+LmCbL OhGyZEjsy9giU4+Gewm4jaDpSgXqPVM9vGYbZwZiybTfNw2WyQx4CfdraBMbKJLU qIfw7Fo0O+pJcCUr5fF8mRU= Received: (qmail 70554 invoked by alias); 6 Oct 2017 14:18:42 -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 70543 invoked by uid 89); 6 Oct 2017 14:18:41 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.4 required=5.0 tests=BAYES_00, FREEMAIL_FROM, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy=thereof, 7.5 X-HELO: mail-qt0-f169.google.com Received: from mail-qt0-f169.google.com (HELO mail-qt0-f169.google.com) (209.85.216.169) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 06 Oct 2017 14:18:40 +0000 Received: by mail-qt0-f169.google.com with SMTP id 6so22561824qtw.3 for ; Fri, 06 Oct 2017 07:18:39 -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=A6j8D1ra4ErRLeivpU81SVuOwCJOfeJOtOys9Lmb79s=; b=htvfhJ3zLWy/oiTdXAUn5qB1MNZS7BxlapY1Zd8Lj4Tb8T7U0l4fu6vFA92x1qpn81 gnbF/fBs13nfOrSiWDSXnTqpeDVWLshxMTellFsK7rYVx3zmcSDByll0YndAVYltBmYZ FB7cv5AOHR2B2tQmUeKHsLesafGS2enSIyyET+Ixq6tdVbiUEwMzlaJY5hWCiSgZQK4J 1NGDL4QzysxyoSfF8jvuonp0h2ChRqLLlRlneQXzLWf2YLbF8WNBWQPqdekdPiOxUXb9 4zqdQpYGUUKUhJcqwlqIw3KD1pc2f9Zn/zcZ8Qv9ZzB4OL1inQjlKpYxhiCSorO+ou/X r9/Q== X-Gm-Message-State: AMCzsaW1IIbnU50PCezgI20iu6RbsEoVZ4IP3dNAX7NAWgwy5kvk0Ht4 8YKeGIyUu/POg/lgL0rBzY4= X-Google-Smtp-Source: AOwi7QAKl35Fjl7o5mmEzvRpFRsUI7499kKFjBTUkNmSeN/4lG35iy/TTu/z1mOZv0jUcbMd4S5ivQ== X-Received: by 10.129.160.214 with SMTP id x205mr1724595ywg.145.1507299518145; Fri, 06 Oct 2017 07:18:38 -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 q16sm475856ywa.2.2017.10.06.07.18.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 06 Oct 2017 07:18:37 -0700 (PDT) To: GCC Patches From: Nathan Sidwell Subject: [C++ PATCH] hash-table for extern-c fns. Message-ID: <8423b154-14ac-0263-aa18-01752c6894ef@acm.org> Date: Fri, 6 Oct 2017 10:18:36 -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 converts the extern "C" function map to use a hash table, in the same way as I've just changed namespace bindings. There's a small wart, in that the c_linkage_bindings user (in c-common) expects either a single decl or a TREE_LIST. I.e. not an OVERLOAD. But the hasher expects either a DECL or an OVERLOAD. Rather than extend the hasher (and marginally pessimize it for this special case), I modify the extern-c table handling to insert an initial OVERLOAD node, when there are multiple functions. That can CHAIN directly to a TREE_LIST. Sure, we have a wasted OVERLOAD node in this case, but it's going to be rare -- programs don't usually declare extern "C" functions of the same name in different namespaces. Changing the c-common function is harder, as OVERLOAD is a C++ FE local node. Applying to trunk. nathan 2017-10-06 Nathan Sidwell Use hash_table for extern "C" names * name-lookup.c (extern_c_fns): Use hash_table. (check_extern_c_conflict): Adjust. (c_linkage_bindings): Adjust. Index: name-lookup.c =================================================================== --- name-lookup.c (revision 253489) +++ name-lookup.c (working copy) @@ -2511,9 +2511,9 @@ update_binding (cp_binding_level *level, return decl; } -/* Map of identifiers to extern C functions (or LISTS thereof). */ +/* Table of identifiers to extern C functions (or LISTS thereof). */ -static GTY(()) hash_map *extern_c_fns; +static GTY(()) hash_table *extern_c_fns; /* DECL has C linkage. If we have an existing instance, make sure it has the same exception specification [7.5, 7.6]. If there's no @@ -2527,17 +2527,15 @@ check_extern_c_conflict (tree decl) return; if (!extern_c_fns) - extern_c_fns = hash_map::create_ggc (127); + extern_c_fns = hash_table::create_ggc (127); - bool existed; - tree *slot = &extern_c_fns->get_or_insert (DECL_NAME (decl), &existed); - if (!existed) - *slot = decl; - else + tree *slot = extern_c_fns + ->find_slot_with_hash (DECL_NAME (decl), + IDENTIFIER_HASH_VALUE (DECL_NAME (decl)), INSERT); + if (tree old = *slot) { - tree old = *slot; - if (TREE_CODE (old) == TREE_LIST) - old = TREE_VALUE (old); + if (TREE_CODE (old) == OVERLOAD) + old = OVL_FUNCTION (old); int mismatch = 0; if (DECL_CONTEXT (old) == DECL_CONTEXT (decl)) @@ -2563,9 +2561,24 @@ check_extern_c_conflict (tree decl) "due to different exception specifications"); } else - /* Chain it on for c_linkage_binding's use. */ - *slot = tree_cons (NULL_TREE, decl, *slot); + { + if (old == *slot) + /* The hash table expects OVERLOADS, so construct one with + OLD as both the function and the chain. This allocate + an excess OVERLOAD node, but it's rare to have multiple + extern "C" decls of the same name. And we save + complicating the hash table logic (which is used + elsewhere). */ + *slot = ovl_make (old, old); + + slot = &OVL_CHAIN (*slot); + + /* Chain it on for c_linkage_binding's use. */ + *slot = tree_cons (NULL_TREE, decl, *slot); + } } + else + *slot = decl; } /* Returns a list of C-linkage decls with the name NAME. Used in @@ -2575,8 +2588,15 @@ tree c_linkage_bindings (tree name) { if (extern_c_fns) - if (tree *slot = extern_c_fns->get (name)) - return *slot; + if (tree *slot = extern_c_fns + ->find_slot_with_hash (name, IDENTIFIER_HASH_VALUE (name), NO_INSERT)) + { + tree result = *slot; + if (TREE_CODE (result) == OVERLOAD) + result = OVL_CHAIN (result); + return result; + } + return NULL_TREE; }