Skip to content

Commit

Permalink
Handle unreachable block when computing register pressure (KhronosGro…
Browse files Browse the repository at this point in the history
  • Loading branch information
s-perron authored Nov 27, 2019
1 parent 868ca39 commit 5438545
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 3 deletions.
13 changes: 10 additions & 3 deletions source/opt/register_pressure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,16 @@ class ComputeRegisterLiveness {
// - Second, walk loop forest to propagate registers crossing back-edges
// (add iterative values into the liveness set).
void Compute() {
cfg_.ForEachBlockInPostOrder(&*function_->begin(), [this](BasicBlock* bb) {
ComputePartialLiveness(bb);
});
for (BasicBlock& start_bb : *function_) {
if (reg_pressure_->Get(start_bb.id()) != nullptr) {
continue;
}
cfg_.ForEachBlockInPostOrder(&start_bb, [this](BasicBlock* bb) {
if (reg_pressure_->Get(bb->id()) == nullptr) {
ComputePartialLiveness(bb);
}
});
}
DoLoopLivenessUnification();
EvaluateRegisterRequirements();
}
Expand Down
40 changes: 40 additions & 0 deletions test/opt/register_liveness.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1277,6 +1277,46 @@ TEST_F(PassClassTest, FissionSimulation) {
}
}

// Test that register liveness does not fail when there is an unreachable block.
// We are not testing if the liveness is computed correctly because the specific
// results do not matter for unreachable blocks.
TEST_F(PassClassTest, RegisterLivenessWithUnreachableBlock) {
const std::string text = R"(
OpCapability Shader
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
OpEntryPoint Fragment %2 "main"
OpExecutionMode %2 OriginLowerLeft
OpSource GLSL 330
OpSourceExtension "GL_ARB_shading_language_420pack"
%void = OpTypeVoid
%4 = OpTypeFunction %void
%2 = OpFunction %void None %4
%5 = OpLabel
OpBranch %6
%6 = OpLabel
OpLoopMerge %7 %8 None
OpBranch %9
%9 = OpLabel
OpBranch %7
%8 = OpLabel
OpBranch %6
%7 = OpLabel
OpReturn
OpFunctionEnd
)";

std::unique_ptr<IRContext> context =
BuildModule(SPV_ENV_UNIVERSAL_1_1, nullptr, text,
SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
Module* module = context->module();
EXPECT_NE(nullptr, module) << "Assembling failed for shader:\n"
<< text << std::endl;
Function* f = &*module->begin();
LivenessAnalysis* liveness_analysis = context->GetLivenessAnalysis();
liveness_analysis->Get(f);
}

} // namespace
} // namespace opt
} // namespace spvtools

0 comments on commit 5438545

Please sign in to comment.