On Tue, Nov 10, 2026, 2:57 PM Andrea Pinski <[email protected]>
wrote:

> On Tue, Nov 10, 2026 at 7:04 AM Richard Biener
> <[email protected]> wrote:
> >
> > On Tue, Nov 10, 2026 at 3:46 PM <[email protected]> wrote:
> > >
> > > From: Kyrylo Tkachov <[email protected]>
> > >
> > > get_attributes builds a fresh attribute list for every function decl,
> and the
> > > attribute lists must not be shared between decls.
> >
> > Why must they not be shared?  The middle-end (and LTO) happily
> > does - even sharing "tails" of the attribute lists.
>
> So the reasoning here is due to the way function_builder::get_attributes
> works.
> Now I think we can do much better.
> The last attribute in function_builder::get_attributes can always be
> shared. leaf is the same at the end.
> That will help the sharing there.
>
> then we are left with:
> const/pure/none
> nothrow/none
>
> adding all of these 2 together we can have a tail which can be shared
> across 6 different possibilities for the tail.
> There is also:
> arm::streaming/arm::streaming_compatible/none
> which could be shared too.
>
> so a possibility of 3*6 = 18 sharing for the tail.
> That will most likely be better and we can even have these built lazy
> so we might not get all 18 versions shared.
>
> I think this might speed up things and even save more memory than what
> you are currently doing.
>


The other thing is you can cache arm identifier separately too. And not
even use a lookup. You can wrap it in a function for the use in the other
function and then just pass indetifiers instead of strings .


> Thanks,
> Andrea
>
> >
> > >  The names in them come from
> > > a fixed set of about ten string literals, so registering arm_neon.h and
> > > arm_sve.h sends those same few names through get_identifier tens of
> thousands
> > > of times, and identifier lookup is one of the hottest functions in a
> profile of
> > > the pragma handler.
> > >
> > > Memoize the interned names, keyed on the address of the literal that
> asked for
> > > them.  The lists themselves are still built per decl, so nothing is
> shared.  A
> > > cache miss just interns the name again, so correctness does not depend
> on the
> > > literals being merged.
> > >
> > > Instructions retired for -fsyntax-only on a file that includes just the
> > > header, on top of the preceding table-sizing patch, cc1 built with
> > > --enable-checking=release:
> > >
> > >                      arm_neon.h   arm_sve.h   both
> > >   this patch               -0.1%       -5.4%  -1.2%
> > >   cumulative               -0.2%       -7.1%  -1.6%
> > >
> > > Bootstrapped and tested on aarch64-none-linux-gnu.
> > > Ok for trunk?
> > > Thanks,
> > > Kyrill
> > >
> > > gcc/ChangeLog:
> > >
> > >         * config/aarch64/aarch64-acle-builtins.cc (attribute_ids)
> > >         (attribute_id_names, num_attribute_ids): New variables.
> > >         (attribute_identifier): New function.
> > >         (add_attribute): Use it instead of get_identifier.
> > >
> > > Signed-off-by: Kyrylo Tkachov <[email protected]>
> > > ---
> > >  gcc/config/aarch64/aarch64-acle-builtins.cc | 44 +++++++++++++++++++--
> > >  1 file changed, 41 insertions(+), 3 deletions(-)
> > >
> > > diff --git a/gcc/config/aarch64/aarch64-acle-builtins.cc
> b/gcc/config/aarch64/aarch64-acle-builtins.cc
> > > index a3f967e7971..78bb80f3785 100644
> > > --- a/gcc/config/aarch64/aarch64-acle-builtins.cc
> > > +++ b/gcc/config/aarch64/aarch64-acle-builtins.cc
> > > @@ -702,19 +702,57 @@ function_builder::get_name (const
> function_instance &instance,
> > >    return finish_name ();
> > >  }
> > >
> > > +/* get_attributes and its helpers draw their attribute names from a
> fixed set
> > > +   of ten string literals: the "arm" namespace, "streaming",
> > > +   "streaming_compatible", the "in", "out" and "inout" shared-state
> markers,
> > > +   and "pure", "const", "nothrow" and "leaf".  Keying the cache on
> the address
> > > +   of the literal means the namespace can occupy more than one entry
> if its
> > > +   several occurrences are not merged into one object, so allow for
> that.
> > > +   Running out only costs the caching, never correctness.  */
> > > +static const unsigned int attribute_id_cache_size = 12;
> > > +
> > > +/* Attribute names that attribute_identifier has already interned,
> together
> > > +   with the address of the string literal that asked for each one.  */
> > > +static GTY(()) tree attribute_ids[attribute_id_cache_size];
> > > +static const char *attribute_id_names[attribute_id_cache_size];
> > > +static unsigned int num_attribute_ids;
> > > +
> > > +/* Return the identifier for attribute name NAME.  get_attributes
> builds an
> > > +   attribute list for every function decl and the names come from a
> fixed set
> > > +   of string literals, so interning them through get_identifier each
> time would
> > > +   dominate the identifier table.  Cache them instead, keyed on the
> address of
> > > +   the literal.  A miss just interns NAME again, so correctness does
> not depend
> > > +   on identical literals being merged.  */
> > > +static tree
> > > +attribute_identifier (const char *name)
> > > +{
> > > +  for (unsigned int i = 0; i < num_attribute_ids; ++i)
> > > +    if (attribute_id_names[i] == name)
> > > +      return attribute_ids[i];
> > > +
> > > +  tree id = get_identifier (name);
> > > +  if (num_attribute_ids < attribute_id_cache_size)
> > > +    {
> > > +      attribute_id_names[num_attribute_ids] = name;
> > > +      attribute_ids[num_attribute_ids] = id;
> > > +      num_attribute_ids++;
> > > +    }
> > > +  return id;
> > > +}
> > > +
> > >  /* Add attribute NAME to ATTRS.  */
> > >  static tree
> > >  add_attribute (const char *name, tree attrs)
> > >  {
> > > -  return tree_cons (get_identifier (name), NULL_TREE, attrs);
> > > +  return tree_cons (attribute_identifier (name), NULL_TREE, attrs);
> > >  }
> > >
> > >  /* Add attribute NS::NAME to ATTRS.  */
> > >  static tree
> > >  add_attribute (const char *ns, const char *name, tree value, tree
> attrs)
> > >  {
> > > -  return tree_cons (build_tree_list (get_identifier (ns),
> > > -                                    get_identifier (name)),
> > > +  return tree_cons (build_tree_list (attribute_identifier (ns),
> > > +                                    attribute_identifier (name)),
> > >                     value, attrs);
> > >  }
> > >
> > > --
> > > 2.54.0 (Apple Git-157)
> > >
>

Reply via email to