-
Notifications
You must be signed in to change notification settings - Fork 13.6k
release/19.x: [clang][AArch64] Add SME2.1 feature macros (#105657) #106135
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@sdesmalen-arm What do you think about merging this PR to the release branch? |
@llvm/pr-subscribers-clang @llvm/pr-subscribers-backend-aarch64 Author: None (llvmbot) ChangesBackport 2617023 Requested by: @sdesmalen-arm Full diff: https://github.com/llvm/llvm-project/pull/106135.diff 3 Files Affected:
diff --git a/clang/lib/Basic/Targets/AArch64.cpp b/clang/lib/Basic/Targets/AArch64.cpp
index 6ba31cc05a0d75..63fc15f916c558 100644
--- a/clang/lib/Basic/Targets/AArch64.cpp
+++ b/clang/lib/Basic/Targets/AArch64.cpp
@@ -471,23 +471,25 @@ void AArch64TargetInfo::getTargetDefines(const LangOptions &Opts,
if (HasSVE2 && HasSVE2SM4)
Builder.defineMacro("__ARM_FEATURE_SVE2_SM4", "1");
+ if (HasSVEB16B16)
+ Builder.defineMacro("__ARM_FEATURE_SVE_B16B16", "1");
+
if (HasSME) {
Builder.defineMacro("__ARM_FEATURE_SME");
Builder.defineMacro("__ARM_FEATURE_LOCALLY_STREAMING", "1");
}
- if (HasSME2) {
- Builder.defineMacro("__ARM_FEATURE_SME", "1");
+ if (HasSME2)
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");
+ if (HasSME2p1)
Builder.defineMacro("__ARM_FEATURE_SME2p1", "1");
- Builder.defineMacro("__ARM_FEATURE_LOCALLY_STREAMING", "1");
- }
+
+ if (HasSMEF16F16)
+ Builder.defineMacro("__ARM_FEATURE_SME_F16F16", "1");
+
+ if (HasSMEB16B16)
+ Builder.defineMacro("__ARM_FEATURE_SME_B16B16", "1");
if (HasCRC)
Builder.defineMacro("__ARM_FEATURE_CRC32", "1");
@@ -749,6 +751,7 @@ bool AArch64TargetInfo::hasFeature(StringRef Feature) const {
.Case("sve", FPU & SveMode)
.Case("sve-bf16", FPU & SveMode && HasBFloat16)
.Case("sve-i8mm", FPU & SveMode && HasMatMul)
+ .Case("sve-b16b16", HasSVEB16B16)
.Case("f32mm", FPU & SveMode && HasMatmulFP32)
.Case("f64mm", FPU & SveMode && HasMatmulFP64)
.Case("sve2", FPU & SveMode && HasSVE2)
@@ -763,6 +766,8 @@ bool AArch64TargetInfo::hasFeature(StringRef Feature) const {
.Case("sme-f64f64", HasSMEF64F64)
.Case("sme-i16i64", HasSMEI16I64)
.Case("sme-fa64", HasSMEFA64)
+ .Case("sme-f16f16", HasSMEF16F16)
+ .Case("sme-b16b16", HasSMEB16B16)
.Cases("memtag", "memtag2", HasMTE)
.Case("sb", HasSB)
.Case("predres", HasPredRes)
@@ -863,6 +868,8 @@ bool AArch64TargetInfo::handleTargetFeatures(std::vector<std::string> &Features,
HasSVE2 = true;
HasSVE2SM4 = true;
}
+ if (Feature == "+sve-b16b16")
+ HasSVEB16B16 = true;
if (Feature == "+sve2-bitperm") {
FPU |= NeonMode;
FPU |= SveMode;
@@ -919,6 +926,21 @@ bool AArch64TargetInfo::handleTargetFeatures(std::vector<std::string> &Features,
HasSVE2 = true;
HasSMEFA64 = true;
}
+ if (Feature == "+sme-f16f16") {
+ HasSME = true;
+ HasSME2 = true;
+ HasBFloat16 = true;
+ HasFullFP16 = true;
+ HasSMEF16F16 = true;
+ }
+ if (Feature == "+sme-b16b16") {
+ HasSME = true;
+ HasSME2 = true;
+ HasBFloat16 = true;
+ HasFullFP16 = true;
+ HasSVEB16B16 = true;
+ HasSMEB16B16 = true;
+ }
if (Feature == "+sb")
HasSB = true;
if (Feature == "+predres")
diff --git a/clang/lib/Basic/Targets/AArch64.h b/clang/lib/Basic/Targets/AArch64.h
index 7bdf5a2b4106e4..526f7f30a38618 100644
--- a/clang/lib/Basic/Targets/AArch64.h
+++ b/clang/lib/Basic/Targets/AArch64.h
@@ -53,6 +53,7 @@ class LLVM_LIBRARY_VISIBILITY AArch64TargetInfo : public TargetInfo {
bool HasSVE2AES = false;
bool HasSVE2SHA3 = false;
bool HasSVE2SM4 = false;
+ bool HasSVEB16B16 = false;
bool HasSVE2BitPerm = false;
bool HasMatmulFP64 = false;
bool HasMatmulFP32 = false;
@@ -71,6 +72,8 @@ class LLVM_LIBRARY_VISIBILITY AArch64TargetInfo : public TargetInfo {
bool HasSME2 = false;
bool HasSMEF64F64 = false;
bool HasSMEI16I64 = false;
+ bool HasSMEF16F16 = false;
+ bool HasSMEB16B16 = false;
bool HasSME2p1 = false;
bool HasSB = false;
bool HasPredRes = false;
diff --git a/clang/test/Preprocessor/aarch64-target-features.c b/clang/test/Preprocessor/aarch64-target-features.c
index 87bd3e142d2c40..ae2bdda6f536c5 100644
--- a/clang/test/Preprocessor/aarch64-target-features.c
+++ b/clang/test/Preprocessor/aarch64-target-features.c
@@ -709,3 +709,19 @@
// CHECK-SME2p1: __ARM_FEATURE_SME 1
// CHECK-SME2p1: __ARM_FEATURE_SME2 1
// CHECK-SME2p1: __ARM_FEATURE_SME2p1 1
+
+// RUN: %clang --target=aarch64 -march=armv9-a+sve-b16b16 -x c -E -dM %s -o - | FileCheck --check-prefix=CHECK-SVEB16B16 %s
+// CHECK-SVEB16B16: __ARM_FEATURE_SVE_B16B16 1
+
+// RUN: %clang --target=aarch64 -march=armv9-a+sme-f16f16 -x c -E -dM %s -o - | FileCheck --check-prefix=CHECK-SMEF16F16 %s
+// CHECK-SMEF16F16: __ARM_FEATURE_LOCALLY_STREAMING 1
+// CHECK-SMEF16F16: __ARM_FEATURE_SME 1
+// CHECK-SMEF16F16: __ARM_FEATURE_SME2 1
+// CHECK-SMEF16F16: __ARM_FEATURE_SME_F16F16 1
+
+// RUN: %clang --target=aarch64 -march=armv9-a+sme-b16b16 -x c -E -dM %s -o - | FileCheck --check-prefix=CHECK-SMEB16B16 %s
+// CHECK-SMEB16B16: __ARM_FEATURE_LOCALLY_STREAMING 1
+// CHECK-SMEB16B16: __ARM_FEATURE_SME 1
+// CHECK-SMEB16B16: __ARM_FEATURE_SME2 1
+// CHECK-SMEB16B16: __ARM_FEATURE_SME_B16B16 1
+// CHECK-SMEB16B16: __ARM_FEATURE_SVE_B16B16 1
|
Rationale; this helps people who use LLVM 19 to write code for the SME2.1 intrinsics, which the compiler already supports, but without the macros set a user couldn't write compliant code, e.g. |
(cherry picked from commit 2617023)
@sdesmalen-arm (or anyone else). If you would like to add a note about this fix in the release notes (completely optional). Please reply to this comment with a one or two sentence description of the fix. When you are done, please add the release:note label to this PR. |
Backport 2617023
Requested by: @sdesmalen-arm