[clang] [llvm] [RISCV][FMV] Support target_clones (PR #85786)

Piyou Chen via cfe-commits cfe-commits at lists.llvm.org
Mon Jul 15 06:31:16 PDT 2024


BeMg wrote:

This patch support 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() {
    // Check arch=+ver1
    if (__riscv_feature_bits.length > MAX_GROUPID_IN_VER1 && (__riscv_feature_bits.features[0] & BITMASK_OF_VERSION1) == BITMASK_OF_VERSION1) {
        return bar.arch=+ver1;
    } else {
        // Check arch=+ver2
        if (__riscv_feature_bits.length > MAX_GROUPID_IN_VER2 && (__riscv_feature_bits.features[0] & BITMASK_OF_VERSION2) == BITMASK_OF_VERSION2) {
            return bar.arch=+ver2;
        } else {
            // Default
            return bar.default;
        }
    }
}
```

https://github.com/llvm/llvm-project/pull/85786


More information about the cfe-commits mailing list