diff options
author | Richard Sandiford <richard.sandiford@arm.com> | 2023-12-02 13:49:54 +0000 |
---|---|---|
committer | Richard Sandiford <richard.sandiford@arm.com> | 2023-12-02 13:49:54 +0000 |
commit | 3956f5146dc13aa72977c222cfe472ba1e92834c (patch) | |
tree | de25f56cf6e949b8344be2a47469d8059c85d077 /gcc | |
parent | 301dec8533460152c4dd61f46c8e9276e169c49a (diff) | |
download | gcc-3956f5146dc13aa72977c222cfe472ba1e92834c.zip gcc-3956f5146dc13aa72977c222cfe472ba1e92834c.tar.gz gcc-3956f5146dc13aa72977c222cfe472ba1e92834c.tar.bz2 |
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.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/Makefile.in | 3 | ||||
-rw-r--r-- | gcc/attribs.cc | 19 |
2 files changed, 19 insertions, 3 deletions
diff --git a/gcc/Makefile.in b/gcc/Makefile.in index b79421e..e154f7c 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 8ad9b3b..95b0d0f 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" |