[all-commits] [llvm/llvm-project] 9cd937: [RISCV][FMV] Support target_clones (#85786)

Piyou Chen via All-commits all-commits at lists.llvm.org
Fri Sep 13 03:05:15 PDT 2024


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 9cd93774098c861c260090a690f428b7ae031c65
      https://github.com/llvm/llvm-project/commit/9cd93774098c861c260090a690f428b7ae031c65
  Author: Piyou Chen <piyou.chen at sifive.com>
  Date:   2024-09-13 (Fri, 13 Sep 2024)

  Changed paths:
    M clang/include/clang/Basic/DiagnosticFrontendKinds.td
    M clang/include/clang/Basic/TargetInfo.h
    M clang/include/clang/Sema/SemaRISCV.h
    M clang/lib/AST/ASTContext.cpp
    M clang/lib/Basic/Targets/RISCV.cpp
    M clang/lib/CodeGen/CodeGenFunction.cpp
    M clang/lib/CodeGen/CodeGenFunction.h
    M clang/lib/CodeGen/CodeGenModule.cpp
    M clang/lib/CodeGen/Targets/RISCV.cpp
    M clang/lib/Sema/SemaDeclAttr.cpp
    M clang/lib/Sema/SemaRISCV.cpp
    A clang/test/CodeGen/attr-target-clones-riscv-invalid.c
    A clang/test/CodeGen/attr-target-clones-riscv.c
    A clang/test/CodeGenCXX/attr-target-clones-riscv.cpp
    A clang/test/SemaCXX/attr-target-clones-riscv.cpp

  Log Message:
  -----------
  [RISCV][FMV] Support target_clones (#85786)

This patch enable the function multiversion(FMV) and `target_clones`
attribute for RISC-V target.

The proposal of `target_clones` syntax can be found at the
https://github.com/riscv-non-isa/riscv-c-api-doc/pull/48 (which has
landed), as modified by the proposed
https://github.com/riscv-non-isa/riscv-c-api-doc/pull/85 (which adds the
priority syntax).

It supports the `target_clones` function attribute and function
multiversioning feature for RISC-V target. It will generate the ifunc
resolver function for the function that declared with target_clones
attribute.

The resolver function will check the version support by runtime object
`__riscv_feature_bits`.

For example:

```
__attribute__((target_clones("default", "arch=+ver1", "arch=+ver2"))) int bar() {
    return 1;
}
```

the corresponding resolver will be like:

```
bar.resolver() {
    __init_riscv_feature_bits();
    // Check arch=+ver1
    if ((__riscv_feature_bits.features[0] & BITMASK_OF_VERSION1) == BITMASK_OF_VERSION1) {
        return bar.arch=+ver1;
    } else {
        // Check arch=+ver2
        if ((__riscv_feature_bits.features[0] & BITMASK_OF_VERSION2) == BITMASK_OF_VERSION2) {
            return bar.arch=+ver2;
        } else {
            // Default
            return bar.default;
        }
    }
}
```



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list