Skip to content

Commit 53697a5

Browse files
authored
[AMDGPU] Refactor unit test. NFC (#82976)
I'm about to add more tests here (downstream for now). Change-Id: Ibd5edb398f544c90e6e8b5e49b1777a407f0594a
1 parent 73f11f9 commit 53697a5

File tree

1 file changed

+22
-13
lines changed

1 file changed

+22
-13
lines changed

llvm/unittests/Target/AMDGPU/AMDGPUUnitTests.cpp

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,23 @@ static const std::pair<StringRef, StringRef>
9292
W32FS = {"+wavefrontsize32", "w32"},
9393
W64FS = {"+wavefrontsize64", "w64"};
9494

95-
static void testGPRLimits(
96-
const char *RegName, bool TestW32W64,
97-
std::function<bool(std::stringstream &, unsigned, GCNSubtarget &)> test) {
95+
using TestFuncTy =
96+
function_ref<bool(std::stringstream &, unsigned, const GCNSubtarget &)>;
97+
98+
static bool testAndRecord(std::stringstream &Table, const GCNSubtarget &ST,
99+
TestFuncTy test) {
100+
bool Success = true;
101+
unsigned MaxOcc = ST.getMaxWavesPerEU();
102+
for (unsigned Occ = MaxOcc; Occ > 0; --Occ) {
103+
Table << std::right << std::setw(3) << Occ << " ";
104+
Success = test(Table, Occ, ST) && Success;
105+
Table << '\n';
106+
}
107+
return Success;
108+
}
109+
110+
static void testGPRLimits(const char *RegName, bool TestW32W64,
111+
TestFuncTy test) {
98112
SmallVector<StringRef> CPUs;
99113
AMDGPU::fillValidArchListAMDGCN(CPUs);
100114

@@ -117,13 +131,7 @@ static void testGPRLimits(
117131
FS = &W32FS;
118132

119133
std::stringstream Table;
120-
bool Success = true;
121-
unsigned MaxOcc = ST.getMaxWavesPerEU();
122-
for (unsigned Occ = MaxOcc; Occ > 0; --Occ) {
123-
Table << std::right << std::setw(3) << Occ << " ";
124-
Success = test(Table, Occ, ST) && Success;
125-
Table << '\n';
126-
}
134+
bool Success = testAndRecord(Table, ST, test);
127135
if (!Success || PrintCpuRegLimits)
128136
TablePerCPUs[Table.str()].push_back((CanonCPUName + FS->second).str());
129137

@@ -145,13 +153,14 @@ static void testGPRLimits(
145153
}
146154

147155
TEST(AMDGPU, TestVGPRLimitsPerOccupancy) {
148-
testGPRLimits("VGPR", true, [](std::stringstream &OS, unsigned Occ,
149-
GCNSubtarget &ST) {
156+
auto test = [](std::stringstream &OS, unsigned Occ, const GCNSubtarget &ST) {
150157
unsigned MaxVGPRNum = ST.getAddressableNumVGPRs();
151158
return checkMinMax(
152159
OS, Occ, ST.getOccupancyWithNumVGPRs(MaxVGPRNum), ST.getMaxWavesPerEU(),
153160
[&](unsigned NumGPRs) { return ST.getOccupancyWithNumVGPRs(NumGPRs); },
154161
[&](unsigned Occ) { return ST.getMinNumVGPRs(Occ); },
155162
[&](unsigned Occ) { return ST.getMaxNumVGPRs(Occ); });
156-
});
163+
};
164+
165+
testGPRLimits("VGPR", true, test);
157166
}

0 commit comments

Comments
 (0)