mbox series

[v5,0/8] RISC-V: Add Function Multi-Versioning support

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

Message

Yangyu Chen Nov. 5, 2024, 3:20 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 v4:
- Update document for TARGET_CLONES_ATTR_SEPARATOR

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

Changes since v3:
- Remove committed patches
- Remove skip splitter ';' in riscv_process_one_target_attr
- Rename feature_bits.h to riscv_feature_bits.h
- Split "target" and "target_version" parser [4]
- Keep free arch string in riscv_target_attr_parser::update_settings [5]
- Remove reapply target_version in riscv_process_target_attr [6]
- Fix LTO error as patch [7]
- Use std::vector and std::sort in dispatch_function_versions

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

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/
[4] https://inbox.sourceware.org/gcc-patches/CA+yXCZBG9gKnAQ1xuxw=_j5Ry3cRNDuSNp58Tgpt=pzm4dGv7A@mail.gmail.com/
[5] https://inbox.sourceware.org/gcc-patches/tencent_FD68A30BDF936092B6A663146E634C76C806@qq.com/
[6] https://inbox.sourceware.org/gcc-patches/tencent_A646C713DC9218DD10CA460EBE074153ED07@qq.com/
[7] https://patchwork.sourceware.org/project/gcc/patch/tencent_F08BE088F6B1E3152E508C63C870E31CDF06@qq.com/

Yangyu Chen (8):
  Introduce TARGET_CLONES_ATTR_SEPARATOR for RISC-V
  RISC-V: Implement Priority syntax parser for Function Multi-Versioning
  RISC-V: Implement riscv_minimal_hwprobe_feature_bits
  RISC-V: Implement TARGET_OPTION_VALID_VERSION_ATTRIBUTE_P
  RISC-V: Implement TARGET_COMPARE_VERSION_PRIORITY and
    TARGET_OPTION_FUNCTION_VERSIONS
  RISC-V: Implement TARGET_MANGLE_DECL_ASSEMBLER_NAME
  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/riscv-feature-bits.h         |  44 +
 gcc/config/riscv/riscv-protos.h               |   4 +-
 gcc/config/riscv/riscv-subset.h               |   5 +
 gcc/config/riscv/riscv-target-attr.cc         | 142 +++-
 gcc/config/riscv/riscv.cc                     | 757 ++++++++++++++++++
 gcc/config/riscv/riscv.h                      |   7 +
 gcc/config/riscv/riscv.opt                    |   3 +
 gcc/defaults.h                                |   4 +
 gcc/doc/tm.texi                               |   7 +
 gcc/doc/tm.texi.in                            |   7 +
 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 +-
 24 files changed, 1627 insertions(+), 28 deletions(-)
 create mode 100644 gcc/common/config/riscv/riscv-ext-bitmask.def
 create mode 100644 gcc/config/riscv/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