Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RISC-V: Add function multiversioning support
This patch adds support for function multi-versioning to the RISC-V using the target_clones and target_versions attributes, which follow the RISC-V C-API Docs [1] and the existing proposal about priority syntax [2]. This patch copies many codes from commit 0cfde68 ("[aarch64] Add function multiversioning support") and modifies them to fit the RISC-V port. Some key differences are introduced in previously submitted patches [3] and [4], commit [5] and [6]. To test this patch with the GLIBC dynamic loader, you should apply patch [7] for GLIBC to ensure the dynamic loader will initialize the gp register correctly. [1] https://github.com/riscv-non-isa/riscv-c-api-doc/blob/c6c5d6d9cf96b342293315a5dff3d25e96ef8191/src/c-api.adoc#__attribute__targetattr-string [2] riscv-non-isa/riscv-c-api-doc#85 [3] https://patchwork.sourceware.org/project/gcc/patch/[email protected]/ [4] https://patchwork.sourceware.org/project/gcc/patch/[email protected]/ [5] 6183523 [6] 30e0118 [7] https://patchwork.sourceware.org/project/glibc/patch/[email protected]/ Co-Developed-by: Hank Chang <[email protected]> gcc/ChangeLog: * common/config/riscv/riscv-common.cc (struct riscv_ext_bitmask_table_t): New struct. (riscv_minimal_hwprobe_feature_bits): New function. * config/riscv/riscv-protos.h (riscv_option_valid_version_attribute_p): New function. (riscv_process_target_attr): New function. * config/riscv/riscv-subset.h (riscv_minimal_hwprobe_feature_bits): New function. * config/riscv/riscv-target-attr.cc (riscv_target_attr_parser::handle_priority): New function. (riscv_target_attr_parser::update_settings): Update priority attribute and never free the arch string. (riscv_process_one_target_attr): Add const qualifier to arg_str and split arg_str with ';'. (riscv_process_target_attr): New implementation which consumes the const char *args instead of tree. (riscv_option_valid_attribute_p): Reapply any target_version attribute after target attribute. (riscv_process_target_version_attr): New function. * config/riscv/riscv.cc (riscv_can_inline_p): Refuse to inline when callee is versioned but caller is not. (parse_features_for_version): New function. (compare_fmv_features): New function. (riscv_compare_version_priority): New function. (riscv_common_function_versions): New function. (add_condition_to_bb): New function. (dispatch_function_versions): New function. (get_suffixed_assembler_name): New function. (make_resolver_func): New function. (riscv_mangle_decl_assembler_name): New function. (riscv_generate_version_dispatcher_body): New function. (riscv_get_function_versions_dispatcher): New function. (TARGET_OPTION_VALID_VERSION_ATTRIBUTE_P): Implement it. (TARGET_OPTION_FUNCTION_VERSIONS): Implement it. (TARGET_COMPARE_VERSION_PRIORITY): Implement it. (TARGET_GENERATE_VERSION_DISPATCHER_BODY): Implement it. (TARGET_GET_FUNCTION_VERSIONS_DISPATCHER): Implement it. (TARGET_MANGLE_DECL_ASSEMBLER_NAME): Implement it. * config/riscv/riscv.opt: Add TargetVariable riscv_fmv_priority. * defaults.h (TARGET_CLONES_ATTR_SEPARATOR): Define new macro. * multiple_target.cc (get_attr_str): Use TARGET_CLONES_ATTR_SEPARATOR to separate attributes. (separate_attrs): Likewise. * config/riscv/riscv.h (TARGET_CLONES_ATTR_SEPARATOR): Implement it. (TARGET_HAS_FMV_TARGET_ATTRIBUTE): Implement it. * config/riscv/feature_bits.h: New file.
- Loading branch information