This patch implements the TARGET_MANGLE_DECL_ASSEMBLER_NAME for RISC-V.
This is used to add function multiversioning suffixes to the assembler
name.
gcc/ChangeLog:
* config/riscv/riscv.cc
(riscv_mangle_decl_assembler_name): New function.
(TARGET_MANGLE_DECL_ASSEMBLER_NAME): Define.
---
gcc/config/riscv/riscv.cc | 39 +++++++++++++++++++++++++++++++++++++++
1 file changed, 39 insertions(+)
diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc
index 789667da386..f7082df22ef 100644
--- a/gcc/config/riscv/riscv.cc
+++ b/gcc/config/riscv/riscv.cc
@@ -12695,6 +12695,42 @@ riscv_common_function_versions (tree fn1, tree fn2)
return riscv_compare_version_priority (fn1, fn2) != 0;
}
+/* Implement TARGET_MANGLE_DECL_ASSEMBLER_NAME, to add function multiversioning
+ suffixes. */
+
+tree
+riscv_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;
+}
+
/* On riscv we have an ABI defined safe buffer. This constant is used to
determining the probe offset for alloca. */
@@ -13079,6 +13115,9 @@ riscv_stack_clash_protection_alloca_probe_range (void)
#define TARGET_OPTION_VALID_VERSION_ATTRIBUTE_P \
riscv_option_valid_version_attribute_p
+#undef TARGET_MANGLE_DECL_ASSEMBLER_NAME
+#define TARGET_MANGLE_DECL_ASSEMBLER_NAME riscv_mangle_decl_assembler_name
+
struct gcc_target targetm = TARGET_INITIALIZER;
#include "gt-riscv.h"
--
2.45.2