mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2025-12-29 12:20:10 +01:00
nir: convert nir_opt_idiv_const to nir_shader_instructions_pass
Reviewed-by: Jason Ekstrand <jason.ekstrand@collabora.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/19881>
This commit is contained in:
parent
e83c01919f
commit
c2695dac5a
1 changed files with 21 additions and 48 deletions
|
|
@ -148,11 +148,27 @@ build_imod(nir_builder *b, nir_ssa_def *n, int64_t d)
|
|||
}
|
||||
|
||||
static bool
|
||||
nir_opt_idiv_const_instr(nir_builder *b, nir_alu_instr *alu)
|
||||
nir_opt_idiv_const_instr(nir_builder *b, nir_instr *instr, void *user_data)
|
||||
{
|
||||
unsigned *min_bit_size = user_data;
|
||||
|
||||
if (instr->type != nir_instr_type_alu)
|
||||
return false;
|
||||
|
||||
nir_alu_instr *alu = nir_instr_as_alu(instr);
|
||||
if (alu->op != nir_op_udiv &&
|
||||
alu->op != nir_op_idiv &&
|
||||
alu->op != nir_op_umod &&
|
||||
alu->op != nir_op_imod &&
|
||||
alu->op != nir_op_irem)
|
||||
return false;
|
||||
|
||||
assert(alu->dest.dest.is_ssa);
|
||||
assert(alu->src[0].src.is_ssa && alu->src[1].src.is_ssa);
|
||||
|
||||
if (alu->dest.dest.ssa.bit_size < *min_bit_size)
|
||||
return false;
|
||||
|
||||
if (!nir_src_is_const(alu->src[1].src))
|
||||
return false;
|
||||
|
||||
|
|
@ -208,54 +224,11 @@ nir_opt_idiv_const_instr(nir_builder *b, nir_alu_instr *alu)
|
|||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
nir_opt_idiv_const_impl(nir_function_impl *impl, unsigned min_bit_size)
|
||||
{
|
||||
bool progress = false;
|
||||
|
||||
nir_builder b;
|
||||
nir_builder_init(&b, impl);
|
||||
|
||||
nir_foreach_block(block, impl) {
|
||||
nir_foreach_instr_safe(instr, block) {
|
||||
if (instr->type != nir_instr_type_alu)
|
||||
continue;
|
||||
|
||||
nir_alu_instr *alu = nir_instr_as_alu(instr);
|
||||
if (alu->op != nir_op_udiv &&
|
||||
alu->op != nir_op_idiv &&
|
||||
alu->op != nir_op_umod &&
|
||||
alu->op != nir_op_imod &&
|
||||
alu->op != nir_op_irem)
|
||||
continue;
|
||||
|
||||
assert(alu->dest.dest.is_ssa);
|
||||
if (alu->dest.dest.ssa.bit_size < min_bit_size)
|
||||
continue;
|
||||
|
||||
progress |= nir_opt_idiv_const_instr(&b, alu);
|
||||
}
|
||||
}
|
||||
|
||||
if (progress) {
|
||||
nir_metadata_preserve(impl, nir_metadata_block_index |
|
||||
nir_metadata_dominance);
|
||||
} else {
|
||||
nir_metadata_preserve(impl, nir_metadata_all);
|
||||
}
|
||||
|
||||
return progress;
|
||||
}
|
||||
|
||||
bool
|
||||
nir_opt_idiv_const(nir_shader *shader, unsigned min_bit_size)
|
||||
{
|
||||
bool progress = false;
|
||||
|
||||
nir_foreach_function(function, shader) {
|
||||
if (function->impl)
|
||||
progress |= nir_opt_idiv_const_impl(function->impl, min_bit_size);
|
||||
}
|
||||
|
||||
return progress;
|
||||
return nir_shader_instructions_pass(shader, nir_opt_idiv_const_instr,
|
||||
nir_metadata_block_index |
|
||||
nir_metadata_dominance,
|
||||
&min_bit_size);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue