Skip to content

Commit dd8d8d8

Browse files
sdesmalen-armwwwatermiao
authored andcommitted
[Clang][AArch64] Add missing SME macros (#80293)
__ARM_STATE_ZA and __ARM_STATE_ZT0 are set when the compiler can parse the "za" and "zt0" strings in the SME attributes. __ARM_FEATURE_SME and __ARM_FEATURE_SME2 are set when the compiler can generate code for attributes with "za" and "zt0" state, respectively. __ARM_FEATURE_LOCALLY_STREAMING is set when the compiler supports the __arm_locally_streaming attribute. Signed-off-by: chenmiao <[email protected]> Signed-off-by: chenmiao <[email protected]>
1 parent 0c96571 commit dd8d8d8

File tree

4 files changed

+39
-0
lines changed

4 files changed

+39
-0
lines changed

clang/lib/Basic/Targets/AArch64.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,11 @@ void AArch64TargetInfo::getTargetDefines(const LangOptions &Opts,
374374

375375
Builder.defineMacro("__ARM_ALIGN_MAX_STACK_PWR", "4");
376376

377+
// These macros are set when Clang can parse declarations with these
378+
// attributes.
379+
Builder.defineMacro("__ARM_STATE_ZA", "1");
380+
Builder.defineMacro("__ARM_STATE_ZT0", "1");
381+
377382
// 0xe implies support for half, single and double precision operations.
378383
if (FPU & FPUMode)
379384
Builder.defineMacro("__ARM_FP", "0xE");
@@ -418,6 +423,17 @@ void AArch64TargetInfo::getTargetDefines(const LangOptions &Opts,
418423
if (HasSVE2 && HasSVE2SM4)
419424
Builder.defineMacro("__ARM_FEATURE_SVE2_SM4", "1");
420425

426+
if (HasSME) {
427+
Builder.defineMacro("__ARM_FEATURE_SME");
428+
Builder.defineMacro("__ARM_FEATURE_LOCALLY_STREAMING", "1");
429+
}
430+
431+
if (HasSME2) {
432+
Builder.defineMacro("__ARM_FEATURE_SME");
433+
Builder.defineMacro("__ARM_FEATURE_SME2");
434+
Builder.defineMacro("__ARM_FEATURE_LOCALLY_STREAMING", "1");
435+
}
436+
421437
if (HasCRC)
422438
Builder.defineMacro("__ARM_FEATURE_CRC32", "1");
423439

@@ -670,6 +686,7 @@ bool AArch64TargetInfo::hasFeature(StringRef Feature) const {
670686
.Case("sve2-sha3", FPU & SveMode && HasSVE2SHA3)
671687
.Case("sve2-sm4", FPU & SveMode && HasSVE2SM4)
672688
.Case("sme", HasSME)
689+
.Case("sme2", HasSME2)
673690
.Case("sme-f64f64", HasSMEF64F64)
674691
.Case("sme-i16i64", HasSMEI16I64)
675692
.Case("sme-fa64", HasSMEFA64)
@@ -790,6 +807,12 @@ bool AArch64TargetInfo::handleTargetFeatures(std::vector<std::string> &Features,
790807
HasBFloat16 = true;
791808
HasFullFP16 = true;
792809
}
810+
if (Feature == "+sme2") {
811+
HasSME = true;
812+
HasSME2 = true;
813+
HasBFloat16 = true;
814+
HasFullFP16 = true;
815+
}
793816
if (Feature == "+sme-f64f64") {
794817
HasSME = true;
795818
HasSMEF64F64 = true;

clang/lib/Basic/Targets/AArch64.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ class LLVM_LIBRARY_VISIBILITY AArch64TargetInfo : public TargetInfo {
6868
bool HasCCDP = false;
6969
bool HasFRInt3264 = false;
7070
bool HasSME = false;
71+
bool HasSME2 = false;
7172
bool HasSMEF64F64 = false;
7273
bool HasSMEI16I64 = false;
7374
bool HasSB = false;

clang/test/Preprocessor/aarch64-target-features.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@
5858
// CHECK-NOT: __ARM_FEATURE_SVE_BITS 512
5959
// CHECK-NOT: __ARM_FEATURE_SVE_BITS 1024
6060
// CHECK-NOT: __ARM_FEATURE_SVE_BITS 2048
61+
// CHECK: __ARM_STATE_ZA 1
62+
// CHECK: __ARM_STATE_ZT0 1
63+
// CHECK-NOT: __ARM_FEATURE_SME
64+
// CHECK-NOT: __ARM_FEATURE_SME2
6165

6266
// RUN: %clang -target aarch64-none-elf -march=armv8-r -x c -E -dM %s -o - | FileCheck %s -check-prefix CHECK-R-PROFILE
6367
// RUN: %clang -target arm64-none-linux-gnu -march=armv8-r -x c -E -dM %s -o - | FileCheck %s -check-prefix CHECK-R-PROFILE
@@ -616,3 +620,12 @@
616620

617621
// RUN: %clang --target=aarch64 -march=armv8.2-a+rcpc3 -x c -E -dM %s -o - | FileCheck --check-prefix=CHECK-RCPC3 %s
618622
// CHECK-RCPC3: __ARM_FEATURE_RCPC 3
623+
624+
// RUN: %clang --target=aarch64 -march=armv9-a+sme -x c -E -dM %s -o - | FileCheck --check-prefix=CHECK-SME %s
625+
// CHECK-SME: __ARM_FEATURE_LOCALLY_STREAMING 1
626+
// CHECK-SME: __ARM_FEATURE_SME 1
627+
//
628+
// RUN: %clang --target=aarch64 -march=armv9-a+sme2 -x c -E -dM %s -o - | FileCheck --check-prefix=CHECK-SME2 %s
629+
// CHECK-SME2: __ARM_FEATURE_LOCALLY_STREAMING 1
630+
// CHECK-SME2: __ARM_FEATURE_SME 1
631+
// CHECK-SME2: __ARM_FEATURE_SME2 1

clang/test/Preprocessor/init-aarch64.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
// AARCH64-NEXT: #define __ARM_PCS_AAPCS64 1
3333
// AARCH64-NEXT: #define __ARM_SIZEOF_MINIMAL_ENUM 4
3434
// AARCH64-NEXT: #define __ARM_SIZEOF_WCHAR_T 4
35+
// AARCH64-NEXT: #define __ARM_STATE_ZA 1
36+
// AARCH64-NEXT: #define __ARM_STATE_ZT0 1
3537
// AARCH64-NEXT: #define __ATOMIC_ACQUIRE 2
3638
// AARCH64-NEXT: #define __ATOMIC_ACQ_REL 4
3739
// AARCH64-NEXT: #define __ATOMIC_CONSUME 1

0 commit comments

Comments
 (0)