nir: use nir_shader_instructions_pass in nir_lower_frexp
Changes: - nir_metadata_preserve(..., nir_metadata_all) is called when pass doesn't make progress Reviewed-by: Alyssa Rosenzweig <alyssa@collabora.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12282>
This commit is contained in:

committed by
Marge Bot

parent
a87070937d
commit
dd51dedefd
@@ -163,58 +163,37 @@ lower_frexp_exp(nir_builder *b, nir_ssa_def *x)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
lower_frexp_impl(nir_function_impl *impl)
|
lower_frexp_instr(nir_builder *b, nir_instr *instr, UNUSED void *cb_data)
|
||||||
{
|
{
|
||||||
bool progress = false;
|
if (instr->type != nir_instr_type_alu)
|
||||||
|
return false;
|
||||||
|
|
||||||
nir_builder b;
|
nir_alu_instr *alu_instr = nir_instr_as_alu(instr);
|
||||||
nir_builder_init(&b, impl);
|
nir_ssa_def *lower;
|
||||||
|
|
||||||
nir_foreach_block(block, impl) {
|
b->cursor = nir_before_instr(instr);
|
||||||
nir_foreach_instr_safe(instr, block) {
|
|
||||||
if (instr->type != nir_instr_type_alu)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
nir_alu_instr *alu_instr = nir_instr_as_alu(instr);
|
switch (alu_instr->op) {
|
||||||
nir_ssa_def *lower;
|
case nir_op_frexp_sig:
|
||||||
|
lower = lower_frexp_sig(b, nir_ssa_for_alu_src(b, alu_instr, 0));
|
||||||
b.cursor = nir_before_instr(instr);
|
break;
|
||||||
|
case nir_op_frexp_exp:
|
||||||
switch (alu_instr->op) {
|
lower = lower_frexp_exp(b, nir_ssa_for_alu_src(b, alu_instr, 0));
|
||||||
case nir_op_frexp_sig:
|
break;
|
||||||
lower = lower_frexp_sig(&b, nir_ssa_for_alu_src(&b, alu_instr, 0));
|
default:
|
||||||
break;
|
return false;
|
||||||
case nir_op_frexp_exp:
|
|
||||||
lower = lower_frexp_exp(&b, nir_ssa_for_alu_src(&b, alu_instr, 0));
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
nir_ssa_def_rewrite_uses(&alu_instr->dest.dest.ssa,
|
|
||||||
lower);
|
|
||||||
nir_instr_remove(instr);
|
|
||||||
progress = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (progress) {
|
nir_ssa_def_rewrite_uses(&alu_instr->dest.dest.ssa, lower);
|
||||||
nir_metadata_preserve(impl, nir_metadata_block_index |
|
nir_instr_remove(instr);
|
||||||
nir_metadata_dominance);
|
return true;
|
||||||
}
|
|
||||||
|
|
||||||
return progress;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
nir_lower_frexp(nir_shader *shader)
|
nir_lower_frexp(nir_shader *shader)
|
||||||
{
|
{
|
||||||
bool progress = false;
|
return nir_shader_instructions_pass(shader, lower_frexp_instr,
|
||||||
|
nir_metadata_block_index |
|
||||||
nir_foreach_function(function, shader) {
|
nir_metadata_dominance,
|
||||||
if (function->impl)
|
NULL);
|
||||||
progress |= lower_frexp_impl(function->impl);
|
|
||||||
}
|
|
||||||
|
|
||||||
return progress;
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user