[clang] [Clang][AArch64] Add missing SME/SVE2.1 feature macros (PR #98058)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Jul 8 10:42:42 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-aarch64
Author: None (SpencerAbson)
<details>
<summary>Changes</summary>
The 2022 SME2.1and SVE2.1 feature macros are missing from Clang. Passing '-target-feature +sme2p1' and 'target-feature +sve2p1' should prompt Clang to define __ARM_FEATURE_SVE2p1 and __ARM_FEATURE_SME2p1 respectively, including their prerequisits..
This patch includes __ARM_FEATURE_SVE2p1 and __ARM_FEATURE_SME2p1, plus a clang preprocessor test for each. It also ensures that the Clang macro builder is in a consistent fashion across Targets/AArch64.cpp.
---
Full diff: https://github.com/llvm/llvm-project/pull/98058.diff
3 Files Affected:
- (modified) clang/lib/Basic/Targets/AArch64.cpp (+28-2)
- (modified) clang/lib/Basic/Targets/AArch64.h (+2)
- (modified) clang/test/Preprocessor/aarch64-target-features.c (+15)
``````````diff
diff --git a/clang/lib/Basic/Targets/AArch64.cpp b/clang/lib/Basic/Targets/AArch64.cpp
index 2692ddec26ff4..d6120ffb685e1 100644
--- a/clang/lib/Basic/Targets/AArch64.cpp
+++ b/clang/lib/Basic/Targets/AArch64.cpp
@@ -448,6 +448,9 @@ void AArch64TargetInfo::getTargetDefines(const LangOptions &Opts,
if (HasSVE2)
Builder.defineMacro("__ARM_FEATURE_SVE2", "1");
+
+ if (HasSVE2p1)
+ Builder.defineMacro("__ARM_FEATURE_SVE2p1", "1");
if (HasSVE2 && HasSVE2AES)
Builder.defineMacro("__ARM_FEATURE_SVE2_AES", "1");
@@ -467,8 +470,15 @@ void AArch64TargetInfo::getTargetDefines(const LangOptions &Opts,
}
if (HasSME2) {
- Builder.defineMacro("__ARM_FEATURE_SME");
- Builder.defineMacro("__ARM_FEATURE_SME2");
+ Builder.defineMacro("__ARM_FEATURE_SME", "1");
+ Builder.defineMacro("__ARM_FEATURE_SME2", "1");
+ Builder.defineMacro("__ARM_FEATURE_LOCALLY_STREAMING", "1");
+ }
+
+ if (HasSME2p1) {
+ Builder.defineMacro("__ARM_FEATURE_SME", "1");
+ Builder.defineMacro("__ARM_FEATURE_SME2", "1");
+ Builder.defineMacro("__ARM_FEATURE_SME2p1", "1");
Builder.defineMacro("__ARM_FEATURE_LOCALLY_STREAMING", "1");
}
@@ -739,8 +749,10 @@ bool AArch64TargetInfo::hasFeature(StringRef Feature) const {
.Case("sve2-bitperm", FPU & SveMode && HasSVE2BitPerm)
.Case("sve2-sha3", FPU & SveMode && HasSVE2SHA3)
.Case("sve2-sm4", FPU & SveMode && HasSVE2SM4)
+ .Case("sve2p1", FPU & SveMode && HasSVE2p1)
.Case("sme", HasSME)
.Case("sme2", HasSME2)
+ .Case("sme2p1", HasSME2p1)
.Case("sme-f64f64", HasSMEF64F64)
.Case("sme-i16i64", HasSMEI16I64)
.Case("sme-fa64", HasSMEFA64)
@@ -816,6 +828,13 @@ bool AArch64TargetInfo::handleTargetFeatures(std::vector<std::string> &Features,
HasFullFP16 = true;
HasSVE2 = true;
}
+ if (Feature == "+sve2p1") {
+ FPU |= NeonMode;
+ FPU |= SveMode;
+ HasFullFP16 = true;
+ HasSVE2 = true;
+ HasSVE2p1 = true;
+ }
if (Feature == "+sve2-aes") {
FPU |= NeonMode;
FPU |= SveMode;
@@ -867,6 +886,13 @@ bool AArch64TargetInfo::handleTargetFeatures(std::vector<std::string> &Features,
HasBFloat16 = true;
HasFullFP16 = true;
}
+ if (Feature == "+sme2p1") {
+ HasSME = true;
+ HasSME2 = true;
+ HasSME2p1 = true;
+ HasBFloat16 = true;
+ HasFullFP16 = true;
+ }
if (Feature == "+sme-f64f64") {
HasSME = true;
HasSMEF64F64 = true;
diff --git a/clang/lib/Basic/Targets/AArch64.h b/clang/lib/Basic/Targets/AArch64.h
index 71510fe289510..7bdf5a2b4106e 100644
--- a/clang/lib/Basic/Targets/AArch64.h
+++ b/clang/lib/Basic/Targets/AArch64.h
@@ -49,6 +49,7 @@ class LLVM_LIBRARY_VISIBILITY AArch64TargetInfo : public TargetInfo {
bool HasMatMul = false;
bool HasBFloat16 = false;
bool HasSVE2 = false;
+ bool HasSVE2p1 = false;
bool HasSVE2AES = false;
bool HasSVE2SHA3 = false;
bool HasSVE2SM4 = false;
@@ -70,6 +71,7 @@ class LLVM_LIBRARY_VISIBILITY AArch64TargetInfo : public TargetInfo {
bool HasSME2 = false;
bool HasSMEF64F64 = false;
bool HasSMEI16I64 = false;
+ bool HasSME2p1 = false;
bool HasSB = false;
bool HasPredRes = false;
bool HasSSBS = false;
diff --git a/clang/test/Preprocessor/aarch64-target-features.c b/clang/test/Preprocessor/aarch64-target-features.c
index 71cc36acf3f0e..87bd3e142d2c4 100644
--- a/clang/test/Preprocessor/aarch64-target-features.c
+++ b/clang/test/Preprocessor/aarch64-target-features.c
@@ -236,6 +236,15 @@
// RUN: %clang -target aarch64-none-linux-gnu -march=armv9-a+sve2-bitperm -x c -E -dM %s -o - | FileCheck --check-prefix=CHECK-SVE2BITPERM %s
// CHECK-SVE2BITPERM: __ARM_FEATURE_SVE2_BITPERM 1
+// RUN: %clang -target aarch64-none-linux-gnu -march=armv9-a+sve2p1 -x c -E -dM %s -o - | FileCheck --check-prefix=CHECK-SVE2p1 %s
+// CHECK-SVE2p1: __ARM_FEATURE_FP16_SCALAR_ARITHMETIC 1
+// CHECK-SVE2p1: __ARM_FEATURE_FP16_VECTOR_ARITHMETIC 1
+// CHECK-SVE2p1: __ARM_FEATURE_SVE2 1
+// CHECK-SVE2p1: __ARM_FEATURE_SVE2p1 1
+// CHECK-SVE2p1: __ARM_NEON 1
+// CHECK-SVE2p1: __ARM_NEON_FP 0xE
+// CHECK-SVE2p1: __ARM_NEON_SVE_BRIDGE 1
+
// RUN: %clang -target aarch64-none-linux-gnu -march=armv8.2a+dotprod -x c -E -dM %s -o - | FileCheck --check-prefix=CHECK-DOTPROD %s
// RUN: %clang -target aarch64-none-linux-gnu -march=armv8.4a -x c -E -dM %s -o - | FileCheck --check-prefix=CHECK-DOTPROD %s
// CHECK-DOTPROD: __ARM_FEATURE_DOTPROD 1
@@ -694,3 +703,9 @@
// CHECK-SME2: __ARM_FEATURE_LOCALLY_STREAMING 1
// CHECK-SME2: __ARM_FEATURE_SME 1
// CHECK-SME2: __ARM_FEATURE_SME2 1
+
+// RUN: %clang --target=aarch64 -march=armv9-a+sme2p1 -x c -E -dM %s -o - | FileCheck --check-prefix=CHECK-SME2p1 %s
+// CHECK-SME2p1: __ARM_FEATURE_LOCALLY_STREAMING 1
+// CHECK-SME2p1: __ARM_FEATURE_SME 1
+// CHECK-SME2p1: __ARM_FEATURE_SME2 1
+// CHECK-SME2p1: __ARM_FEATURE_SME2p1 1
``````````
</details>
https://github.com/llvm/llvm-project/pull/98058
More information about the cfe-commits
mailing list