Skip to content

Commit f363e30

Browse files
authored
[AMDGPU] Report error in clang if wave32 is requested where unsupported (#97633)
1 parent af21bc1 commit f363e30

File tree

5 files changed

+31
-16
lines changed

5 files changed

+31
-16
lines changed

clang/lib/Basic/Targets/AMDGPU.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,15 @@ bool AMDGPUTargetInfo::initFeatureMap(
187187
return false;
188188

189189
// TODO: Should move this logic into TargetParser
190-
std::string ErrorMsg;
191-
if (!insertWaveSizeFeature(CPU, getTriple(), Features, ErrorMsg)) {
192-
Diags.Report(diag::err_invalid_feature_combination) << ErrorMsg;
190+
auto HasError = insertWaveSizeFeature(CPU, getTriple(), Features);
191+
switch (HasError.first) {
192+
default:
193+
break;
194+
case llvm::AMDGPU::INVALID_FEATURE_COMBINATION:
195+
Diags.Report(diag::err_invalid_feature_combination) << HasError.second;
196+
return false;
197+
case llvm::AMDGPU::UNSUPPORTED_TARGET_FEATURE:
198+
Diags.Report(diag::err_opt_not_valid_on_target) << HasError.second;
193199
return false;
194200
}
195201

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// RUN: not %clang_cc1 -triple amdgcn -target-feature +wavefrontsize32 -target-feature +wavefrontsize64 -o /dev/null %s 2>&1 | FileCheck %s
22
// RUN: not %clang_cc1 -triple amdgcn -target-cpu gfx1103 -target-feature +wavefrontsize32 -target-feature +wavefrontsize64 -o /dev/null %s 2>&1 | FileCheck %s
3+
// RUN: not %clang_cc1 -triple amdgcn -target-cpu gfx900 -target-feature +wavefrontsize32 -o /dev/null %s 2>&1 | FileCheck %s --check-prefix=GFX9
34

45
// CHECK: error: invalid feature combination: 'wavefrontsize32' and 'wavefrontsize64' are mutually exclusive
6+
// GFX9: error: option 'wavefrontsize32' cannot be specified on this target
57

68
kernel void test() {}

clang/test/SemaOpenCL/builtins-amdgcn-error-wave32.cl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ void test_ballot_wave32(global uint* out, int a, int b) {
1212
*out = __builtin_amdgcn_ballot_w32(a == b); // expected-error {{'__builtin_amdgcn_ballot_w32' needs target feature wavefrontsize32}}
1313
}
1414

15-
// FIXME: Should error for subtargets that don't support wave32
16-
__attribute__((target("wavefrontsize32")))
15+
__attribute__((target("wavefrontsize32"))) // gfx9-error@*:* {{option 'wavefrontsize32' cannot be specified on this target}}
1716
void test_ballot_wave32_target_attr(global uint* out, int a, int b) {
1817
*out = __builtin_amdgcn_ballot_w32(a == b);
1918
}

llvm/include/llvm/TargetParser/TargetParser.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,12 @@ enum ArchFeatureKind : uint32_t {
157157
FEATURE_WGP = 1 << 9,
158158
};
159159

160+
enum FeatureError : uint32_t {
161+
NO_ERROR = 0,
162+
INVALID_FEATURE_COMBINATION,
163+
UNSUPPORTED_TARGET_FEATURE
164+
};
165+
160166
StringRef getArchFamilyNameAMDGCN(GPUKind AK);
161167

162168
StringRef getArchNameAMDGCN(GPUKind AK);
@@ -177,8 +183,9 @@ void fillAMDGPUFeatureMap(StringRef GPU, const Triple &T,
177183
StringMap<bool> &Features);
178184

179185
/// Inserts wave size feature for given GPU into features map
180-
bool insertWaveSizeFeature(StringRef GPU, const Triple &T,
181-
StringMap<bool> &Features, std::string &ErrorMsg);
186+
std::pair<FeatureError, StringRef>
187+
insertWaveSizeFeature(StringRef GPU, const Triple &T,
188+
StringMap<bool> &Features);
182189

183190
} // namespace AMDGPU
184191
} // namespace llvm

llvm/lib/TargetParser/TargetParser.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -616,18 +616,19 @@ static bool isWave32Capable(StringRef GPU, const Triple &T) {
616616
return IsWave32Capable;
617617
}
618618

619-
bool AMDGPU::insertWaveSizeFeature(StringRef GPU, const Triple &T,
620-
StringMap<bool> &Features,
621-
std::string &ErrorMsg) {
619+
std::pair<FeatureError, StringRef>
620+
AMDGPU::insertWaveSizeFeature(StringRef GPU, const Triple &T,
621+
StringMap<bool> &Features) {
622622
bool IsWave32Capable = isWave32Capable(GPU, T);
623623
const bool IsNullGPU = GPU.empty();
624-
// FIXME: Not diagnosing wavefrontsize32 on wave64 only targets.
625-
const bool HaveWave32 =
626-
(IsWave32Capable || IsNullGPU) && Features.count("wavefrontsize32");
624+
const bool HaveWave32 = Features.count("wavefrontsize32");
627625
const bool HaveWave64 = Features.count("wavefrontsize64");
628626
if (HaveWave32 && HaveWave64) {
629-
ErrorMsg = "'wavefrontsize32' and 'wavefrontsize64' are mutually exclusive";
630-
return false;
627+
return {AMDGPU::INVALID_FEATURE_COMBINATION,
628+
"'wavefrontsize32' and 'wavefrontsize64' are mutually exclusive"};
629+
}
630+
if (HaveWave32 && !IsNullGPU && !IsWave32Capable) {
631+
return {AMDGPU::UNSUPPORTED_TARGET_FEATURE, "wavefrontsize32"};
631632
}
632633
// Don't assume any wavesize with an unknown subtarget.
633634
if (!IsNullGPU) {
@@ -638,5 +639,5 @@ bool AMDGPU::insertWaveSizeFeature(StringRef GPU, const Triple &T,
638639
Features.insert(std::make_pair(DefaultWaveSizeFeature, true));
639640
}
640641
}
641-
return true;
642+
return {NO_ERROR, StringRef()};
642643
}

0 commit comments

Comments
 (0)