public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH 1/3] attribs: Cache the gnu namespace
@ 2023-11-06 12:23 Richard Sandiford
  2023-11-10  1:36 ` Jeff Law
  0 siblings, 1 reply; 2+ messages in thread
From: Richard Sandiford @ 2023-11-06 12:23 UTC (permalink / raw)
  To: gcc-patches

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"
-- 
2.25.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH 1/3] attribs: Cache the gnu namespace
  2023-11-06 12:23 [PATCH 1/3] attribs: Cache the gnu namespace Richard Sandiford
@ 2023-11-10  1:36 ` Jeff Law
  0 siblings, 0 replies; 2+ messages in thread
From: Jeff Law @ 2023-11-10  1:36 UTC (permalink / raw)
  To: gcc-patches, richard.sandiford



On 11/6/23 05:23, Richard Sandiford wrote:
> 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.
I trust your gut instincts.  So OK.

jeff

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-11-10  1:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-06 12:23 [PATCH 1/3] attribs: Cache the gnu namespace Richard Sandiford
2023-11-10  1:36 ` Jeff Law

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).