Skip to content
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

[AArch64][compiler-rt] Add a function returning the current vector length #92921

Merged
merged 6 commits into from
Jun 5, 2024

Conversation

kmclaughlin-arm
Copy link
Contributor

get_runtime_vl emits a cntd instruction if SVE is available at runtime,
otherwise it will return 0.

…ngth

get_runtime_vl emits a cntd instruction if SVE is available at runtime,
otherwise it will return 0.
Copy link

github-actions bot commented May 21, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

Copy link
Collaborator

@efriedma-quic efriedma-quic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function should be in the ABI document before we merge it, I think.

__init_cpu_features();
}

__attribute__((target("sve"))) long emit_cntd(void) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

static?

return vl;
}

long get_runtime_vl(void) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This probably should be prefixed with __aarch64

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@@ -2,6 +2,8 @@
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#include "../cpu_model/aarch64.c"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This exports a function named get_features from compiler-rt... probably you want to hide it somehow (__ prefix, or make it static).

@efriedma-quic efriedma-quic requested a review from labrinea May 31, 2024 19:24

long long __get_aarch64_features(void);

void CONSTRUCTOR_ATTRIBUTE __init_cpu_features(void);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
Copy link
Collaborator

@efriedma-quic efriedma-quic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@kmclaughlin-arm kmclaughlin-arm merged commit 043cc5a into llvm:main Jun 5, 2024
6 checks passed
@yozhu
Copy link
Contributor

yozhu commented Jun 7, 2024

This change results in compiler-rt build failure:

compiler-rt/lib/builtins/aarch64/sme-abi-vg.c:27:5: error: call to undeclared function '__init_cpu_features'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
    27 |     __init_cpu_features();
       |     ^
compiler-rt/lib/builtins/aarch64/sme-abi-vg.c:33:60: error: use of undeclared identifier 'FEAT_SVE'
    33 |   bool HasSVE = __aarch64_cpu_features.features & (1ULL << FEAT_SVE);

The new C file, sme-abi-vg.c, doesn't have #if !defined(DISABLE_AARCH64_FMV).

kmclaughlin-arm added a commit that referenced this pull request Jun 12, 2024
…ioning is not supported (#94973)

This prevents build failures when building with `DISABLE_AARCH64_FMV`,
see #92921.
@kmclaughlin-arm kmclaughlin-arm deleted the get-rt-vl branch June 14, 2024 12:55
sdesmalen-arm added a commit to sdesmalen-arm/llvm-project that referenced this pull request Dec 10, 2024
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`.
sdesmalen-arm added a commit to sdesmalen-arm/llvm-project that referenced this pull request Dec 10, 2024
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`.
sdesmalen-arm added a commit to sdesmalen-arm/llvm-project that referenced this pull request Dec 10, 2024
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`.
sdesmalen-arm added a commit that referenced this pull request Dec 11, 2024
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants