-
Notifications
You must be signed in to change notification settings - Fork 47
Function multi-version proposal #48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This repository is for specifications of features that are portable between multiple RISC-V toolchains. As such it is inappropriate to specify any behavior exclusively in terms of Linux-only interfaces like hwprobe and cpuinfo. Providing a string-to-bool or string-to-int (for things like Zicbo* cache block size) lookup interface as a portable frontend to Linux's syscalls, the HWCAP-inspired interfaces on the BSDs, and whatever NT ends up with is a good idea, although it's useful for more than just ifunc; @jrtc27 suggested |
Here is proposal riscv-non-isa/riscv-c-api-doc#48. During the Function multi-version dispatch the function, we need a method to retrieve the RISC-V hardware environment to make sure all extension must be available. Differential Revision: https://reviews.llvm.org/D155938
46c4bd7
to
6272992
Compare
Can How are versions and clones prioritized? A big list of every possible exception isn't going to work for us, so it should be something in the source code. Not sure if declaration order would cause problems. |
Hi @sorear, thanks for the comment.
For target_version and target_clones's From the compiler's perspective, mtune, mcpu information will be highly related to the compilation result. If someday, we need to add mtune and mcpu to target_version /target_clones's @kito-cheng any other comments on this topic?
Currently, the selection order depend on IFUNC resolver's implementation. We plan to add the one another option inside |
I have created a pull request llvm/llvm-project#85786 to LLVM to implement I have also created a draft pull request llvm/llvm-project#85790 to implement For example
|
9a9fe83
to
b33e1cf
Compare
Rebase to origin/main |
a58b156
to
8e75c7b
Compare
Update: Remove the |
Define the two syntax for function multiversion on RISC-V. 1. target_clones 2. target_version Both of them are kind of function attribute
8e75c7b
to
fabd52a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, this has discussed for a while and remove arch=<full-arch-string>
to prevent some implementation issue is reasonable to me, anyway we gonna merge this and implement that on GCC and LLVM :)
For anyone following along, there is a follow on proposal to add syntax to assist with selection between multiple candidates, see #85 |
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 riscv-non-isa/riscv-c-api-doc#48 (which has landed), as modified by the proposed riscv-non-isa/riscv-c-api-doc#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; } } } ```
This patch enable `target_version` attribute for RISC-V target. The proposal of `target_version` syntax can be found at the riscv-non-isa/riscv-c-api-doc#48 (which has landed), as modified by the proposed riscv-non-isa/riscv-c-api-doc#85 (which adds the priority syntax). `target_version` attribute will trigger the function multi-versioning feature and act like `target_clones` attribute. See #85786 for the implementation of `target_clones`.
Fix the buildbot failure caused by heap use-after-free error. Origin message: This patch enable `target_version` attribute for RISC-V target. The proposal of `target_version` syntax can be found at the riscv-non-isa/riscv-c-api-doc#48 (which has landed), as modified by the proposed riscv-non-isa/riscv-c-api-doc#85 (which adds the priority syntax). `target_version` attribute will trigger the function multi-versioning feature and act like `target_clones` attribute. See #85786 for the implementation of `target_clones`.
During the Function multi-version dispatch the function, we need a method to retrieve the RISC-V hardware environment to make sure all extension must be available.
The problem is
From the compiler's view, it will generate the IFUNC resolver when there are more than one implementation with the same symbol name.
Consider following example:
The corresponding assembly will look like:
The resolver that the compiler generates query and selects for each candidate function. When fulfilling the requirement, then return the corresponding function ptr for further processing.
In this proposal, the major part of the resolver function is
__riscv_ifunc_select
.__riscv_ifunc_select
must retrieve the hardware information for deciding whether to execute the specific function.Here we propose that function as the following declaration
Where FeatureString is a string that concatenates all target features belonging to a particular function. The form can be described in the following BNF form.
When hardware fulfills the FeatureStr, then returns true. Otherwise this function returns false.
2023/09/04 Update: The following section take the linux platform as example for
__riscv_ifunc_select
implementation.There are two ways to retrieve hardware information.
Another problem is where to place the function definition.
The compiler-rt/libgcc is a good place to implement these functions, like other target(x86/aarch64) implementation.
[1] https://docs.kernel.org/riscv/hwprobe.html
2024/07/11 Update
arch=<full-arch-string>
from syntax