Skip to content

Commit ff9cdbd

Browse files
[Clang][Sema] Extend test coverage for SVE/SME builtin usage. (#156908)
Adds SEMA tests to verify correct SVE/SME builtin usage based on the calling function's type (i.e. normal, streaming or streaming compatible). For invalid uses the tests verify the expected diagnostic is emitted. This exposed an issue whereby some builtins are incorrectly callable by streaming compatible functions, which this PR fixes. The tests are autogenerated based on the builtin definitions (e.g. arm_sve.td). This is achieved by extending SVEEmitter, which can now emit a JSON file containing builtin usage information that can be fed to aarch64_builtins_test_generator.py that is also part of this PR. Everything currently in `clang/test/Sema/AArch64` is the result of: ``` clang/utils/aarch64_builtins_test_generator.py --gen-streaming-guard-tests <LLVM_BUILD_DIR>/tools/clang/include/clang/Basic/arm_sve_builtins.json --out-dir clang/test/Sema/AArch64/ clang/utils/aarch64_builtins_test_generator.py --gen-streaming-guard-tests <LLVM_BUILD_DIR>/tools/clang/include/clang/Basic/arm_sme_builtins.json --out-dir clang/test/Sema/AArch64/ ```
1 parent ad00610 commit ff9cdbd

File tree

68 files changed

+69142
-81
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+69142
-81
lines changed

clang/include/clang/Basic/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,9 @@ clang_tablegen(arm_mve_builtin_aliases.inc -gen-arm-mve-builtin-aliases
159159
clang_tablegen(arm_sve_builtins.inc -gen-arm-sve-builtins
160160
SOURCE arm_sve.td
161161
TARGET ClangARMSveBuiltins)
162+
clang_tablegen(arm_sve_builtins.json -gen-arm-sve-builtins-json
163+
SOURCE arm_sve.td
164+
TARGET ClangARMSveBuiltinsJSON)
162165
clang_tablegen(arm_sve_builtin_cg.inc -gen-arm-sve-builtin-codegen
163166
SOURCE arm_sve.td
164167
TARGET ClangARMSveBuiltinCG)
@@ -174,6 +177,9 @@ clang_tablegen(arm_sve_streaming_attrs.inc -gen-arm-sve-streaming-attrs
174177
clang_tablegen(arm_sme_builtins.inc -gen-arm-sme-builtins
175178
SOURCE arm_sme.td
176179
TARGET ClangARMSmeBuiltins)
180+
clang_tablegen(arm_sme_builtins.json -gen-arm-sme-builtins-json
181+
SOURCE arm_sme.td
182+
TARGET ClangARMSmeBuiltinsJSON)
177183
clang_tablegen(arm_sme_builtin_cg.inc -gen-arm-sme-builtin-codegen
178184
SOURCE arm_sme.td
179185
TARGET ClangARMSmeBuiltinCG)

clang/lib/Sema/SemaARM.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -603,8 +603,8 @@ static bool checkArmStreamingBuiltin(Sema &S, CallExpr *TheCall,
603603
bool SatisfiesSME = Builtin::evaluateRequiredTargetFeatures(
604604
StreamingBuiltinGuard, CallerFeatures);
605605

606-
if ((SatisfiesSVE && SatisfiesSME) ||
607-
(SatisfiesSVE && FnType == SemaARM::ArmStreamingCompatible))
606+
if (SatisfiesSVE && SatisfiesSME)
607+
// Function type is irrelevant for streaming-agnostic builtins.
608608
return false;
609609
else if (SatisfiesSVE)
610610
BuiltinType = SemaARM::ArmNonStreaming;

clang/test/CodeGen/AArch64/sve2-intrinsics/acle_sve2_rax1.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
2-
// RUN: %clang_cc1 -fclang-abi-compat=latest -triple aarch64 -target-feature +sve -target-feature +sve2 -target-feature +sve-sha3 -O1 -Werror -Wall -emit-llvm -o - %s | FileCheck %s
3-
// RUN: %clang_cc1 -fclang-abi-compat=latest -triple aarch64 -target-feature +sme -target-feature +sme2 -target-feature +sme2p1 -target-feature +sve-sha3 -O1 -Werror -Wall -emit-llvm -o - %s | FileCheck %s
4-
// RUN: %clang_cc1 -fclang-abi-compat=latest -triple aarch64 -target-feature +sve -target-feature +sve2 -target-feature +sme2p1 -target-feature +sve-sha3 -O1 -Werror -Wall -emit-llvm -o - %s | FileCheck %s
5-
// RUN: %clang_cc1 -fclang-abi-compat=latest -triple aarch64 -target-feature +sve -target-feature +sve2 -target-feature +sve-sha3 -O1 -Werror -Wall -emit-llvm -o - -x c++ %s | FileCheck %s -check-prefix=CPP-CHECK
6-
// RUN: %clang_cc1 -fclang-abi-compat=latest -DSVE_OVERLOADED_FORMS -triple aarch64 -target-feature +sve -target-feature +sve2 -target-feature +sve-sha3 -O1 -Werror -Wall -emit-llvm -o - %s | FileCheck %s
7-
// RUN: %clang_cc1 -fclang-abi-compat=latest -DSVE_OVERLOADED_FORMS -triple aarch64 -target-feature +sve -target-feature +sve2 -target-feature +sve-sha3 -O1 -Werror -Wall -emit-llvm -o - -x c++ %s | FileCheck %s -check-prefix=CPP-CHECK
2+
// RUN: %clang_cc1 -fclang-abi-compat=latest -triple aarch64 -target-feature +sve -target-feature +sve-sha3 -O1 -Werror -Wall -emit-llvm -o - %s | FileCheck %s
3+
// RUN: %clang_cc1 -fclang-abi-compat=latest -triple aarch64 -target-feature +sme -target-feature +sme2p1 -target-feature +sve-sha3 -O1 -Werror -Wall -emit-llvm -o - %s | FileCheck %s
4+
// RUN: %clang_cc1 -fclang-abi-compat=latest -triple aarch64 -target-feature +sve -target-feature +sve-sha3 -O1 -Werror -Wall -emit-llvm -o - -x c++ %s | FileCheck %s -check-prefix=CPP-CHECK
5+
// RUN: %clang_cc1 -fclang-abi-compat=latest -DSVE_OVERLOADED_FORMS -triple aarch64 -target-feature +sve -target-feature +sve-sha3 -O1 -Werror -Wall -emit-llvm -o - %s | FileCheck %s
6+
// RUN: %clang_cc1 -fclang-abi-compat=latest -DSVE_OVERLOADED_FORMS -triple aarch64 -target-feature +sve -target-feature +sve-sha3 -O1 -Werror -Wall -emit-llvm -o - -x c++ %s | FileCheck %s -check-prefix=CPP-CHECK
87

98
// REQUIRES: aarch64-registered-target
109

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// NOTE: File has been autogenerated by utils/aarch64_builtins_test_generator.py
2+
// RUN: %clang_cc1 %s -fsyntax-only -triple aarch64-none-linux-gnu -target-feature +sme -verify
3+
// expected-no-diagnostics
4+
5+
// REQUIRES: aarch64-registered-target
6+
7+
#include <arm_sme.h>
8+
9+
// Properties: guard="" streaming_guard="sme" flags="streaming-compatible,requires-za"
10+
11+
void test(void) __arm_inout("za"){
12+
int64_t int64_t_val;
13+
uint32_t uint32_t_val;
14+
void * void_ptr_val;
15+
16+
svldr_vnum_za(uint32_t_val, void_ptr_val, int64_t_val);
17+
svldr_za(uint32_t_val, void_ptr_val);
18+
svstr_vnum_za(uint32_t_val, void_ptr_val, int64_t_val);
19+
svstr_za(uint32_t_val, void_ptr_val);
20+
svzero_mask_za(2);
21+
svzero_za();
22+
}
23+
24+
void test_streaming(void) __arm_streaming __arm_inout("za"){
25+
int64_t int64_t_val;
26+
uint32_t uint32_t_val;
27+
void * void_ptr_val;
28+
29+
svldr_vnum_za(uint32_t_val, void_ptr_val, int64_t_val);
30+
svldr_za(uint32_t_val, void_ptr_val);
31+
svstr_vnum_za(uint32_t_val, void_ptr_val, int64_t_val);
32+
svstr_za(uint32_t_val, void_ptr_val);
33+
svzero_mask_za(2);
34+
svzero_za();
35+
}
36+
37+
void test_streaming_compatible(void) __arm_streaming_compatible __arm_inout("za"){
38+
int64_t int64_t_val;
39+
uint32_t uint32_t_val;
40+
void * void_ptr_val;
41+
42+
svldr_vnum_za(uint32_t_val, void_ptr_val, int64_t_val);
43+
svldr_za(uint32_t_val, void_ptr_val);
44+
svstr_vnum_za(uint32_t_val, void_ptr_val, int64_t_val);
45+
svstr_za(uint32_t_val, void_ptr_val);
46+
svzero_mask_za(2);
47+
svzero_za();
48+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// NOTE: File has been autogenerated by utils/aarch64_builtins_test_generator.py
2+
// RUN: %clang_cc1 %s -fsyntax-only -triple aarch64-none-linux-gnu -target-feature +sme -target-feature +sme2 -verify
3+
// expected-no-diagnostics
4+
5+
// REQUIRES: aarch64-registered-target
6+
7+
#include <arm_sme.h>
8+
9+
// Properties: guard="" streaming_guard="sme,sme2" flags="streaming-compatible,requires-zt"
10+
11+
void test(void) __arm_inout("zt0"){
12+
void * void_ptr_val;
13+
14+
svldr_zt(0, void_ptr_val);
15+
svstr_zt(0, void_ptr_val);
16+
svzero_zt(0);
17+
}
18+
19+
void test_streaming(void) __arm_streaming __arm_inout("zt0"){
20+
void * void_ptr_val;
21+
22+
svldr_zt(0, void_ptr_val);
23+
svstr_zt(0, void_ptr_val);
24+
svzero_zt(0);
25+
}
26+
27+
void test_streaming_compatible(void) __arm_streaming_compatible __arm_inout("zt0"){
28+
void * void_ptr_val;
29+
30+
svldr_zt(0, void_ptr_val);
31+
svstr_zt(0, void_ptr_val);
32+
svzero_zt(0);
33+
}

0 commit comments

Comments
 (0)