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.

I understand that this patch lacks comprehensive documentation and
test cases, as I am still in the process of writing them.
However, I would appreciate feedback on the implementation before
adding them. If the implementation is deemed acceptable, I
will proceed with writing the documentation and test cases.

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_7e345ef1390b9a68a738cee15ec510864...@qq.com/


Yangyu Chen (3):
  Fortran: Do not make_decl_rtl in trans_function_start
  json: add iterate method to object class
  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    | 124 +++++++++++++++++++++++++++++++++++++-
 5 files changed, 134 insertions(+), 6 deletions(-)

-- 
2.49.0

Reply via email to