Skip to content

Commit 2b079c9

Browse files
committed
Update CodeGenOpt unit tests
There is a flag-day change around CodeGen enums in llvm/llvm-project#66295. Changes were made in GPUOpen-Drivers#2770 but some unit tests were missed.
1 parent 1d10129 commit 2b079c9

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

lgc/unittests/interface/OptLevelTest.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,15 @@ TEST(LgcInterfaceTests, DefaultOptLevel) {
4141
unsigned palAbiVersion = 0xFFFFFFFF;
4242
StringRef gpuName = "gfx802";
4343

44+
#if LLVM_MAIN_REVISION && LLVM_MAIN_REVISION < 474768
45+
// Old version of the code
4446
for (auto optLevel : {Level::None, Level::Less, Level::Default, Level::Aggressive}) {
47+
#else
48+
// New version of the code (also handles unknown version, which we treat as latest)
49+
// Returns the optimization level for the context.
50+
for (auto optLevel :
51+
{CodeGenOptLevel::None, CodeGenOptLevel::Less, CodeGenOptLevel::Default, CodeGenOptLevel::Aggressive}) {
52+
#endif
4553
std::unique_ptr<TargetMachine> targetMachine = LgcContext::createTargetMachine(gpuName, optLevel);
4654
std::unique_ptr<LgcContext> lgcContext(LgcContext::create(&*targetMachine, context, palAbiVersion));
4755
EXPECT_EQ(lgcContext->getOptimizationLevel(), optLevel);

llpc/unittests/context/testOptLevel.cpp

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,31 +50,61 @@ TEST(LlpcContextTests, MatchPipelineOptLevel) {
5050

5151
Context *context = new Context(GfxIp);
5252

53+
#if LLVM_MAIN_REVISION && LLVM_MAIN_REVISION < 474768
54+
// Old version of the code
5355
for (auto optLevel : {Level::None, Level::Less, Level::Default, Level::Aggressive}) {
56+
#else
57+
// New version of the code (also handles unknown version, which we treat as latest)
58+
// Returns the optimization level for the context.
59+
for (auto optLevel :
60+
{CodeGenOptLevel::None, CodeGenOptLevel::Less, CodeGenOptLevel::Default, CodeGenOptLevel::Aggressive}) {
61+
#endif
5462
GraphicsPipelineBuildInfo pipelineInfo = {};
55-
pipelineInfo.options.optimizationLevel = optLevel;
63+
pipelineInfo.options.optimizationLevel = static_cast<uint32_t>(optLevel);
5664

5765
GraphicsContext graphicsContext(GfxIp, &pipelineInfo, &pipelineHash, &cacheHash);
5866

5967
context->attachPipelineContext(&graphicsContext);
6068

69+
#if LLVM_MAIN_REVISION && LLVM_MAIN_REVISION < 474768
70+
// Old version of the code
6171
if (optLevel == Level::None) {
72+
#else
73+
// New version of the code (also handles unknown version, which we treat as latest)
74+
// Returns the optimization level for the context.
75+
if (optLevel == CodeGenOptLevel::None) {
76+
#endif
6277
// None might not be possible, so accept >= Level::None
6378
EXPECT_GE(context->getLgcContext()->getOptimizationLevel(), optLevel);
6479
} else {
6580
EXPECT_EQ(context->getLgcContext()->getOptimizationLevel(), optLevel);
6681
}
6782
}
6883

84+
#if LLVM_MAIN_REVISION && LLVM_MAIN_REVISION < 474768
85+
// Old version of the code
6986
for (auto optLevel : {Level::None, Level::Less, Level::Default, Level::Aggressive}) {
87+
#else
88+
// New version of the code (also handles unknown version, which we treat as latest)
89+
// Returns the optimization level for the context.
90+
for (auto optLevel :
91+
{CodeGenOptLevel::None, CodeGenOptLevel::Less, CodeGenOptLevel::Default, CodeGenOptLevel::Aggressive}) {
92+
#endif
7093
ComputePipelineBuildInfo pipelineInfo = {};
71-
pipelineInfo.options.optimizationLevel = optLevel;
94+
pipelineInfo.options.optimizationLevel = static_cast<uint32_t>(optLevel);
7295

7396
ComputeContext computeContext(GfxIp, &pipelineInfo, &pipelineHash, &cacheHash);
7497

7598
context->attachPipelineContext(&computeContext);
7699

100+
#if LLVM_MAIN_REVISION && LLVM_MAIN_REVISION < 474768
101+
// Old version of the code
77102
if (optLevel == Level::None) {
103+
#else
104+
// New version of the code (also handles unknown version, which we treat as latest)
105+
// Returns the optimization level for the context.
106+
if (optLevel == CodeGenOptLevel::None) {
107+
#endif
78108
// None might not be possible, so accept >= Level::None
79109
EXPECT_GE(context->getLgcContext()->getOptimizationLevel(), optLevel);
80110
} else {

0 commit comments

Comments
 (0)