mbox series

[v3,00/11] RISC-V: Add Function Multi-Versioning support

Message ID tencent_C5B4CB1C237133637A42181B23F92605D309@qq.com
Headers show
Series RISC-V: Add Function Multi-Versioning support | expand

Message

Yangyu Chen Oct. 24, 2024, 7:08 a.m. UTC
This patch series adds support for Function Multi-Versioning (FMV) to
RISC-V. The FMV feature allows users to specify multiple versions of a
function and select the version at runtime based on the target_clones
and target_version attributes, which follow the RISC-V C-API Docs [1]
and the existing proposal about priority syntax [2].

To test this series with the GLIBC dynamic loader, you should apply
patch [3] for GLIBC to ensure the dynamic loader will initialize the
gp register correctly.

Changes since v2:
- Add missing replacement for TARGET_CLONES_ATTR_SEPARATOR
- Move RISC-V Extension Bitmask Definitions to riscv-ext-bitmask.def

v2: https://patchwork.sourceware.org/project/gcc/list/?series=39772&state=*

Changes since v1:
- Add RISC-V FMV test cases
- Split patches for better review
- Fix commet typo in dispatch_function_versions
- Severial improvements in function riscv_process_target_version_attr
- Initialize m_priority in riscv_target_attr_parser constructor
- Use unsigned to reference feature bits array in compare_fmv_features
- Never check "default" target in riscv_process_target_attr since we
  have already checked it in riscv_process_target_version_attr

v1: https://patchwork.sourceware.org/project/gcc/patch/tencent_3B2442361B6DF87E046FB4E71D55715D6309@qq.com/

[1] https://github.com/riscv-non-isa/riscv-c-api-doc/blob/c6c5d6d9cf96b342293315a5dff3d25e96ef8191/src/c-api.adoc#__attribute__targetattr-string
[2] https://github.com/riscv-non-isa/riscv-c-api-doc/pull/85
[3] https://patchwork.sourceware.org/project/glibc/patch/tencent_71D182FBDA6E8E57B80731DD218D8D5C7C08@qq.com/

Yangyu Chen (11):
  Introduce TARGET_CLONES_ATTR_SEPARATOR for RISC-V
  RISC-V: Split riscv_process_target_attr with const char *args argument
  RISC-V: Implement Priority syntax parser for Function Multi-Versioning
  RISC-V: Implement riscv_minimal_hwprobe_feature_bits
  RISC-V: Implement TARGET_COMPARE_VERSION_PRIORITY and
    TARGET_OPTION_FUNCTION_VERSIONS
  RISC-V: Implement TARGET_OPTION_VALID_VERSION_ATTRIBUTE_P
  RISC-V: Implement TARGET_MANGLE_DECL_ASSEMBLER_NAME
  RISC-V: Do not inline when callee is versioned but caller is not
  RISC-V: Reapply target_version attribute after target attribute
  RISC-V: Implement TARGET_GENERATE_VERSION_DISPATCHER_BODY and
    TARGET_GET_FUNCTION_VERSIONS_DISPATCHER
  RISC-V: Add Multi-Versioning Test Cases

 gcc/attribs.cc                                |  17 +-
 gcc/common/config/riscv/riscv-common.cc       |  94 +++
 gcc/common/config/riscv/riscv-ext-bitmask.def |  83 ++
 gcc/config/riscv/feature_bits.h               |  44 +
 gcc/config/riscv/riscv-protos.h               |   6 +
 gcc/config/riscv/riscv-subset.h               |   5 +
 gcc/config/riscv/riscv-target-attr.cc         | 198 ++++-
 gcc/config/riscv/riscv.cc                     | 756 ++++++++++++++++++
 gcc/config/riscv/riscv.h                      |   7 +
 gcc/config/riscv/riscv.opt                    |   3 +
 gcc/defaults.h                                |   4 +
 gcc/multiple_target.cc                        |  19 +-
 gcc/testsuite/g++.target/riscv/mv-symbols1.C  |  70 ++
 gcc/testsuite/g++.target/riscv/mv-symbols2.C  |  61 ++
 gcc/testsuite/g++.target/riscv/mv-symbols3.C  |  50 ++
 gcc/testsuite/g++.target/riscv/mv-symbols4.C  |  56 ++
 gcc/testsuite/g++.target/riscv/mv-symbols5.C  |  62 ++
 gcc/testsuite/g++.target/riscv/mvc-symbols1.C |  49 ++
 gcc/testsuite/g++.target/riscv/mvc-symbols2.C |  36 +
 gcc/testsuite/g++.target/riscv/mvc-symbols3.C |  42 +
 gcc/testsuite/g++.target/riscv/mvc-symbols4.C |  32 +
 gcc/tree.cc                                   |   4 +-
 22 files changed, 1649 insertions(+), 49 deletions(-)
 create mode 100644 gcc/common/config/riscv/riscv-ext-bitmask.def
 create mode 100644 gcc/config/riscv/feature_bits.h
 create mode 100644 gcc/testsuite/g++.target/riscv/mv-symbols1.C
 create mode 100644 gcc/testsuite/g++.target/riscv/mv-symbols2.C
 create mode 100644 gcc/testsuite/g++.target/riscv/mv-symbols3.C
 create mode 100644 gcc/testsuite/g++.target/riscv/mv-symbols4.C
 create mode 100644 gcc/testsuite/g++.target/riscv/mv-symbols5.C
 create mode 100644 gcc/testsuite/g++.target/riscv/mvc-symbols1.C
 create mode 100644 gcc/testsuite/g++.target/riscv/mvc-symbols2.C
 create mode 100644 gcc/testsuite/g++.target/riscv/mvc-symbols3.C
 create mode 100644 gcc/testsuite/g++.target/riscv/mvc-symbols4.C