From 5345051a8551b3fe6bc89bced15ec1a31fc4e60d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Aedo?= Date: Sat, 13 Nov 2021 14:13:30 -0300 Subject: [PATCH] Removed tracking of OpConstant and OpPhi. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We don't need to keep track of them because when the block.condition is either a SPIRConstant or a SPIRVariable, we can get the type directly in the get_case_list. Signed-off-by: Sebastián Aedo --- spirv_cross.cpp | 26 ++++++++++++++++++++++---- spirv_parser.cpp | 3 --- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/spirv_cross.cpp b/spirv_cross.cpp index 85e2a755..2b047722 100644 --- a/spirv_cross.cpp +++ b/spirv_cross.cpp @@ -1628,13 +1628,31 @@ SPIRBlock::ContinueBlockType Compiler::continue_block_type(const SPIRBlock &bloc const SmallVector &Compiler::get_case_list(const SPIRBlock &block) const { - auto search = ir.load_type_width.find(block.condition); - if (search == ir.load_type_width.end()) + uint32_t width = 0; + + // First we check if we can get the type directly from the block.condition + // since it can be a SPIRConstant or a SPIRVariable. + if (const auto *constant = maybe_get(block.condition)) { - SPIRV_CROSS_THROW("Use of undeclared variable on a switch statement."); + const auto &type = get(constant->constant_type); + width = type.width; + } + else if (const auto *var = maybe_get(block.condition)) + { + const auto &type = get(var->basetype); + width = type.width; + } + else + { + auto search = ir.load_type_width.find(block.condition); + if (search == ir.load_type_width.end()) + { + SPIRV_CROSS_THROW("Use of undeclared variable on a switch statement."); + } + + width = search->second; } - const uint32_t width = search->second; if (width > 32) return block.cases_64bit; diff --git a/spirv_parser.cpp b/spirv_parser.cpp index fc01ce25..f13e0639 100644 --- a/spirv_parser.cpp +++ b/spirv_parser.cpp @@ -771,8 +771,6 @@ void Parser::parse(const Instruction &instruction) uint32_t result_type = ops[0]; uint32_t id = ops[1]; - auto &type = get(result_type); - ir.load_type_width.insert({ id, type.width }); // Instead of a temporary, create a new function-wide temporary with this ID instead. auto &var = set(id, result_type, spv::StorageClassFunction); @@ -791,7 +789,6 @@ void Parser::parse(const Instruction &instruction) { uint32_t id = ops[1]; auto &type = get(ops[0]); - ir.load_type_width.insert({ id, type.width }); if (type.width > 32) set(id, ops[0], ops[2] | (uint64_t(ops[3]) << 32), op == OpSpecConstant);