]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
LoongArch: Implement TARGET_MANGLE_DECL_ASSEMBLER_NAME.
authorLulu Cheng <chenglulu@loongson.cn>
Sat, 20 Sep 2025 01:22:32 +0000 (09:22 +0800)
committerLulu Cheng <chenglulu@loongson.cn>
Tue, 11 Nov 2025 07:33:36 +0000 (15:33 +0800)
Implements TARGET_MANGLE_DECL_ASSEMBLER_NAME for LoongArch.
This is used to add function multiversioning suffixes to the assembler
name.

gcc/ChangeLog:

* config/loongarch/loongarch.cc (INCLUDE_STRING): Include.
(loongarch_mangle_decl_assembler_name): New function.
(TARGET_MANGLE_DECL_ASSEMBLER_NAME): Define.

gcc/config/loongarch/loongarch.cc

index d74537f91461f93a15ea2026fd0480810cc97d96..1e5ce54e83a05087c21be98877481960d65ea3bc 100644 (file)
@@ -21,6 +21,7 @@ along with GCC; see the file COPYING3.  If not see
 
 #define IN_TARGET_CODE 1
 
+#define INCLUDE_STRING
 #include "config.h"
 #include "system.h"
 #include "coretypes.h"
@@ -11597,6 +11598,41 @@ loongarch_get_function_versions_dispatcher (void *decl)
   return dispatch_decl;
 }
 
+/* Implement TARGET_MANGLE_DECL_ASSEMBLER_NAME, to add function multiversioning
+   suffixes.  */
+
+tree
+loongarch_mangle_decl_assembler_name (tree decl, tree id)
+{
+  /* For function version, add the target suffix to the assembler name.  */
+  if (TREE_CODE (decl) == FUNCTION_DECL
+      && DECL_FUNCTION_VERSIONED (decl))
+    {
+      std::string name = IDENTIFIER_POINTER (id) + std::string (".");
+      tree target_attr = lookup_attribute ("target_version",
+                                          DECL_ATTRIBUTES (decl));
+
+      if (target_attr == NULL_TREE)
+       {
+         name += "default";
+         return get_identifier (name.c_str ());
+       }
+
+      const char *version_string
+       = TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (target_attr)));
+
+      /* Replace non-alphanumeric characters with underscores as the suffix.  */
+      for (const char *c = version_string; *c; c++)
+       name += ISALNUM (*c) == 0 ? '_' : *c;
+
+      if (DECL_ASSEMBLER_NAME_SET_P (decl))
+       SET_DECL_RTL (decl, NULL);
+
+      id = get_identifier (name.c_str ());
+    }
+  return id;
+}
+
 /* Initialize the GCC target structure.  */
 #undef TARGET_ASM_ALIGNED_HI_OP
 #define TARGET_ASM_ALIGNED_HI_OP "\t.half\t"
@@ -11892,6 +11928,10 @@ loongarch_get_function_versions_dispatcher (void *decl)
 #define TARGET_GET_FUNCTION_VERSIONS_DISPATCHER \
   loongarch_get_function_versions_dispatcher
 
+#undef TARGET_MANGLE_DECL_ASSEMBLER_NAME
+#define TARGET_MANGLE_DECL_ASSEMBLER_NAME \
+  loongarch_mangle_decl_assembler_name
+
 struct gcc_target targetm = TARGET_INITIALIZER;
 
 #include "gt-loongarch.h"