mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-08 19:58:09 +02:00
nir/peephole_select: Rename are_all_move_to_phi and use a switch
Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
This commit is contained in:
parent
cc5ddd584d
commit
8cf40ed05d
1 changed files with 35 additions and 29 deletions
|
|
@ -52,36 +52,41 @@ struct peephole_select_state {
|
||||||
};
|
};
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
are_all_move_to_phi(nir_block *block)
|
block_check_for_allowed_instrs(nir_block *block)
|
||||||
{
|
{
|
||||||
nir_foreach_instr(block, instr) {
|
nir_foreach_instr(block, instr) {
|
||||||
if (instr->type != nir_instr_type_alu)
|
switch (instr->type) {
|
||||||
return false;
|
case nir_instr_type_alu: {
|
||||||
|
/* It must be a move operation */
|
||||||
/* It must be a move operation */
|
nir_alu_instr *mov = nir_instr_as_alu(instr);
|
||||||
nir_alu_instr *mov = nir_instr_as_alu(instr);
|
if (mov->op != nir_op_fmov && mov->op != nir_op_imov)
|
||||||
if (mov->op != nir_op_fmov && mov->op != nir_op_imov)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
/* Can't handle saturate */
|
|
||||||
if (mov->dest.saturate)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
/* It must be SSA */
|
|
||||||
if (!mov->dest.dest.is_ssa)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
/* It cannot have any if-uses */
|
|
||||||
if (mov->dest.dest.ssa.if_uses->entries != 0)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
/* The only uses of this definition must be phi's in the successor */
|
|
||||||
struct set_entry *entry;
|
|
||||||
set_foreach(mov->dest.dest.ssa.uses, entry) {
|
|
||||||
const nir_instr *dest_instr = entry->key;
|
|
||||||
if (dest_instr->type != nir_instr_type_phi ||
|
|
||||||
dest_instr->block != block->successors[0])
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
/* Can't handle saturate */
|
||||||
|
if (mov->dest.saturate)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
/* It must be SSA */
|
||||||
|
if (!mov->dest.dest.is_ssa)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
/* It cannot have any if-uses */
|
||||||
|
if (mov->dest.dest.ssa.if_uses->entries != 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
/* The only uses of this definition must be phi's in the successor */
|
||||||
|
struct set_entry *entry;
|
||||||
|
set_foreach(mov->dest.dest.ssa.uses, entry) {
|
||||||
|
const nir_instr *dest_instr = entry->key;
|
||||||
|
if (dest_instr->type != nir_instr_type_phi ||
|
||||||
|
dest_instr->block != block->successors[0])
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -119,8 +124,9 @@ nir_opt_peephole_select_block(nir_block *block, void *void_state)
|
||||||
nir_block *then_block = nir_cf_node_as_block(then_node);
|
nir_block *then_block = nir_cf_node_as_block(then_node);
|
||||||
nir_block *else_block = nir_cf_node_as_block(else_node);
|
nir_block *else_block = nir_cf_node_as_block(else_node);
|
||||||
|
|
||||||
/* ... and those blocks must only contain move-to-phi. */
|
/* ... and those blocks must only contain "allowed" instructions. */
|
||||||
if (!are_all_move_to_phi(then_block) || !are_all_move_to_phi(else_block))
|
if (!block_check_for_allowed_instrs(then_block) ||
|
||||||
|
!block_check_for_allowed_instrs(else_block))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
/* At this point, we know that the previous CFG node is an if-then
|
/* At this point, we know that the previous CFG node is an if-then
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue