[v6,0/3] fmv: Add -ftarget-clones-table option support

Message ID tencent_E30926688F388EE02AC74486E835BAF0390A@qq.com
Headers
Series fmv: Add -ftarget-clones-table option support |

Message

Yangyu Chen Oct. 7, 2025, 12:44 p.m. UTC
  This patch series introduces support for the target_clones table
option in GCC. This option enables users to specify target_clones
attributes in a separate file, allowing GCC to generate multiple
versions of the function with different ISA extensions based on the
specified table. This is achieved using the -ftarget-clones-table
option.

The primary objective of this patch series is to provide a
user-friendly way to specify target_clones attributes without
modifying the source code. This approach enhances the source code's
cleanliness, facilitates easier maintenance, and ensures portability
across different architectures and compiler versions.

A example usage is shown below:

Say we have a function `foo` in C source code `foo.c`.

Then we have a target clones table file `target_clones.json`:

```json
{
  "foo": {
    "x86_64": ["avx2", "avx512f"],
    "riscv64": ["arch=+v", "arch=+zba,+zbb", ...],
    ... // more architectures
  },
  // more functions
}
```

Then use: `gcc -O3 -ftarget-clones-table=target_clones.json -S foo.c`
to compile the source code. This will generate multiple versions of
the `foo` function with the specified target clones attributes for
each architecture.

Changes in v6:
- Add doc in doc/invoke.texi

v5: https://patchwork.sourceware.org/project/gcc/cover/tencent_3DBE4676BE12C123ED71C72D5CD098A39007@qq.com/

Changes in v5:
- Add some detailed comments
- Delete node only when !TARGET_HAS_FMV_TARGET_ATTRIBUTE and target_attr is present
- Raise error if "default" present in the target clones table

v4: https://patchwork.sourceware.org/project/gcc/cover/tencent_07C73CDC8318F910F2C6003E00C11BED0607@qq.com/

Changes in v4:
- Delete node only when !TARGET_HAS_FMV_TARGET_ATTRIBUTE

v3: https://patchwork.sourceware.org/project/gcc/cover/tencent_7B3F04A7F18A6F457051DBC4110FF72A8605@qq.com/

Changes in v3:
- Rebase to the latest master branch
- Skip unsupported C++ virtual functions
- Merge table clones table with attributes instead of replacing them
- Add a testcase

v2: https://patchwork.sourceware.org/project/gcc/cover/tencent_815F8860AE36BFA3102E4ECC77C843231606@qq.com/

Changes in v2:
- Use the name of "-ftarget-clones-table" instead of "-ftarget-profile"
- Use JSON formatted table instead of a text file
- Each architectures like x86_64, aarch64, riscv64, etc. Can specify
  multiple target clones attributes in a single JSON table, which
  makes it more flexible and easier to use.

v1: https://patchwork.sourceware.org/project/gcc/cover/tencent_7E345EF1390B9A68A738CEE15EC510864C0A@qq.com/

Yangyu Chen (3):
  Fortran: Do not make_decl_rtl in trans_function_start
  json: add iterate method to object class
  fmv: Add -ftarget-clones-table option support

 gcc/Makefile.in                          |   1 +
 gcc/common.opt                           |   7 +
 gcc/doc/invoke.texi                      |  69 +++++++++-
 gcc/fortran/trans-decl.cc                |   3 -
 gcc/json.h                               |   5 +
 gcc/multiple_target.cc                   | 158 +++++++++++++++++++++--
 gcc/testsuite/gcc.target/i386/tct-0.c    |  11 ++
 gcc/testsuite/gcc.target/i386/tct-0.json |   5 +
 8 files changed, 246 insertions(+), 13 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/i386/tct-0.c
 create mode 100644 gcc/testsuite/gcc.target/i386/tct-0.json