Skip to content

[clang][AArch64] Add SME2.1 feature macros #105657

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

Merged
merged 1 commit into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 31 additions & 9 deletions clang/lib/Basic/Targets/AArch64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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")
Expand Down
3 changes: 3 additions & 0 deletions clang/lib/Basic/Targets/AArch64.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
16 changes: 16 additions & 0 deletions clang/test/Preprocessor/aarch64-target-features.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading