Smaller cleanups on multi-function Private LUTs.

This commit is contained in:
Hans-Kristian Arntzen 2024-03-18 11:25:38 +01:00
parent 6ee80151e4
commit 48bede6a2a

View File

@ -3738,8 +3738,11 @@ void Compiler::find_function_local_luts(SPIRFunction &entry, const AnalyzeVariab
// First check if there are writes to the variable. Later, if there are none, we'll // First check if there are writes to the variable. Later, if there are none, we'll
// reconsider it as globally accessed LUT. // reconsider it as globally accessed LUT.
var.is_written_to |= handler.complete_write_variables_to_block.count(var.self) != 0 || if (!var.is_written_to)
handler.partial_write_variables_to_block.count(var.self) != 0; {
var.is_written_to = handler.complete_write_variables_to_block.count(var.self) != 0 ||
handler.partial_write_variables_to_block.count(var.self) != 0;
}
// Only consider function local variables here. // Only consider function local variables here.
// If we only have a single function in our CFG, private storage is also fine, // If we only have a single function in our CFG, private storage is also fine,
@ -4623,25 +4626,27 @@ void Compiler::build_function_control_flow_graphs_and_analyze()
} }
} }
// Find LUTs which are not function local. // Find LUTs which are not function local. Only consider this case if the CFG is multi-function,
for (auto id: global_variables) // otherwise we treat Private as Function trivially.
// Needs to be analyzed from the outside since we have to block the LUT optimization if at least
// one function writes to it.
if (!single_function)
{ {
auto &var = get<SPIRVariable>(id); for (auto &id : global_variables)
auto &type = get_variable_data_type(var); {
auto &var = get<SPIRVariable>(id);
auto &type = get_variable_data_type(var);
if (!is_array(type)) if (is_array(type) && var.storage == StorageClassPrivate &&
continue; var.initializer && !var.is_written_to &&
ir.ids[var.initializer].get_type() == TypeConstant)
if (var.storage != StorageClassPrivate || !var.initializer || var.is_written_to) {
continue; get<SPIRConstant>(var.initializer).is_used_as_lut = true;
var.static_expression = var.initializer;
if (ir.ids[var.initializer].get_type() != TypeConstant) var.statically_assigned = true;
continue; var.remapped_variable = true;
}
get<SPIRConstant>(var.initializer).is_used_as_lut = true; }
var.static_expression = var.initializer;
var.statically_assigned = true;
var.remapped_variable = true;
} }
} }