Skip to content

Commit 9e64951

Browse files
[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.
1 parent 9efdccb commit 9e64951

File tree

4 files changed

+39
-0
lines changed

4 files changed

+39
-0
lines changed

clang/lib/Basic/Targets/AArch64.cpp

+23
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,11 @@ void AArch64TargetInfo::getTargetDefines(const LangOptions &Opts,
386386

387387
Builder.defineMacro("__ARM_ALIGN_MAX_STACK_PWR", "4");
388388

389+
// These macros are set when Clang can parse declarations with these
390+
// attributes.
391+
Builder.defineMacro("__ARM_STATE_ZA", "1");
392+
Builder.defineMacro("__ARM_STATE_ZT0", "1");
393+
389394
// 0xe implies support for half, single and double precision operations.
390395
if (FPU & FPUMode)
391396
Builder.defineMacro("__ARM_FP", "0xE");
@@ -430,6 +435,17 @@ void AArch64TargetInfo::getTargetDefines(const LangOptions &Opts,
430435
if (HasSVE2 && HasSVE2SM4)
431436
Builder.defineMacro("__ARM_FEATURE_SVE2_SM4", "1");
432437

438+
if (HasSME) {
439+
Builder.defineMacro("__ARM_FEATURE_SME");
440+
Builder.defineMacro("__ARM_FEATURE_LOCALLY_STREAMING", "1");
441+
}
442+
443+
if (HasSME2) {
444+
Builder.defineMacro("__ARM_FEATURE_SME");
445+
Builder.defineMacro("__ARM_FEATURE_SME2");
446+
Builder.defineMacro("__ARM_FEATURE_LOCALLY_STREAMING", "1");
447+
}
448+
433449
if (HasCRC)
434450
Builder.defineMacro("__ARM_FEATURE_CRC32", "1");
435451

@@ -692,6 +708,7 @@ bool AArch64TargetInfo::hasFeature(StringRef Feature) const {
692708
.Case("sve2-sha3", FPU & SveMode && HasSVE2SHA3)
693709
.Case("sve2-sm4", FPU & SveMode && HasSVE2SM4)
694710
.Case("sme", HasSME)
711+
.Case("sme2", HasSME2)
695712
.Case("sme-f64f64", HasSMEF64F64)
696713
.Case("sme-i16i64", HasSMEI16I64)
697714
.Case("sme-fa64", HasSMEFA64)
@@ -812,6 +829,12 @@ bool AArch64TargetInfo::handleTargetFeatures(std::vector<std::string> &Features,
812829
HasBFloat16 = true;
813830
HasFullFP16 = true;
814831
}
832+
if (Feature == "+sme2") {
833+
HasSME = true;
834+
HasSME2 = true;
835+
HasBFloat16 = true;
836+
HasFullFP16 = true;
837+
}
815838
if (Feature == "+sme-f64f64") {
816839
HasSME = true;
817840
HasSMEF64F64 = true;

clang/lib/Basic/Targets/AArch64.h

+1
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

+13
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@
6060
// CHECK-NOT: __ARM_FEATURE_SVE_BITS 512
6161
// CHECK-NOT: __ARM_FEATURE_SVE_BITS 1024
6262
// CHECK-NOT: __ARM_FEATURE_SVE_BITS 2048
63+
// CHECK: __ARM_STATE_ZA 1
64+
// CHECK: __ARM_STATE_ZT0 1
65+
// CHECK-NOT: __ARM_FEATURE_SME
66+
// CHECK-NOT: __ARM_FEATURE_SME2
6367

6468
// RUN: %clang -target aarch64-none-elf -march=armv8-r -x c -E -dM %s -o - | FileCheck %s -check-prefix CHECK-R-PROFILE
6569
// RUN: %clang -target arm64-none-linux-gnu -march=armv8-r -x c -E -dM %s -o - | FileCheck %s -check-prefix CHECK-R-PROFILE
@@ -672,3 +676,12 @@
672676

673677
// RUN: %clang --target=aarch64 -march=armv8.2-a+rcpc3 -x c -E -dM %s -o - | FileCheck --check-prefix=CHECK-RCPC3 %s
674678
// CHECK-RCPC3: __ARM_FEATURE_RCPC 3
679+
680+
// RUN: %clang --target=aarch64 -march=armv9-a+sme -x c -E -dM %s -o - | FileCheck --check-prefix=CHECK-SME %s
681+
// CHECK-SME: __ARM_FEATURE_LOCALLY_STREAMING 1
682+
// CHECK-SME: __ARM_FEATURE_SME 1
683+
//
684+
// RUN: %clang --target=aarch64 -march=armv9-a+sme2 -x c -E -dM %s -o - | FileCheck --check-prefix=CHECK-SME2 %s
685+
// CHECK-SME2: __ARM_FEATURE_LOCALLY_STREAMING 1
686+
// CHECK-SME2: __ARM_FEATURE_SME 1
687+
// CHECK-SME2: __ARM_FEATURE_SME2 1

clang/test/Preprocessor/init-aarch64.c

+2
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)