From: Richard Sandiford Date: Sat, 2 Dec 2023 13:49:54 +0000 (+0000) Subject: attribs: Cache the gnu namespace X-Git-Tag: basepoints/gcc-15~4061 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=3956f5146dc13aa72977c222cfe472ba1e92834c;p=thirdparty%2Fgcc.git attribs: Cache the gnu namespace 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. 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. --- diff --git a/gcc/Makefile.in b/gcc/Makefile.in index b79421e7252d..e154f7c0055f 100644 --- a/gcc/Makefile.in +++ b/gcc/Makefile.in @@ -2816,7 +2816,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 8ad9b3b23490..95b0d0fab1d7 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 @@ -2692,3 +2705,5 @@ attribs_cc_tests () } /* namespace selftest */ #endif /* CHECKING_P */ + +#include "gt-attribs.h"