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.

>  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