Skip to content

Commit c83a13c

Browse files
sdesmalen-armllvmbot
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. (cherry picked from commit 9e64951)
1 parent 1cfd46f commit c83a13c

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
@@ -387,6 +387,11 @@ void AArch64TargetInfo::getTargetDefines(const LangOptions &Opts,
387387

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

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

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

@@ -686,6 +702,7 @@ bool AArch64TargetInfo::hasFeature(StringRef Feature) const {
686702
.Case("sve2-sha3", FPU & SveMode && HasSVE2SHA3)
687703
.Case("sve2-sm4", FPU & SveMode && HasSVE2SM4)
688704
.Case("sme", HasSME)
705+
.Case("sme2", HasSME2)
689706
.Case("sme-f64f64", HasSMEF64F64)
690707
.Case("sme-i16i64", HasSMEI16I64)
691708
.Case("sme-fa64", HasSMEFA64)
@@ -806,6 +823,12 @@ bool AArch64TargetInfo::handleTargetFeatures(std::vector<std::string> &Features,
806823
HasBFloat16 = true;
807824
HasFullFP16 = true;
808825
}
826+
if (Feature == "+sme2") {
827+
HasSME = true;
828+
HasSME2 = true;
829+
HasBFloat16 = true;
830+
HasFullFP16 = true;
831+
}
809832
if (Feature == "+sme-f64f64") {
810833
HasSME = true;
811834
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
@@ -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
@@ -634,3 +638,12 @@
634638

635639
// RUN: %clang --target=aarch64 -march=armv8.2-a+rcpc3 -x c -E -dM %s -o - | FileCheck --check-prefix=CHECK-RCPC3 %s
636640
// CHECK-RCPC3: __ARM_FEATURE_RCPC 3
641+
642+
// RUN: %clang --target=aarch64 -march=armv9-a+sme -x c -E -dM %s -o - | FileCheck --check-prefix=CHECK-SME %s
643+
// CHECK-SME: __ARM_FEATURE_LOCALLY_STREAMING 1
644+
// CHECK-SME: __ARM_FEATURE_SME 1
645+
//
646+
// RUN: %clang --target=aarch64 -march=armv9-a+sme2 -x c -E -dM %s -o - | FileCheck --check-prefix=CHECK-SME2 %s
647+
// CHECK-SME2: __ARM_FEATURE_LOCALLY_STREAMING 1
648+
// CHECK-SME2: __ARM_FEATURE_SME 1
649+
// 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)