From patchwork Mon Nov 6 12:23:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 161993 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:8f47:0:b0:403:3b70:6f57 with SMTP id j7csp2616789vqu; Mon, 6 Nov 2023 04:24:00 -0800 (PST) X-Google-Smtp-Source: AGHT+IHXOQrZTA91sW2zWxkImQqT88MZSksW7LtdB5Z8d5pD05lE1k8T8gajlJIzEoY+GXCaoNe/ X-Received: by 2002:ac8:5852:0:b0:40f:ce6d:775e with SMTP id h18-20020ac85852000000b0040fce6d775emr37302731qth.42.1699273440484; Mon, 06 Nov 2023 04:24:00 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1699273440; cv=pass; d=google.com; s=arc-20160816; b=UBcqjRAVfkDa1DdEdcNfSMZOaLphTy/+VYPBKfW6l4tXfeKAUPGeL+RK+3wPWBFLKh 5JFo4EwA4I7K8obMZRZ/xktHu10221gqYQhQ8f3wMKLrlT54Mfudemi6dAshw3N+8kwP 7oo3FYmJ0KqtgYbhoH1UNRONbdrHlxw+/xlOnYPoLAewVBO8Du0JroJTrnb1cjWXfjIJ aPR6EphVHbkyiKG2ULQv5CPwmlnTeKeFQPGdRkda2OVHkxMUOdaQpn2zN/G73vp7rkaW KSha97mpb5ls4JP4PIxYGSvGhIhhLPWyYJELxgraJ+7qM3wsAe5Is/8AmxxH0qTMj4sa FjaQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:mime-version:user-agent :message-id:date:subject:mail-followup-to:to:from:arc-filter :dmarc-filter:delivered-to; bh=fQSFD+MdguwP/CGjFWIIooFyxYTxSJ3c4HbfCTKdT2I=; fh=hPrbWPhweUx4V0GV9uXJqbyAzg2ABmTz7kczrAQqMmM=; b=Kb/1j8092s3+nhrnCb4JOF4+RAWCjlBsfXQb5oGpLOtct/xMZW/1AFCceHwiaa6OCp a2xUYvW+VNWhuJwdbqgwXImj6MojxgMGWbuSxuutp0TD91TYyEH3CXqOUYdYSPXK72UH ic2lFOGBX2dXVMhsCiT8+3E7VQHiV3IOOFak4MBucPqr3d5sGn+1D4QK/w7dnwnM7quo oRUeL9cH28Qy2v1joenODT7rMwSjNgStQGyLRcr8j3WR9Utx4led0jQPi7ZlH8I8NSi1 7ZfayY6VdSVUKzFhvS8mEtkjusR1Fh42334SwfiBtLg0bzairej+70JFlcWAJRAgwSI+ 2CkA== ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id v2-20020a05622a188200b0041816d65a98si5471188qtc.421.2023.11.06.04.24.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 04:24:00 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 417263858C2B for ; Mon, 6 Nov 2023 12:24:00 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by sourceware.org (Postfix) with ESMTP id 243043858C2B for ; Mon, 6 Nov 2023 12:23:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 243043858C2B Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=arm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 243043858C2B Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699273419; cv=none; b=sUNlnBhVJdd3m0ckBUMVuduL1lvfED0Gb+v/bEhe0VU9dui3Mel7kQteQOe0l39PhbZz8bIsz+5GIg3ZxtUl2kySkUvj2z5g4YQ6Puax2lmkrrC5Vv7RumNj55YQSc0A1hhFoI4sq0Lf7hgn78S1YFYfRsMMt7e9oqmZDOL4zRc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699273419; c=relaxed/simple; bh=LK/m6I/irTWmnUChnRip9VuWTngyGZv+nelYD4XN5NQ=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=hF/EQOHtde5rWMczL2Ife2GgoDJKp4KjmmRMHjHNMibjKhyF3VPyx1Ndv7a6QLhAJWSQMOy+qm4xoYP4hJ4IYeV2tEV2ZVB/JAVFoNpqGmaZU7tECoJoDfJFaN8e8JCBK+a4W7KGIYO8P5GCZeolOjKaO4t1U+i+eNr9+5IqcrY= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id B958C1FB for ; Mon, 6 Nov 2023 04:24:20 -0800 (PST) Received: from localhost (e121540-lin.manchester.arm.com [10.32.110.72]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 3681E3F64C for ; Mon, 6 Nov 2023 04:23:36 -0800 (PST) From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.sandiford@arm.com Subject: [PATCH 1/3] attribs: Cache the gnu namespace Date: Mon, 06 Nov 2023 12:23:34 +0000 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) MIME-Version: 1.0 X-Spam-Status: No, score=-23.3 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_NONE, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1781817347347098963 X-GMAIL-MSGID: 1781817347347098963 Later patches add more calls to get_attribute_namespace. For scoped attributes, this is a simple operation on tree pointers. But for normal GNU attributes (the vast majority), it involves a call to get_identifier ("gnu"). This patch caches the identifier for speed. Admittedly I'm just going off gut instinct here. I'm happy to drop the patch if this doesn't seem worth a new GC root. Tested on aarch64-linux-gnu & x86_64-linux-gnu. OK to install? Richard gcc/ * Makefile.in (GTFILES): Add attribs.cc. * attribs.cc (gnu_namespace_cache): New variable. (get_gnu_namespace): New function. (lookup_attribute_spec): Use it instead of get_identifier ("gnu"). (get_attribute_namespace, attribs_cc_tests): Likewise. --- gcc/Makefile.in | 3 ++- gcc/attribs.cc | 19 +++++++++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/gcc/Makefile.in b/gcc/Makefile.in index 29cec21c825..a128ff76c07 100644 --- a/gcc/Makefile.in +++ b/gcc/Makefile.in @@ -2812,7 +2812,8 @@ GTFILES = $(CPPLIB_H) $(srcdir)/input.h $(srcdir)/coretypes.h \ $(srcdir)/symtab-thunks.h $(srcdir)/symtab-thunks.cc \ $(srcdir)/symtab-clones.h \ $(srcdir)/reload.h $(srcdir)/caller-save.cc $(srcdir)/symtab.cc \ - $(srcdir)/alias.cc $(srcdir)/bitmap.cc $(srcdir)/cselib.cc $(srcdir)/cgraph.cc \ + $(srcdir)/alias.cc $(srcdir)/attribs.cc \ + $(srcdir)/bitmap.cc $(srcdir)/cselib.cc $(srcdir)/cgraph.cc \ $(srcdir)/ipa-prop.cc $(srcdir)/ipa-cp.cc $(srcdir)/ipa-utils.h \ $(srcdir)/ipa-param-manipulation.h $(srcdir)/ipa-sra.cc \ $(srcdir)/ipa-modref.h $(srcdir)/ipa-modref.cc \ diff --git a/gcc/attribs.cc b/gcc/attribs.cc index 6725fe78f2c..6c70110e350 100644 --- a/gcc/attribs.cc +++ b/gcc/attribs.cc @@ -102,6 +102,19 @@ static const struct attribute_spec *lookup_scoped_attribute_spec (const_tree, static bool attributes_initialized = false; +/* Do not use directly; go through get_gnu_namespace instead. */ +static GTY(()) tree gnu_namespace_cache; + +/* Return the IDENTIFIER_NODE for the gnu namespace. */ + +static tree +get_gnu_namespace () +{ + if (!gnu_namespace_cache) + gnu_namespace_cache = get_identifier ("gnu"); + return gnu_namespace_cache; +} + /* Return base name of the attribute. Ie '__attr__' is turned into 'attr'. To avoid need for copying, we simply return length of the string. */ @@ -403,7 +416,7 @@ lookup_attribute_spec (const_tree name) name = TREE_VALUE (name); } else - ns = get_identifier ("gnu"); + ns = get_gnu_namespace (); return lookup_scoped_attribute_spec (ns, name); } @@ -420,7 +433,7 @@ get_attribute_namespace (const_tree attr) { if (cxx11_attribute_p (attr)) return TREE_PURPOSE (TREE_PURPOSE (attr)); - return get_identifier ("gnu"); + return get_gnu_namespace (); } /* Check LAST_DECL and NODE of the same symbol for attributes that are @@ -2689,3 +2702,5 @@ attribs_cc_tests () } /* namespace selftest */ #endif /* CHECKING_P */ + +#include "gt-attribs.h"