[clang] [llvm] [AMDGPU] Report error in clang if wave32 is requested where unsupported (PR #97633)
Stanislav Mekhanoshin via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 9 11:37:31 PDT 2024
https://github.com/rampitec updated https://github.com/llvm/llvm-project/pull/97633
>From dc9d1e2039981bb412e68975570d9911511bb880 Mon Sep 17 00:00:00 2001
From: Stanislav Mekhanoshin <Stanislav.Mekhanoshin at amd.com>
Date: Wed, 3 Jul 2024 13:12:21 -0700
Subject: [PATCH 1/2] [AMDGPU] Report error in clang if wave32 is requested
where unsupported
---
clang/lib/Basic/Targets/AMDGPU.cpp | 8 ++++++--
clang/test/CodeGenOpenCL/amdgpu-features-illegal.cl | 2 ++
.../test/SemaOpenCL/builtins-amdgcn-error-wave32.cl | 3 +--
llvm/include/llvm/TargetParser/TargetParser.h | 3 ++-
llvm/lib/TargetParser/TargetParser.cpp | 13 +++++++++----
5 files changed, 20 insertions(+), 9 deletions(-)
diff --git a/clang/lib/Basic/Targets/AMDGPU.cpp b/clang/lib/Basic/Targets/AMDGPU.cpp
index cc7be64656e5b..ea20acdb930fa 100644
--- a/clang/lib/Basic/Targets/AMDGPU.cpp
+++ b/clang/lib/Basic/Targets/AMDGPU.cpp
@@ -188,8 +188,12 @@ bool AMDGPUTargetInfo::initFeatureMap(
// TODO: Should move this logic into TargetParser
std::string ErrorMsg;
- if (!insertWaveSizeFeature(CPU, getTriple(), Features, ErrorMsg)) {
- Diags.Report(diag::err_invalid_feature_combination) << ErrorMsg;
+ bool IsCombinationError;
+ if (!insertWaveSizeFeature(CPU, getTriple(), Features, ErrorMsg,
+ IsCombinationError)) {
+ Diags.Report(IsCombinationError ? diag::err_invalid_feature_combination
+ : diag::err_opt_not_valid_on_target)
+ << ErrorMsg;
return false;
}
diff --git a/clang/test/CodeGenOpenCL/amdgpu-features-illegal.cl b/clang/test/CodeGenOpenCL/amdgpu-features-illegal.cl
index 7dbf5c3c6cd59..4e2f7f86e8402 100644
--- a/clang/test/CodeGenOpenCL/amdgpu-features-illegal.cl
+++ b/clang/test/CodeGenOpenCL/amdgpu-features-illegal.cl
@@ -1,6 +1,8 @@
// RUN: not %clang_cc1 -triple amdgcn -target-feature +wavefrontsize32 -target-feature +wavefrontsize64 -o /dev/null %s 2>&1 | FileCheck %s
// RUN: not %clang_cc1 -triple amdgcn -target-cpu gfx1103 -target-feature +wavefrontsize32 -target-feature +wavefrontsize64 -o /dev/null %s 2>&1 | FileCheck %s
+// RUN: not %clang_cc1 -triple amdgcn -target-cpu gfx900 -target-feature +wavefrontsize32 -o /dev/null %s 2>&1 | FileCheck %s --check-prefix=GFX9
// CHECK: error: invalid feature combination: 'wavefrontsize32' and 'wavefrontsize64' are mutually exclusive
+// GFX9: error: option 'wavefrontsize32' cannot be specified on this target
kernel void test() {}
diff --git a/clang/test/SemaOpenCL/builtins-amdgcn-error-wave32.cl b/clang/test/SemaOpenCL/builtins-amdgcn-error-wave32.cl
index 52f31c1ff0575..e0e3872b566d9 100644
--- a/clang/test/SemaOpenCL/builtins-amdgcn-error-wave32.cl
+++ b/clang/test/SemaOpenCL/builtins-amdgcn-error-wave32.cl
@@ -12,8 +12,7 @@ void test_ballot_wave32(global uint* out, int a, int b) {
*out = __builtin_amdgcn_ballot_w32(a == b); // expected-error {{'__builtin_amdgcn_ballot_w32' needs target feature wavefrontsize32}}
}
-// FIXME: Should error for subtargets that don't support wave32
-__attribute__((target("wavefrontsize32")))
+__attribute__((target("wavefrontsize32"))) // gfx9-error@*:* {{option 'wavefrontsize32' cannot be specified on this target}}
void test_ballot_wave32_target_attr(global uint* out, int a, int b) {
*out = __builtin_amdgcn_ballot_w32(a == b);
}
diff --git a/llvm/include/llvm/TargetParser/TargetParser.h b/llvm/include/llvm/TargetParser/TargetParser.h
index e03d8f6eebfca..858a1fdc01b37 100644
--- a/llvm/include/llvm/TargetParser/TargetParser.h
+++ b/llvm/include/llvm/TargetParser/TargetParser.h
@@ -178,7 +178,8 @@ void fillAMDGPUFeatureMap(StringRef GPU, const Triple &T,
/// Inserts wave size feature for given GPU into features map
bool insertWaveSizeFeature(StringRef GPU, const Triple &T,
- StringMap<bool> &Features, std::string &ErrorMsg);
+ StringMap<bool> &Features, std::string &ErrorMsg,
+ bool &IsCombinationError);
} // namespace AMDGPU
} // namespace llvm
diff --git a/llvm/lib/TargetParser/TargetParser.cpp b/llvm/lib/TargetParser/TargetParser.cpp
index 00df92e0aaded..4bcd966183c67 100644
--- a/llvm/lib/TargetParser/TargetParser.cpp
+++ b/llvm/lib/TargetParser/TargetParser.cpp
@@ -618,15 +618,20 @@ static bool isWave32Capable(StringRef GPU, const Triple &T) {
bool AMDGPU::insertWaveSizeFeature(StringRef GPU, const Triple &T,
StringMap<bool> &Features,
- std::string &ErrorMsg) {
+ std::string &ErrorMsg,
+ bool &IsCombinationError) {
bool IsWave32Capable = isWave32Capable(GPU, T);
const bool IsNullGPU = GPU.empty();
- // FIXME: Not diagnosing wavefrontsize32 on wave64 only targets.
- const bool HaveWave32 =
- (IsWave32Capable || IsNullGPU) && Features.count("wavefrontsize32");
+ const bool HaveWave32 = Features.count("wavefrontsize32");
const bool HaveWave64 = Features.count("wavefrontsize64");
if (HaveWave32 && HaveWave64) {
ErrorMsg = "'wavefrontsize32' and 'wavefrontsize64' are mutually exclusive";
+ IsCombinationError = true;
+ return false;
+ }
+ if (HaveWave32 && !IsNullGPU && !IsWave32Capable) {
+ ErrorMsg = "wavefrontsize32";
+ IsCombinationError = false;
return false;
}
// Don't assume any wavesize with an unknown subtarget.
>From ced7def14582ddd599f883c27b2470cb5688ce8c Mon Sep 17 00:00:00 2001
From: Stanislav Mekhanoshin <Stanislav.Mekhanoshin at amd.com>
Date: Tue, 9 Jul 2024 11:37:01 -0700
Subject: [PATCH 2/2] Changed return type of insertWaveSizeFeature()
---
clang/lib/Basic/Targets/AMDGPU.cpp | 16 +++++++++-------
llvm/include/llvm/TargetParser/TargetParser.h | 13 ++++++++++---
llvm/lib/TargetParser/TargetParser.cpp | 18 +++++++-----------
3 files changed, 26 insertions(+), 21 deletions(-)
diff --git a/clang/lib/Basic/Targets/AMDGPU.cpp b/clang/lib/Basic/Targets/AMDGPU.cpp
index ea20acdb930fa..3b748d0249d57 100644
--- a/clang/lib/Basic/Targets/AMDGPU.cpp
+++ b/clang/lib/Basic/Targets/AMDGPU.cpp
@@ -187,13 +187,15 @@ bool AMDGPUTargetInfo::initFeatureMap(
return false;
// TODO: Should move this logic into TargetParser
- std::string ErrorMsg;
- bool IsCombinationError;
- if (!insertWaveSizeFeature(CPU, getTriple(), Features, ErrorMsg,
- IsCombinationError)) {
- Diags.Report(IsCombinationError ? diag::err_invalid_feature_combination
- : diag::err_opt_not_valid_on_target)
- << ErrorMsg;
+ auto HasError = insertWaveSizeFeature(CPU, getTriple(), Features);
+ switch (HasError.first) {
+ default:
+ break;
+ case llvm::AMDGPU::INVALID_FEATURE_COMBINATION:
+ Diags.Report(diag::err_invalid_feature_combination) << HasError.second;
+ return false;
+ case llvm::AMDGPU::UNSUPPORTED_TARGET_FEATURE:
+ Diags.Report(diag::err_opt_not_valid_on_target) << HasError.second;
return false;
}
diff --git a/llvm/include/llvm/TargetParser/TargetParser.h b/llvm/include/llvm/TargetParser/TargetParser.h
index 858a1fdc01b37..22041fa51258e 100644
--- a/llvm/include/llvm/TargetParser/TargetParser.h
+++ b/llvm/include/llvm/TargetParser/TargetParser.h
@@ -157,6 +157,13 @@ enum ArchFeatureKind : uint32_t {
FEATURE_WGP = 1 << 9,
};
+
+enum FeatureError : uint32_t {
+ NO_ERROR = 0,
+ INVALID_FEATURE_COMBINATION,
+ UNSUPPORTED_TARGET_FEATURE
+};
+
StringRef getArchFamilyNameAMDGCN(GPUKind AK);
StringRef getArchNameAMDGCN(GPUKind AK);
@@ -177,9 +184,9 @@ void fillAMDGPUFeatureMap(StringRef GPU, const Triple &T,
StringMap<bool> &Features);
/// Inserts wave size feature for given GPU into features map
-bool insertWaveSizeFeature(StringRef GPU, const Triple &T,
- StringMap<bool> &Features, std::string &ErrorMsg,
- bool &IsCombinationError);
+std::pair<FeatureError, StringRef>
+insertWaveSizeFeature(StringRef GPU, const Triple &T,
+ StringMap<bool> &Features);
} // namespace AMDGPU
} // namespace llvm
diff --git a/llvm/lib/TargetParser/TargetParser.cpp b/llvm/lib/TargetParser/TargetParser.cpp
index 4bcd966183c67..cd48575f143a6 100644
--- a/llvm/lib/TargetParser/TargetParser.cpp
+++ b/llvm/lib/TargetParser/TargetParser.cpp
@@ -616,23 +616,19 @@ static bool isWave32Capable(StringRef GPU, const Triple &T) {
return IsWave32Capable;
}
-bool AMDGPU::insertWaveSizeFeature(StringRef GPU, const Triple &T,
- StringMap<bool> &Features,
- std::string &ErrorMsg,
- bool &IsCombinationError) {
+std::pair<FeatureError, StringRef>
+AMDGPU::insertWaveSizeFeature(StringRef GPU, const Triple &T,
+ StringMap<bool> &Features) {
bool IsWave32Capable = isWave32Capable(GPU, T);
const bool IsNullGPU = GPU.empty();
const bool HaveWave32 = Features.count("wavefrontsize32");
const bool HaveWave64 = Features.count("wavefrontsize64");
if (HaveWave32 && HaveWave64) {
- ErrorMsg = "'wavefrontsize32' and 'wavefrontsize64' are mutually exclusive";
- IsCombinationError = true;
- return false;
+ return {AMDGPU::INVALID_FEATURE_COMBINATION,
+ "'wavefrontsize32' and 'wavefrontsize64' are mutually exclusive"};
}
if (HaveWave32 && !IsNullGPU && !IsWave32Capable) {
- ErrorMsg = "wavefrontsize32";
- IsCombinationError = false;
- return false;
+ return {AMDGPU::UNSUPPORTED_TARGET_FEATURE, "wavefrontsize32"};
}
// Don't assume any wavesize with an unknown subtarget.
if (!IsNullGPU) {
@@ -643,5 +639,5 @@ bool AMDGPU::insertWaveSizeFeature(StringRef GPU, const Triple &T,
Features.insert(std::make_pair(DefaultWaveSizeFeature, true));
}
}
- return true;
+ return {NO_ERROR, StringRef()};
}
More information about the llvm-commits
mailing list