Skip to content

Commit

Permalink
Update CodeGenOpt unit tests (#2734)
Browse files Browse the repository at this point in the history
There is a flag-day change around CodeGen enums in llvm/llvm-project#66295.

Changes were made in #2707 but some
unit tests were missed.
  • Loading branch information
dstutt authored Sep 28, 2023
1 parent 51863d9 commit 6ca60f4
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
8 changes: 8 additions & 0 deletions lgc/unittests/interface/OptLevelTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,15 @@ TEST(LgcInterfaceTests, DefaultOptLevel) {
unsigned palAbiVersion = 0xFFFFFFFF;
StringRef gpuName = "gfx802";

#if LLVM_MAIN_REVISION && LLVM_MAIN_REVISION < 474768
// Old version of the code
for (auto optLevel : {Level::None, Level::Less, Level::Default, Level::Aggressive}) {
#else
// New version of the code (also handles unknown version, which we treat as latest)
// Returns the optimization level for the context.
for (auto optLevel :
{CodeGenOptLevel::None, CodeGenOptLevel::Less, CodeGenOptLevel::Default, CodeGenOptLevel::Aggressive}) {
#endif
std::unique_ptr<TargetMachine> targetMachine = LgcContext::createTargetMachine(gpuName, optLevel);
std::unique_ptr<LgcContext> lgcContext(LgcContext::create(&*targetMachine, context, palAbiVersion));
EXPECT_EQ(lgcContext->getOptimizationLevel(), optLevel);
Expand Down
34 changes: 32 additions & 2 deletions llpc/unittests/context/testOptLevel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,31 +50,61 @@ TEST(LlpcContextTests, MatchPipelineOptLevel) {

Context *context = new Context(GfxIp);

#if LLVM_MAIN_REVISION && LLVM_MAIN_REVISION < 474768
// Old version of the code
for (auto optLevel : {Level::None, Level::Less, Level::Default, Level::Aggressive}) {
#else
// New version of the code (also handles unknown version, which we treat as latest)
// Returns the optimization level for the context.
for (auto optLevel :
{CodeGenOptLevel::None, CodeGenOptLevel::Less, CodeGenOptLevel::Default, CodeGenOptLevel::Aggressive}) {
#endif
GraphicsPipelineBuildInfo pipelineInfo = {};
pipelineInfo.options.optimizationLevel = optLevel;
pipelineInfo.options.optimizationLevel = static_cast<uint32_t>(optLevel);

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

context->attachPipelineContext(&graphicsContext);

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

#if LLVM_MAIN_REVISION && LLVM_MAIN_REVISION < 474768
// Old version of the code
for (auto optLevel : {Level::None, Level::Less, Level::Default, Level::Aggressive}) {
#else
// New version of the code (also handles unknown version, which we treat as latest)
// Returns the optimization level for the context.
for (auto optLevel :
{CodeGenOptLevel::None, CodeGenOptLevel::Less, CodeGenOptLevel::Default, CodeGenOptLevel::Aggressive}) {
#endif
ComputePipelineBuildInfo pipelineInfo = {};
pipelineInfo.options.optimizationLevel = optLevel;
pipelineInfo.options.optimizationLevel = static_cast<uint32_t>(optLevel);

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

context->attachPipelineContext(&computeContext);

#if LLVM_MAIN_REVISION && LLVM_MAIN_REVISION < 474768
// Old version of the code
if (optLevel == Level::None) {
#else
// New version of the code (also handles unknown version, which we treat as latest)
// Returns the optimization level for the context.
if (optLevel == CodeGenOptLevel::None) {
#endif
// None might not be possible, so accept >= Level::None
EXPECT_GE(context->getLgcContext()->getOptimizationLevel(), optLevel);
} else {
Expand Down

0 comments on commit 6ca60f4

Please sign in to comment.