From: Ezra Sitorus <[email protected]>
Date: Wed, 28 Oct 2026 20:30:37 +0000
Subject: [PATCH v4 1/2] aarch64: custom intrinsics suffix naming; explicit SME
 function bases

Allow SME function groups to specify function_base implementation independently
of public intrinsic name. The motivation for this is to use distinct
implementations while sharing a public base name.

Add a function_shape hook for appending type/group suffixes which allows shapes
to override the default layout. The default implementation uses the standard
naming of existing intrinsics (up to 3 type suffixes followed by optional group
suffix).

gcc/ChangeLog:
        * config/aarch64/aarch64-acle-builtins.cc (sme_function_groups): Define
          DEF_SME_FUNCTION_BASE_GS_FPM
          (function_builder::get_name): Call append_type_and_group_suffixes.
        * config/aarch64/aarch64-acle-builtins.h (append_name): Make public.
          (append_type_and_group_suffixes): New function.
        * config/aarch64/aarch64-sve-builtins-sme.def
          (DEF_SME_FUNCTION_BASE_GS): New define.
---
 gcc/config/aarch64/aarch64-acle-builtins.cc    | 17 ++++++++++++-----
 gcc/config/aarch64/aarch64-acle-builtins.h     | 18 +++++++++++++++++-
 .../aarch64/aarch64-sve-builtins-sme.def       |  6 ++++++
 3 files changed, 35 insertions(+), 6 deletions(-)

diff --git a/gcc/config/aarch64/aarch64-acle-builtins.cc 
b/gcc/config/aarch64/aarch64-acle-builtins.cc
index 2d52443a68ca..056ba692d680 100644
--- a/gcc/config/aarch64/aarch64-acle-builtins.cc
+++ b/gcc/config/aarch64/aarch64-acle-builtins.cc
@@ -251,6 +251,15 @@ static constexpr function_group_info sme_function_groups[] 
= {
     /* .extensions = */ aarch64_required_extensions::REQUIRED_EXTENSIONS \
                        .and_also (AARCH64_FL_ZA_ON),             \
     /* .fpm_mode   = */ FPM_##FPM_MODE },
+#define DEF_SME_FUNCTION_BASE_GS_FPM(NAME, BASE, SHAPE, TYPES, GROUPS, PREDS, 
FPM_MODE) \
+  { /* .base_name  = */ #NAME,                                         \
+    /* .base       = */ &functions::BASE,                              \
+    /* .shape      = */ &shapes::SHAPE,                                        
\
+    /* .types      = */ types_##TYPES,                                 \
+    /* .groups     = */ groups_##GROUPS,                               \
+    /* .preds      = */ preds_##PREDS,                                 \
+    /* .extensions = */ aarch64_required_extensions::REQUIRED_EXTENSIONS, \
+    /* .fpm_mode   = */ FPM_##FPM_MODE },
 #include "aarch64-sve-builtins-sme.def"
 };
 
@@ -639,11 +648,9 @@ function_builder::get_name (const function_instance 
&instance,
       }
   else
     append_name (instance.mode_suffix ().string);
-  for (unsigned int i = 0; i < 3; ++i)
-    if (!overloaded_p || instance.shape->explicit_type_suffix_p (i))
-      append_name (instance.type_suffix (i).string);
-  if (!overloaded_p || instance.shape->explicit_group_suffix_p ())
-    append_name (instance.group_suffix ().string);
+
+  instance.shape->append_type_and_group_suffixes (*this, instance, 
overloaded_p);
+
   append_name (pred_suffixes[instance.pred]);
   if (instance.fpm_mode == FPM_set)
     append_name ("_fpm");
diff --git a/gcc/config/aarch64/aarch64-acle-builtins.h 
b/gcc/config/aarch64/aarch64-acle-builtins.h
index 1572594872b9..d5d4097937dc 100644
--- a/gcc/config/aarch64/aarch64-acle-builtins.h
+++ b/gcc/config/aarch64/aarch64-acle-builtins.h
@@ -456,9 +456,9 @@ public:
                                 mode_suffix_index);
 
   void register_function_group (const function_group_info &);
+  void append_name (const char *);
 
 private:
-  void append_name (const char *);
   char *finish_name ();
 
   char *get_name (const function_instance &, bool);
@@ -837,6 +837,22 @@ public:
   /* Check whether the given call is semantically valid.  Return true
      if it is, otherwise report an error and return false.  */
   virtual bool check (function_checker &) const { return true; }
+
+  /* Append the type and group suffixes for INSTANCE.  OVERLOADED_P selects the
+     overloaded spelling.  Shapes can override this when the suffix layout
+     differs from the standard type-type-group ordering.  */
+  virtual void
+  append_type_and_group_suffixes (function_builder &b,
+                                 const function_instance &instance,
+                                 bool overloaded_p) const
+  {
+    for (unsigned int i = 0; i < 3; ++i)
+      if (!overloaded_p || explicit_type_suffix_p (i))
+       b.append_name (instance.type_suffix (i).string);
+
+    if (!overloaded_p || explicit_group_suffix_p ())
+      b.append_name (instance.group_suffix ().string);
+  }
 };
 
 /* RAII class for temporarily disabling the effect of any -fpack-struct option.
diff --git a/gcc/config/aarch64/aarch64-sve-builtins-sme.def 
b/gcc/config/aarch64/aarch64-sve-builtins-sme.def
index 88c0dd68dc6a..e2aecf5b0f89 100644
--- a/gcc/config/aarch64/aarch64-sve-builtins-sme.def
+++ b/gcc/config/aarch64/aarch64-sve-builtins-sme.def
@@ -44,6 +44,10 @@
 DEF_SME_ZA_FUNCTION_GS_FPM (NAME, SHAPE, TYPES, none, PREDS, unused)
 #endif
 
+/* Same as `DEF_SME_FUNCTION_GS` above, but with differing NAME and function 
BASE name.  */
+#define DEF_SME_FUNCTION_BASE_GS(NAME, BASE, SHAPE, TYPES, GROUPS, PREDS) \
+  DEF_SME_FUNCTION_BASE_GS_FPM (NAME, BASE, SHAPE, TYPES, GROUPS, PREDS, 
unused)
+
 #define REQUIRED_EXTENSIONS streaming_compatible (0)
 DEF_SME_FUNCTION (arm_has_sme, bool_inherent, none, none)
 DEF_SME_FUNCTION (arm_in_streaming_mode, bool_inherent, none, none)
@@ -409,3 +413,5 @@ DEF_SME_ZA_FUNCTION_GS_FPM (svtmopa_lane, 
ternary_za_uint_dual_single, tmop_s_mf
 #undef DEF_SME_ZA_FUNCTION_GS_FPM
 #undef DEF_SME_FUNCTION
 #undef DEF_SME_FUNCTION_GS
+#undef DEF_SME_FUNCTION_BASE_GS
+#undef DEF_SME_FUNCTION_BASE_GS_FPM
-- 
2.53.0

Reply via email to