opt: add Int64 capability to trim pass (#5398)

Adds support for Int64 capability trimming.
This commit is contained in:
Nathan Gauër 2023-09-05 15:47:46 +02:00 committed by GitHub
parent 3cc7e1c4c3
commit 1121c23198
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 54 additions and 2 deletions

View File

@ -40,6 +40,7 @@ constexpr uint32_t kOpTypePointerStorageClassIndex = 0;
constexpr uint32_t kTypeArrayTypeIndex = 0;
constexpr uint32_t kOpTypeScalarBitWidthIndex = 0;
constexpr uint32_t kTypePointerTypeIdInIdx = 1;
constexpr uint32_t kOpTypeIntSizeIndex = 0;
// DFS visit of the type defined by `instruction`.
// If `condition` is true, children of the current node are visited.
@ -255,13 +256,24 @@ static std::optional<spv::Capability> Handler_OpTypePointer_StorageUniform16(
: std::nullopt;
}
static std::optional<spv::Capability> Handler_OpTypeInt_Int64(
const Instruction* instruction) {
assert(instruction->opcode() == spv::Op::OpTypeInt &&
"This handler only support OpTypeInt opcodes.");
const uint32_t size =
instruction->GetSingleWordInOperand(kOpTypeIntSizeIndex);
return size == 64 ? std::optional(spv::Capability::Int64) : std::nullopt;
}
// Opcode of interest to determine capabilities requirements.
constexpr std::array<std::pair<spv::Op, OpcodeHandler>, 4> kOpcodeHandlers{{
constexpr std::array<std::pair<spv::Op, OpcodeHandler>, 5> kOpcodeHandlers{{
// clang-format off
{spv::Op::OpTypePointer, Handler_OpTypePointer_StorageInputOutput16},
{spv::Op::OpTypePointer, Handler_OpTypePointer_StoragePushConstant16},
{spv::Op::OpTypePointer, Handler_OpTypePointer_StorageUniformBufferBlock16},
{spv::Op::OpTypePointer, Handler_OpTypePointer_StorageUniform16}
{spv::Op::OpTypePointer, Handler_OpTypePointer_StorageUniform16},
{spv::Op::OpTypeInt, Handler_OpTypeInt_Int64 },
// clang-format on
}};

View File

@ -78,6 +78,7 @@ class TrimCapabilitiesPass : public Pass {
spv::Capability::FragmentShaderSampleInterlockEXT,
spv::Capability::FragmentShaderShadingRateInterlockEXT,
spv::Capability::Groups,
spv::Capability::Int64,
spv::Capability::Linkage,
spv::Capability::MinLod,
spv::Capability::Shader,

View File

@ -1591,6 +1591,45 @@ TEST_F(TrimCapabilitiesPassTest,
EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithChange);
}
TEST_F(TrimCapabilitiesPassTest, Int64_RemovedWhenUnused) {
const std::string kTest = R"(
OpCapability Int64
; CHECK-NOT: OpCapability Int64
OpCapability Shader
OpMemoryModel Logical GLSL450
OpEntryPoint GLCompute %1 "main"
%void = OpTypeVoid
%3 = OpTypeFunction %void
%1 = OpFunction %void None %3
%6 = OpLabel
OpReturn
OpFunctionEnd;
)";
const auto result =
SinglePassRunAndMatch<TrimCapabilitiesPass>(kTest, /* skip_nop= */ false);
EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithChange);
}
TEST_F(TrimCapabilitiesPassTest, Int64_RemainsWhenUsed) {
const std::string kTest = R"(
OpCapability Int64
; CHECK: OpCapability Int64
OpCapability Shader
OpMemoryModel Logical GLSL450
OpEntryPoint GLCompute %1 "main"
%void = OpTypeVoid
%int = OpTypeInt 64 0
%3 = OpTypeFunction %void
%1 = OpFunction %void None %3
%6 = OpLabel
OpReturn
OpFunctionEnd;
)";
const auto result =
SinglePassRunAndMatch<TrimCapabilitiesPass>(kTest, /* skip_nop= */ false);
EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithoutChange);
}
} // namespace
} // namespace opt
} // namespace spvtools