[AArch64][compiler-rt] Add a function returning the current vector length#92921
[AArch64][compiler-rt] Add a function returning the current vector length#92921kmclaughlin-arm merged 6 commits intollvm:mainfrom
Conversation
…ngth get_runtime_vl emits a cntd instruction if SVE is available at runtime, otherwise it will return 0.
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
efriedma-quic
left a comment
There was a problem hiding this comment.
This function should be in the ABI document before we merge it, I think.
| __init_cpu_features(); | ||
| } | ||
|
|
||
| __attribute__((target("sve"))) long emit_cntd(void) { |
| return vl; | ||
| } | ||
|
|
||
| long get_runtime_vl(void) { |
There was a problem hiding this comment.
This probably should be prefixed with __aarch64
There was a problem hiding this comment.
Hi @efriedma-quic, I've added this routine to the ABI document in ARM-software/abi-aa#263 and renamed it to __arm_get_current_vg.
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
|
||
| #include "../cpu_model/aarch64.c" |
There was a problem hiding this comment.
cpu_model/aarch64.c isn't a header; including it seem wrong.
ARM-software/abi-aa#263 - Renamed get_runtime_vl to __arm_get_current_vg - Also return VG if currently in streaming-mode - Added static to get_aarch64_cpu_features - Added aarch64.h and included in sme-abi-init.c
…me_state, to check if currently in streaming mode.
| FEAT_INIT // Used as flag of features initialization completion | ||
| }; | ||
|
|
||
| long long get_features(void); |
There was a problem hiding this comment.
This exports a function named get_features from compiler-rt... probably you want to hide it somehow (__ prefix, or make it static).
|
|
||
| long long __get_aarch64_features(void); | ||
|
|
||
| void CONSTRUCTOR_ATTRIBUTE __init_cpu_features(void); |
There was a problem hiding this comment.
You shouldn't need CONSTRUCTOR_ATTRIBUTE on the declaration here, I think.
| extern struct SME_STATE __arm_sme_state(void) __arm_streaming_compatible; | ||
|
|
||
| __attribute__((target("sve"))) long | ||
| __arm_get_current_vg(void) __arm_streaming_compatible { |
There was a problem hiding this comment.
Maybe split this into a separate file, so code using the other stuff defined in this file doesn't pull in the constructor? I assume __arm_get_current_vg won't be used in most configurations.
There was a problem hiding this comment.
I've split this into a separate file and replaced the use of has_sme() with __aarch64_has_sme_and_tpidr2_el0.
| FEAT_INIT // Used as flag of features initialization completion | ||
| }; | ||
|
|
||
| long long __get_aarch64_features(void); |
There was a problem hiding this comment.
Looking again... maybe we should just poke at __aarch64_cpu_features directly, instead of adding this function? __aarch64_cpu_features is already part of the ABI (clang codegen knows about it).
There was a problem hiding this comment.
Thanks, I've removed __get_aarch64_features. I'd missed that clang was also using __aarch64_cpu_features.
- Removed __get_aarch64_features. - Split out changes for __arm_get_current_vg into a new file (sme-abi-vg.c) and removed from sme-abi-init.c.
|
This change results in The new C file, |
When llvm#92921 added the `__arm_get_current_vg` functionality, it used the FMV feature bits mechanism rather than the existing mechanism that was previously added for SME that called `getauxval` (on Linux platforms) or `__aarch64_sme_accessible` (required for baremetal libraries). It seems simpler to always use the FMV feature bits mechanism, but for baremetal targets we still need to rely on `__arm_sme_accessible`.
…features. (#119414) When #92921 added the `__arm_get_current_vg` functionality, it used the FMV feature bits mechanism rather than the mechanism that was previously added for SME which called `getauxval` on Linux platforms or `__aarch64_sme_accessible` required for baremetal libraries. It is better to always use `__aarch64_cpu_features`. For baremetal we still need to rely on `__arm_sme_accessible` to initialise the struct.
get_runtime_vl emits a cntd instruction if SVE is available at runtime,
otherwise it will return 0.