Removed tracking of OpConstant and OpPhi.

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 <saedo@codeweavers.com>
This commit is contained in:
Sebastián Aedo 2021-11-13 14:13:30 -03:00
parent 75e3752273
commit 5345051a85
2 changed files with 22 additions and 7 deletions

View File

@ -1628,13 +1628,31 @@ SPIRBlock::ContinueBlockType Compiler::continue_block_type(const SPIRBlock &bloc
const SmallVector<SPIRBlock::Case> &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<SPIRConstant>(block.condition))
{
SPIRV_CROSS_THROW("Use of undeclared variable on a switch statement.");
const auto &type = get<SPIRType>(constant->constant_type);
width = type.width;
}
else if (const auto *var = maybe_get<SPIRVariable>(block.condition))
{
const auto &type = get<SPIRType>(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;

View File

@ -771,8 +771,6 @@ void Parser::parse(const Instruction &instruction)
uint32_t result_type = ops[0];
uint32_t id = ops[1];
auto &type = get<SPIRType>(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<SPIRVariable>(id, result_type, spv::StorageClassFunction);
@ -791,7 +789,6 @@ void Parser::parse(const Instruction &instruction)
{
uint32_t id = ops[1];
auto &type = get<SPIRType>(ops[0]);
ir.load_type_width.insert({ id, type.width });
if (type.width > 32)
set<SPIRConstant>(id, ops[0], ops[2] | (uint64_t(ops[3]) << 32), op == OpSpecConstant);