From patchwork Wed Dec 7 12:54:41 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 87095 Delivered-To: patch@linaro.org Received: by 10.140.20.101 with SMTP id 92csp298954qgi; Wed, 7 Dec 2016 04:56:03 -0800 (PST) X-Received: by 10.99.207.17 with SMTP id j17mr117868943pgg.57.1481115363470; Wed, 07 Dec 2016 04:56:03 -0800 (PST) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id a17si23952852pgi.189.2016.12.07.04.56.03 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 07 Dec 2016 04:56:03 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-return-443680-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org; spf=pass (google.com: domain of gcc-patches-return-443680-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-443680-patch=linaro.org@gcc.gnu.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to:cc :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=liK7mIaNEIRSpR/1J3OzfhQNhQ4EN9KmwqSowmNM3Uso25C2UE mVUZVbVFK6GcT/sXmaY3gpl8Qq8oEo5J2ycazNwBEGREZmP2yxNHS+TfxsGECObq +oYCpayA/Ci/gaVxBYAeP5CTfuYnjtJCWoBEXiO/eaBKDpsbeH9tAUyYc= 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:cc :from:subject:message-id:date:mime-version:content-type; s= default; bh=9kkqFOZXE+6sZVpnAKt0EuB2qlw=; b=u35e0Sqaebip+yySXqUk EBbVlDmRT0RkDqu6SlF5D9S7rvrD7VIqgTQqn5c0gizZXQ/ekmyWZN+FhmPryLdb /kiW18xdhvLIqnvIsBbqdObRPOiZ7ebyeLCPMsS1VdLwTdqAS2ZEcMTquagvqBOw BDL08NrsSFEoJzg0iEG10mA= Received: (qmail 56286 invoked by alias); 7 Dec 2016 12:54:57 -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 56270 invoked by uid 89); 7 Dec 2016 12:54:56 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.1 required=5.0 tests=BAYES_00, FREEMAIL_FROM, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=no version=3.3.2 spammy=U*nathan, nathan@acm.org, nathanacmorg, D*acm.org X-HELO: mail-yw0-f194.google.com Received: from mail-yw0-f194.google.com (HELO mail-yw0-f194.google.com) (209.85.161.194) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 07 Dec 2016 12:54:45 +0000 Received: by mail-yw0-f194.google.com with SMTP id b66so31795551ywh.2 for ; Wed, 07 Dec 2016 04:54:45 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:to:cc:from:subject:message-id:date :user-agent:mime-version; bh=sDSENAUrbuEk0TY7gIsiGq9pw92OcvLmYaR/ylHi2Ic=; b=Pa6Qjs+1HD5WspAvk1JibGhMLj0bUiOdAEISyMv2KKsaWPBRYcjPjCmOaTn4sGBLvP OZh+BQBOOChlIckLlcEWbIPaz5Fp8ZkXB/9qOSjGZPZj2BnPC+jEutkC2xVLHQJm368Z /u2RoBZSvnRDS39Cll/rK081AaQ1lUgUKTcCd0q5E9MP4deKWoRCyunod4weXT9A7WLm OWOddC1ovQbZxIfuusLiAnJjn9T6yzFYOqGCzddxQyJO85TQctfx8wu2BuC6umYT4Nsh HgALW85SPZdvHpagLxvuT3HBlQVpTxsqfEE+csZAz6kuFwrWRvdeM/SKf9dF/1teL3DV WovQ== X-Gm-Message-State: AKaTC02hQRT9pBpFYRylceqmTVhXuyE9TKZt4HM/ffe0ocQP6hT3A3OZGsxkVQK+KIY0ZA== X-Received: by 10.37.176.68 with SMTP id e4mr18345919ybj.38.1481115284160; Wed, 07 Dec 2016 04:54:44 -0800 (PST) Received: from ?IPv6:2620:10d:c0a3:20fb:f6d0:5ac5:64cd:f102? ([2620:10d:c091:200::a:6eb0]) by smtp.googlemail.com with ESMTPSA id b197sm10063284ywe.56.2016.12.07.04.54.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 07 Dec 2016 04:54:43 -0800 (PST) To: GCC Patches Cc: Jason Merrill From: Nathan Sidwell Subject: [C++ PATCH] cache auto/decltype(auto) identifiers Message-ID: <5f3dfd02-4ff9-4450-9ca5-e58038e3b5e8@acm.org> Date: Wed, 7 Dec 2016 07:54:41 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.5.1 MIME-Version: 1.0 While lookign at generic lambda mangling, I noticed we like to use 'get_identifier ("auto")' a lot. Particularly in is_auto, which is called during tree walking. That's needlessly expensive. Fixed by adding a couple of new global identifiers. Committed. nathan -- Nathan Sidwell 2016-12-07 Nathan Sidwell * cp-tree.h (enum cp_tree_index): Add CPTI_AUTO_IDENTIFIER & CPTI_DECLTYPE_AUTO_IDENTIFIER. (auto_identifier, decltype_auto_identifier): New. *decl.c (initialize_predefined_identifiers): Add 'auto' and 'decltype(auto)'. (grokdeclarator): Use cached identifier. * pt.c (make_decltype_auto, make_auto, make_constrained_auto, is_auto): Likewise. Index: cp/cp-tree.h =================================================================== --- cp/cp-tree.h (revision 243314) +++ cp/cp-tree.h (working copy) @@ -1117,6 +1117,8 @@ enum cp_tree_index CPTI_PFN_IDENTIFIER, CPTI_VPTR_IDENTIFIER, CPTI_STD_IDENTIFIER, + CPTI_AUTO_IDENTIFIER, + CPTI_DECLTYPE_AUTO_IDENTIFIER, CPTI_LANG_NAME_C, CPTI_LANG_NAME_CPLUSPLUS, @@ -1200,6 +1202,9 @@ extern GTY(()) tree cp_global_trees[CPTI #define vptr_identifier cp_global_trees[CPTI_VPTR_IDENTIFIER] /* The name of the std namespace. */ #define std_identifier cp_global_trees[CPTI_STD_IDENTIFIER] +/* auto and declspec(auto) identifiers. */ +#define auto_identifier cp_global_trees[CPTI_AUTO_IDENTIFIER] +#define decltype_auto_identifier cp_global_trees[CPTI_DECLTYPE_AUTO_IDENTIFIER] /* The name of a C++17 deduction guide. */ #define lang_name_c cp_global_trees[CPTI_LANG_NAME_C] #define lang_name_cplusplus cp_global_trees[CPTI_LANG_NAME_CPLUSPLUS] Index: cp/decl.c =================================================================== --- cp/decl.c (revision 243314) +++ cp/decl.c (working copy) @@ -4034,6 +4034,8 @@ initialize_predefined_identifiers (void) { "__vtt_parm", &vtt_parm_identifier, 0 }, { "::", &global_scope_name, 0 }, { "std", &std_identifier, 0 }, + { "auto", &auto_identifier, 0 }, + { "decltype(auto)", &decltype_auto_identifier, 0 }, { NULL, NULL, 0 } }; @@ -10600,7 +10602,7 @@ grokdeclarator (const cp_declarator *dec gcc_unreachable (); } if (TREE_CODE (type) != TEMPLATE_TYPE_PARM - || TYPE_IDENTIFIER (type) != get_identifier ("auto")) + || TYPE_IDENTIFIER (type) != auto_identifier) { if (type != error_mark_node) { Index: cp/pt.c =================================================================== --- cp/pt.c (revision 243314) +++ cp/pt.c (working copy) @@ -24302,13 +24302,13 @@ make_auto_1 (tree name, bool set_canonic tree make_decltype_auto (void) { - return make_auto_1 (get_identifier ("decltype(auto)"), true); + return make_auto_1 (decltype_auto_identifier, true); } tree make_auto (void) { - return make_auto_1 (get_identifier ("auto"), true); + return make_auto_1 (auto_identifier, true); } /* Return a C++17 deduction placeholder for class template TMPL. */ @@ -24330,7 +24330,7 @@ make_template_placeholder (tree tmpl) tree make_constrained_auto (tree con, tree args) { - tree type = make_auto_1 (get_identifier ("auto"), false); + tree type = make_auto_1 (auto_identifier, false); /* Build the constraint. */ tree tmpl = DECL_TI_TEMPLATE (con); @@ -25016,8 +25016,8 @@ bool is_auto (const_tree type) { if (TREE_CODE (type) == TEMPLATE_TYPE_PARM - && (TYPE_IDENTIFIER (type) == get_identifier ("auto") - || TYPE_IDENTIFIER (type) == get_identifier ("decltype(auto)") + && (TYPE_IDENTIFIER (type) == auto_identifier + || TYPE_IDENTIFIER (type) == decltype_auto_identifier || CLASS_PLACEHOLDER_TEMPLATE (type))) return true; else