From patchwork Fri May 26 17:24:17 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 767489 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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 3wZCgp6fXMz9s78 for ; Sat, 27 May 2017 03:25:07 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="lDx4z3eX"; dkim-atps=neutral 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=hVm85bVAYIZhU9TPpdT8By8Ia7Vg32gXWfz4EsTTEAuDsTL7rF EQ4vvrCQMEzUsX7RttbXPx/cprIeJoEgEhsZpWWIUiKXAI5ntAqq+kHpknDvWVMX WxHZt35I3eOKF3+dyvDB0FlTnq/j2I86/YX+U6DNsi7/ZQpi55YuqHlng= 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=9+Es7ONB+qhDiDd9Qifo8LS47L0=; b=lDx4z3eXeebOBxq0AUfK ebkv0veMH8GK/Wlx+1xvB6CNmwIVcvF3rFEE2Hl0PFLOGW5Z2w4+u2pvU0JApZ4A XLCsKPrIUiNoQBde0H+ABmnZP6KxsfWHW+M9os0OFQSEEy8T2zn328dBt5xCfeaK ZnJBWnZVJTogwrMVvC7XXPY= Received: (qmail 60082 invoked by alias); 26 May 2017 17:24:47 -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 44587 invoked by uid 89); 26 May 2017 17:24:22 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.1 required=5.0 tests=BAYES_00, FREEMAIL_FROM, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mail-yw0-f171.google.com Received: from mail-yw0-f171.google.com (HELO mail-yw0-f171.google.com) (209.85.161.171) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 26 May 2017 17:24:20 +0000 Received: by mail-yw0-f171.google.com with SMTP id l14so7565581ywk.1 for ; Fri, 26 May 2017 10:24:21 -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=Pxr1oBIJC5yZu6GtiU7udLPcGmmCYiAOU5RSkOYNEwA=; b=HpDXSyzCtYaFwbsYrM2mTB57qyS8efLtVeQqpEjLCp6+SqmT4suRHrbzCvV9pgYLDz fsIXzRO3ch8HGG+7CttvtLbULTMnr12dSNE/3PNAvZ+buxk7qHW9kutal7Y0MXRz3Gv5 BVPMTOzFOEt3T+asHpDkvyyhvCD88mSrdVA1UwtPD0qfbthEbjqGV7f64kt+8Lwy9+FW cJSw9mbO0rdHqOrlT/sFzFgjAs/piXaElRWgUgXnOHi9wrlQ/O99PsaFpGQCqQB7JhsP Ca4JYze+BZTG8UhAe3nEZRUvmor25t2oKPeKUX9yP3cN6P9FT3+g2mgskWdWZshMryNo wXXw== X-Gm-Message-State: AODbwcAyYz45SLayVbCMEvPbH2UTFUgf6GwZdydGcB6yNQdXhhVm2UKR KMX3fjnjLc1w9VtG X-Received: by 10.129.155.1 with SMTP id s1mr2510217ywg.278.1495819459774; Fri, 26 May 2017 10:24:19 -0700 (PDT) Received: from ?IPv6:2620:10d:c0a3:20fb:f6d0:5ac5:64cd:f102? ([2620:10d:c091:200::2:a1d1]) by smtp.googlemail.com with ESMTPSA id d12sm585698ywa.44.2017.05.26.10.24.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 26 May 2017 10:24:19 -0700 (PDT) To: GCC Patches From: Nathan Sidwell Subject: [C++ PATCH] inline & using namespace representation Message-ID: <84b100df-c969-3f29-006f-f046623c37b1@acm.org> Date: Fri, 26 May 2017 13:24:17 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.1.0 MIME-Version: 1.0 This patch changes the representation of a namespace's inline children and using directives. Using directive were a TREE_LIST, which (a) held the complete graph and (b) noted the common ancestor. We now need neither of them Inline children were in the using directive list too, but then I stripped them out of there, and one had to look down the namespace binding list. Which isn't the best. The patch makes both a vector of tree, held on lang_decl_ns. Remember I just removed the ns_user member from there, so this isn't an increase in size over all. All the uses of these fields are fixed up in the obvious way. nathan 2017-05-26 Nathan Sidwell gcc/cp/ Inline and using namespace representation change. * cp-tree.h (struct lang_decl_ns): Delete ns_using. Add usings, inlinees as vector. (DECL_NAMESPACE_USING): Adjust. (DECL_NAMESPACE_INLINEES): New. * name-lookup.h (struct cp_binding_level): Change usings representation. * name-lookup.c (name_lookup::do_queue_usings, name_lookup::queue_usings): Adjust. (name_lookup::search_namespace, name_lookup::search_usings, name_lookup::queue_namespace): Adjust. (name_lookup::adl_namespace_only): Adjust. (add_using_namespace, push_namespace): Push onto vector. (pop_namespace): Add timing logic. libcc1/ * libcp1plugin.cc (plugin_make_namespace_inline): Push onto linees. Index: gcc/cp/cp-tree.h =================================================================== --- gcc/cp/cp-tree.h (revision 248517) +++ gcc/cp/cp-tree.h (working copy) @@ -2546,7 +2546,11 @@ struct GTY(()) lang_decl_fn { struct GTY(()) lang_decl_ns { struct lang_decl_base base; cp_binding_level *level; - tree ns_using; + + /* using directives and inline children. These need to be va_gc, + because of PCH. */ + vec *usings; + vec *inlinees; }; /* DECL_LANG_SPECIFIC for parameters. */ @@ -3133,10 +3137,13 @@ struct GTY(()) lang_decl { #define DECL_NAMESPACE_INLINE_P(NODE) \ TREE_LANG_FLAG_0 (NAMESPACE_DECL_CHECK (NODE)) -/* For a NAMESPACE_DECL: the list of using namespace directives - The PURPOSE is the used namespace, the value is the namespace - that is the common ancestor. */ -#define DECL_NAMESPACE_USING(NODE) (LANG_DECL_NS_CHECK (NODE)->ns_using) +/* In a NAMESPACE_DECL, a vector of using directives. */ +#define DECL_NAMESPACE_USING(NODE) \ + (LANG_DECL_NS_CHECK (NODE)->usings) + +/* In a NAMESPACE_DECL, a vector of inline namespaces. */ +#define DECL_NAMESPACE_INLINEES(NODE) \ + (LANG_DECL_NS_CHECK (NODE)->inlinees) /* In a NAMESPACE_DECL, points to the original namespace if this is a namespace alias. */ Index: gcc/cp/name-lookup.c =================================================================== --- gcc/cp/name-lookup.c (revision 248518) +++ gcc/cp/name-lookup.c (working copy) @@ -220,8 +220,10 @@ private: private: using_queue *queue_namespace (using_queue *queue, int depth, tree scope); - using_queue *do_queue_usings (using_queue *queue, int depth, tree usings); - using_queue *queue_usings (using_queue *queue, int depth, tree usings) + using_queue *do_queue_usings (using_queue *queue, int depth, + vec *usings); + using_queue *queue_usings (using_queue *queue, int depth, + vec *usings) { if (usings) queue = do_queue_usings (queue, depth, usings); @@ -496,11 +498,10 @@ name_lookup::search_namespace (tree scop /* Look in exactly namespace. */ bool found = search_namespace_only (scope); - /* Look down into inline namespaces. */ - for (tree inner = NAMESPACE_LEVEL (scope)->namespaces; - inner; inner = TREE_CHAIN (inner)) - if (DECL_NAMESPACE_INLINE_P (inner)) - found |= search_namespace (inner); + /* Recursively look in its inline children. */ + if (vec *inlinees = DECL_NAMESPACE_INLINEES (scope)) + for (unsigned ix = inlinees->length (); ix--;) + found |= search_namespace ((*inlinees)[ix]); if (found) mark_found (scope); @@ -520,17 +521,14 @@ name_lookup::search_usings (tree scope) return true; bool found = false; - - /* Look in direct usings. */ - for (tree usings = DECL_NAMESPACE_USING (scope); - usings; usings = TREE_CHAIN (usings)) - found |= search_qualified (TREE_PURPOSE (usings), true); + if (vec *usings = DECL_NAMESPACE_USING (scope)) + for (unsigned ix = usings->length (); ix--;) + found |= search_qualified ((*usings)[ix], true); /* Look in its inline children. */ - for (tree inner = NAMESPACE_LEVEL (scope)->namespaces; - inner; inner = TREE_CHAIN (inner)) - if (DECL_NAMESPACE_INLINE_P (inner)) - found |= search_usings (inner); + if (vec *inlinees = DECL_NAMESPACE_INLINEES (scope)) + for (unsigned ix = inlinees->length (); ix--;) + found |= search_usings ((*inlinees)[ix]); if (found) mark_found (scope); @@ -580,10 +578,9 @@ name_lookup::queue_namespace (using_queu vec_safe_push (queue, using_pair (common, scope)); /* Queue its inline children. */ - for (tree inner = NAMESPACE_LEVEL (scope)->namespaces; - inner; inner = TREE_CHAIN (inner)) - if (DECL_NAMESPACE_INLINE_P (inner)) - queue = queue_namespace (queue, depth, inner); + if (vec *inlinees = DECL_NAMESPACE_INLINEES (scope)) + for (unsigned ix = inlinees->length (); ix--;) + queue = queue_namespace (queue, depth, (*inlinees)[ix]); /* Queue its using targets. */ queue = queue_usings (queue, depth, DECL_NAMESPACE_USING (scope)); @@ -594,10 +591,11 @@ name_lookup::queue_namespace (using_queu /* Add the namespaces in USINGS to the unqualified search queue. */ name_lookup::using_queue * -name_lookup::do_queue_usings (using_queue *queue, int depth, tree usings) +name_lookup::do_queue_usings (using_queue *queue, int depth, + vec *usings) { - for (; usings; usings = TREE_CHAIN (usings)) - queue = queue_namespace (queue, depth, TREE_PURPOSE (usings)); + for (unsigned ix = usings->length (); ix--;) + queue = queue_namespace (queue, depth, (*usings)[ix]); return queue; } @@ -686,10 +684,9 @@ name_lookup::adl_namespace_only (tree sc mark_seen (scope); /* Look down into inline namespaces. */ - for (tree inner = NAMESPACE_LEVEL (scope)->namespaces; - inner; inner = TREE_CHAIN (inner)) - if (DECL_NAMESPACE_INLINE_P (inner)) - adl_namespace_only (inner); + if (vec *inlinees = DECL_NAMESPACE_INLINEES (scope)) + for (unsigned ix = inlinees->length (); ix--;) + adl_namespace_only ((*inlinees)[ix]); if (cxx_binding *binding = find_namespace_binding (scope, name)) add_fns (ovl_skip_hidden (binding->value)); @@ -5962,13 +5959,14 @@ do_pop_nested_namespace (tree ns) the unqualified search. */ static void -add_using_namespace (tree &usings, tree target) +add_using_namespace (vec *&usings, tree target) { - for (tree probe = usings; probe; probe = TREE_CHAIN (probe)) - if (target == TREE_PURPOSE (probe)) - return; + if (usings) + for (unsigned ix = usings->length (); ix--;) + if ((*usings)[ix] == target) + return; - usings = tree_cons (target, NULL_TREE, usings); + vec_safe_push (usings, target); } /* Tell the debug system of a using directive. */ @@ -6142,8 +6140,14 @@ push_namespace (tree name, bool make_inl else if (TREE_PUBLIC (current_namespace)) TREE_PUBLIC (ns) = 1; + if (name == anon_identifier || make_inline) + emit_debug_info_using_namespace (current_namespace, ns); + if (make_inline) - DECL_NAMESPACE_INLINE_P (ns) = true; + { + DECL_NAMESPACE_INLINE_P (ns) = true; + vec_safe_push (DECL_NAMESPACE_INLINEES (current_namespace), ns); + } } } @@ -6171,10 +6175,14 @@ push_namespace (tree name, bool make_inl void pop_namespace (void) { + bool subtime = timevar_cond_start (TV_NAME_LOOKUP); + gcc_assert (current_namespace != global_namespace); current_namespace = CP_DECL_CONTEXT (current_namespace); /* The binding level is not popped, as it might be re-opened later. */ leave_scope (); + + timevar_cond_stop (TV_NAME_LOOKUP, subtime); } /* External entry points for do_{push_to/pop_from}_top_level. */ Index: gcc/cp/name-lookup.h =================================================================== --- gcc/cp/name-lookup.h (revision 248518) +++ gcc/cp/name-lookup.h (working copy) @@ -194,9 +194,9 @@ struct GTY(()) cp_binding_level { /* A list of USING_DECL nodes. */ tree usings; - /* A list of used namespaces. PURPOSE is the namespace, - VALUE the common ancestor with this binding_level's namespace. */ - tree using_directives; + + /* Using directives. */ + vec *using_directives; /* For the binding level corresponding to a class, the entities declared in the class or its base classes. */ Index: libcc1/libcp1plugin.cc =================================================================== --- libcc1/libcp1plugin.cc (revision 248518) +++ libcc1/libcp1plugin.cc (working copy) @@ -934,6 +934,7 @@ plugin_make_namespace_inline (cc1_plugin return 0; DECL_NAMESPACE_INLINE_P (inline_ns) = true; + vec_safe_push (DECL_NAMESPACE_INLINEES (parent_ns), inline_ns); return 1; }