LiuChen3 updated this revision to Diff 450724.
LiuChen3 added a comment.
change the error report
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D131134/new/
https://reviews.llvm.org/D131134
Files:
clang/include/clang/Basic/DiagnosticCommonKinds.td
clang/lib/Basic/Targets/X86.cpp
clang/lib/Driver/ToolChains/Arch/X86.cpp
clang/test/Driver/x86-target-features.c
clang/test/Preprocessor/predefined-arch-macros.c
clang/test/Preprocessor/x86_amx_target_features.c
Index: clang/test/Preprocessor/x86_amx_target_features.c
===================================================================
--- clang/test/Preprocessor/x86_amx_target_features.c
+++ clang/test/Preprocessor/x86_amx_target_features.c
@@ -1,35 +1,35 @@
-// RUN: %clang -target i386-unknown-linux-gnu -march=i386 -mamx-tile -x c -E -dM -o - %s | FileCheck -check-prefix=AMX-TILE %s
+// RUN: %clang -target x86_64-unknown-linux-gnu -march=x86-64 -mamx-tile -x c -E -dM -o - %s | FileCheck -check-prefix=AMX-TILE %s
// AMX-TILE: #define __AMXTILE__ 1
-// RUN: %clang -target i386-unknown-linux-gnu -march=i386 -mamx-bf16 -x c -E -dM -o - %s | FileCheck -check-prefix=AMX-BF16 %s
+// RUN: %clang -target x86_64-unknown-linux-gnu -march=x86-64 -mamx-bf16 -x c -E -dM -o - %s | FileCheck -check-prefix=AMX-BF16 %s
// AMX-BF16: #define __AMXBF16__ 1
// AMX-BF16: #define __AMXTILE__ 1
-// RUN: %clang -target i386-unknown-linux-gnu -march=i386 -mamx-int8 -x c -E -dM -o - %s | FileCheck -check-prefix=AMX-INT8 %s
+// RUN: %clang -target x86_64-unknown-linux-gnu -march=x86-64 -mamx-int8 -x c -E -dM -o - %s | FileCheck -check-prefix=AMX-INT8 %s
// AMX-INT8: #define __AMXINT8__ 1
// AMX-INT8: #define __AMXTILE__ 1
-// RUN: %clang -target i386-unknown-linux-gnu -march=i386 -mno-amx-tile -x c -E -dM -o - %s | FileCheck -check-prefix=NOAMX-TILE %s
+// RUN: %clang -target x86_64-unknown-linux-gnu -march=x86-64 -mno-amx-tile -x c -E -dM -o - %s | FileCheck -check-prefix=NOAMX-TILE %s
// NOAMX-TILE-NOT: #define __AMXTILE__ 1
-// RUN: %clang -target i386-unknown-linux-gnu -march=i386 -mno-amx-bf16 -x c -E -dM -o - %s | FileCheck -check-prefix=NOAMX-BF16 %s
+// RUN: %clang -target x86_64-unknown-linux-gnu -march=x86-64 -mno-amx-bf16 -x c -E -dM -o - %s | FileCheck -check-prefix=NOAMX-BF16 %s
// NOAMX-BF16-NOT: #define __AMXBF16__ 1
-// RUN: %clang -target i386-unknown-linux-gnu -march=i386 -amx-bf16 -mno-amx-tile -x c -E -dM -o - %s | FileCheck -check-prefix=NOAMX-BF16 %s
+// RUN: %clang -target x86_64-unknown-linux-gnu -march=x86-64 -amx-bf16 -mno-amx-tile -x c -E -dM -o - %s | FileCheck -check-prefix=NOAMX-BF16 %s
// NOAMX-BF16-NOT: #define __AMXTILE__ 1
// NOAMX-BF16-NOT: #define __AMXBF16__ 1
-// RUN: %clang -target i386-unknown-linux-gnu -march=i386 -mno-amx-int8 -x c -E -dM -o - %s | FileCheck -check-prefix=NOAMX-INT8 %s
+// RUN: %clang -target x86_64-unknown-linux-gnu -march=x86-64 -mno-amx-int8 -x c -E -dM -o - %s | FileCheck -check-prefix=NOAMX-INT8 %s
// NOAMX-INT8-NOT: #define __AMXINT8__ 1
-// RUN: %clang -target i386-unknown-linux-gnu -march=i386 -amx-int8 -mno-amx-tile -x c -E -dM -o - %s | FileCheck -check-prefix=NOAMX-INT8 %s
+// RUN: %clang -target x86_64-unknown-linux-gnu -march=x86-64 -amx-int8 -mno-amx-tile -x c -E -dM -o - %s | FileCheck -check-prefix=NOAMX-INT8 %s
// NOAMX-INT8-NOT: #define __AMXTILE__ 1
// NOAMX-INT8-NOT: #define __AMXINT8__ 1
Index: clang/test/Preprocessor/predefined-arch-macros.c
===================================================================
--- clang/test/Preprocessor/predefined-arch-macros.c
+++ clang/test/Preprocessor/predefined-arch-macros.c
@@ -1647,9 +1647,6 @@
// RUN: -target i386-unknown-linux \
// RUN: | FileCheck -match-full-lines %s -check-prefix=CHECK_SPR_M32
// CHECK_SPR_M32: #define __AES__ 1
-// CHECK_SPR_M32: #define __AMXBF16__ 1
-// CHECK_SPR_M32: #define __AMXINT8__ 1
-// CHECK_SPR_M32: #define __AMXTILE__ 1
// CHECK_SPR_M32: #define __AVX2__ 1
// CHECK_SPR_M32: #define __AVX512BF16__ 1
// CHECK_SPR_M32: #define __AVX512BITALG__ 1
@@ -1716,7 +1713,7 @@
// CHECK_SPR_M32: #define i386 1
// RUN: %clang -march=sapphirerapids -m64 -E -dM %s -o - 2>&1 \
-// RUN: -target i386-unknown-linux \
+// RUN: -target x86_64-unknown-linux \
// RUN: | FileCheck -match-full-lines %s -check-prefix=CHECK_SPR_M64
// CHECK_SPR_M64: #define __AES__ 1
// CHECK_SPR_M64: #define __AMXBF16__ 1
Index: clang/test/Driver/x86-target-features.c
===================================================================
--- clang/test/Driver/x86-target-features.c
+++ clang/test/Driver/x86-target-features.c
@@ -270,20 +270,26 @@
// WIDE_KL: "-target-feature" "+widekl"
// NO-WIDE_KL: "-target-feature" "-widekl"
-// RUN: %clang --target=i386 -march=i386 -mamx-tile %s -### 2>&1 | FileCheck --check-prefix=AMX-TILE %s
-// RUN: %clang --target=i386 -march=i386 -mno-amx-tile %s -### 2>&1 | FileCheck --check-prefix=NO-AMX-TILE %s
+// RUN: %clang --target=x86_64 -march=x86-64 -mamx-tile %s -### 2>&1 | FileCheck --check-prefix=AMX-TILE %s
+// RUN: %clang --target=x86_64 -march=x86-64 -mno-amx-tile %s -### 2>&1 | FileCheck --check-prefix=NO-AMX-TILE %s
+// RUN: not %clang --target=i386 -march=i386 -mamx-tile %s 2>&1 | FileCheck %s -check-prefix=AMX-TILE-ERROR
// AMX-TILE: "-target-feature" "+amx-tile"
// NO-AMX-TILE: "-target-feature" "-amx-tile"
+// AMX-TILE-ERROR: error: option '-mamx-tile' cannot be specified on this target
-// RUN: %clang --target=i386 -march=i386 -mamx-bf16 %s -### 2>&1 | FileCheck --check-prefix=AMX-BF16 %s
-// RUN: %clang --target=i386 -march=i386 -mno-amx-bf16 %s -### 2>&1 | FileCheck -check-prefix=NO-AMX-BF16 %s
+// RUN: %clang --target=x86_64 -march=x86-64 -mamx-bf16 %s -### 2>&1 | FileCheck --check-prefix=AMX-BF16 %s
+// RUN: %clang --target=x86_64 -march=x86-64 -mno-amx-bf16 %s -### 2>&1 | FileCheck -check-prefix=NO-AMX-BF16 %s
+// RUN: not %clang --target=i386 -march=i386 -mamx-bf16 %s 2>&1 | FileCheck -check-prefix=AMX-BF16-ERROR %s
// AMX-BF16: "-target-feature" "+amx-bf16"
// NO-AMX-BF16: "-target-feature" "-amx-bf16"
+// AMX-BF16-ERROR: error: option '-mamx-bf16' cannot be specified on this target
-// RUN: %clang --target=i386 -march=i386 -mamx-int8 %s -### 2>&1 | FileCheck --check-prefix=AMX-INT8 %s
-// RUN: %clang --target=i386 -march=i386 -mno-amx-int8 %s -### 2>&1 | FileCheck --check-prefix=NO-AMX-INT8 %s
+// RUN: %clang --target=x86_64 -march=x86-64 -mamx-int8 %s -### 2>&1 | FileCheck --check-prefix=AMX-INT8 %s
+// RUN: %clang --target=x86_64 -march=x86-64 -mno-amx-int8 %s -### 2>&1 | FileCheck --check-prefix=NO-AMX-INT8 %s
+// RUN: not %clang --target=i386 -march=i386 -mamx-int8 %s 2>&1 | FileCheck -check-prefix=AMX-INT8-ERROR %s
// AMX-INT8: "-target-feature" "+amx-int8"
// NO-AMX-INT8: "-target-feature" "-amx-int8"
+// AMX-INT8-ERROR: error: option '-mamx-int8' cannot be specified on this target
// RUN: %clang --target=i386 -march=i386 -mhreset %s -### 2>&1 | FileCheck -check-prefix=HRESET %s
// RUN: %clang --target=i386 -march=i386 -mno-hreset %s -### 2>&1 | FileCheck -check-prefix=NO-HRESET %s
Index: clang/lib/Driver/ToolChains/Arch/X86.cpp
===================================================================
--- clang/lib/Driver/ToolChains/Arch/X86.cpp
+++ clang/lib/Driver/ToolChains/Arch/X86.cpp
@@ -125,12 +125,17 @@
std::vector<StringRef> &Features) {
// If -march=native, autodetect the feature list.
if (const Arg *A = Args.getLastArg(clang::driver::options::OPT_march_EQ)) {
+ bool Is64bitTarget = Triple.getArch() != llvm::Triple::x86;
if (StringRef(A->getValue()) == "native") {
llvm::StringMap<bool> HostFeatures;
if (llvm::sys::getHostCPUFeatures(HostFeatures))
- for (auto &F : HostFeatures)
+ for (auto &F : HostFeatures) {
+ if (F.first().startswith("amx") && F.second && !Is64bitTarget)
+ D.Diag(diag::err_feature_unsupported_on_target)
+ << F.first() << Triple.getArchName();
Features.push_back(
Args.MakeArgString((F.second ? "+" : "-") + F.first()));
+ }
}
}
Index: clang/lib/Basic/Targets/X86.cpp
===================================================================
--- clang/lib/Basic/Targets/X86.cpp
+++ clang/lib/Basic/Targets/X86.cpp
@@ -185,6 +185,7 @@
/// configured set of features.
bool X86TargetInfo::handleTargetFeatures(std::vector<std::string> &Features,
DiagnosticsEngine &Diags) {
+ bool Is64bitTarget = getTriple().getArch() != llvm::Triple::x86;
for (const auto &Feature : Features) {
if (Feature[0] != '+')
continue;
@@ -324,10 +325,16 @@
} else if (Feature == "+hreset") {
HasHRESET = true;
} else if (Feature == "+amx-bf16") {
+ if (!Is64bitTarget)
+ Diags.Report(diag::err_opt_not_valid_on_target) << "-mamx-bf16";
HasAMXBF16 = true;
} else if (Feature == "+amx-int8") {
+ if (!Is64bitTarget)
+ Diags.Report(diag::err_opt_not_valid_on_target) << "-mamx-int8";
HasAMXINT8 = true;
} else if (Feature == "+amx-tile") {
+ if (!Is64bitTarget)
+ Diags.Report(diag::err_opt_not_valid_on_target) << "-mamx-tile";
HasAMXTILE = true;
} else if (Feature == "+avxvnni") {
HasAVXVNNI = true;
Index: clang/include/clang/Basic/DiagnosticCommonKinds.td
===================================================================
--- clang/include/clang/Basic/DiagnosticCommonKinds.td
+++ clang/include/clang/Basic/DiagnosticCommonKinds.td
@@ -327,6 +327,8 @@
"option '%0' cannot be specified on this target">;
def err_invalid_feature_combination : Error<
"invalid feature combination: %0">;
+def err_feature_unsupported_on_target : Error<
+ "feature '%0' is not supported for %1 architecture">;
// Source manager
def err_cannot_open_file : Error<"cannot open file '%0': %1">, DefaultFatal;
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits