diff options
author | Yangyu Chen <cyy@cyyself.name> | 2024-11-05 11:22:56 +0800 |
---|---|---|
committer | Kito Cheng <kito.cheng@sifive.com> | 2024-11-13 17:01:42 +0800 |
commit | 0c77c4b082bf110fd2fc9c800268ac58fa579d06 (patch) | |
tree | 01fdef11d87197d1ff85a2e3d7399d3da36bf016 /gcc | |
parent | 78753c75cf154e7432624e24c68aae3b81ed49f0 (diff) | |
download | gcc-0c77c4b082bf110fd2fc9c800268ac58fa579d06.zip gcc-0c77c4b082bf110fd2fc9c800268ac58fa579d06.tar.gz gcc-0c77c4b082bf110fd2fc9c800268ac58fa579d06.tar.bz2 |
RISC-V: Implement TARGET_MANGLE_DECL_ASSEMBLER_NAME
This patch implements the TARGET_MANGLE_DECL_ASSEMBLER_NAME for RISC-V.
This is used to add function multiversioning suffixes to the assembler
name.
Signed-off-by: Yangyu Chen <cyy@cyyself.name>
gcc/ChangeLog:
* config/riscv/riscv.cc
(riscv_mangle_decl_assembler_name): New function.
(TARGET_MANGLE_DECL_ASSEMBLER_NAME): Define.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/config/riscv/riscv.cc | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc index 9f1023e..ca57d20 100644 --- a/gcc/config/riscv/riscv.cc +++ b/gcc/config/riscv/riscv.cc @@ -12820,6 +12820,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. */ @@ -13223,6 +13259,9 @@ riscv_use_by_pieces_infrastructure_p (unsigned HOST_WIDE_INT size, #undef TARGET_OPTION_FUNCTION_VERSIONS #define TARGET_OPTION_FUNCTION_VERSIONS riscv_common_function_versions +#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" |