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 v4:
- Delete node only when !TARGET_HAS_FMV_TARGET_ATTRIBUTE
v3:
https://patchwork.sourceware.org/project/gcc/cover/[email protected]/
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/[email protected]/
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/[email protected]/
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/fortran/trans-decl.cc | 3 -
gcc/json.h | 5 +
gcc/multiple_target.cc | 145 +++++++++++++++++++++--
gcc/testsuite/gcc.target/i386/tct-0.c | 11 ++
gcc/testsuite/gcc.target/i386/tct-0.json | 5 +
7 files changed, 162 insertions(+), 15 deletions(-)
create mode 100644 gcc/testsuite/gcc.target/i386/tct-0.c
create mode 100644 gcc/testsuite/gcc.target/i386/tct-0.json
--
2.49.0