From 97c79cdf19d63e8dad59c29cf12cae234739b4a2 Mon Sep 17 00:00:00 2001 From: Caio Oliveira Date: Tue, 18 Jul 2023 11:55:01 -0700 Subject: [PATCH] nir: Use instructions_pass() for nir_fixup_deref_modes() Reviewed-by: Faith Ekstrand Part-of: --- src/compiler/nir/nir_deref.c | 54 +++++++++++++++++++++++++------------------- 1 file changed, 31 insertions(+), 23 deletions(-) diff --git a/src/compiler/nir/nir_deref.c b/src/compiler/nir/nir_deref.c index 0ffc40b..03c2728 100644 --- a/src/compiler/nir/nir_deref.c +++ b/src/compiler/nir/nir_deref.c @@ -414,33 +414,41 @@ nir_remove_dead_derefs(nir_shader *shader) return progress; } -void -nir_fixup_deref_modes(nir_shader *shader) +static bool +nir_fixup_deref_modes_instr(UNUSED struct nir_builder *b, nir_instr *instr, UNUSED void *data) { - nir_foreach_function_impl(impl, shader) { - nir_foreach_block(block, impl) { - nir_foreach_instr(instr, block) { - if (instr->type != nir_instr_type_deref) - continue; - - nir_deref_instr *deref = nir_instr_as_deref(instr); - if (deref->deref_type == nir_deref_type_cast) - continue; + if (instr->type != nir_instr_type_deref) + return false; - nir_variable_mode parent_modes; - if (deref->deref_type == nir_deref_type_var) { - parent_modes = deref->var->data.mode; - } else { - assert(deref->parent.is_ssa); - nir_deref_instr *parent = - nir_instr_as_deref(deref->parent.ssa->parent_instr); - parent_modes = parent->modes; - } + nir_deref_instr *deref = nir_instr_as_deref(instr); + if (deref->deref_type == nir_deref_type_cast) + return false; - deref->modes = parent_modes; - } - } + nir_variable_mode parent_modes; + if (deref->deref_type == nir_deref_type_var) { + parent_modes = deref->var->data.mode; + } else { + assert(deref->parent.is_ssa); + nir_deref_instr *parent = + nir_instr_as_deref(deref->parent.ssa->parent_instr); + parent_modes = parent->modes; } + + if (deref->modes == parent_modes) + return false; + + deref->modes = parent_modes; + return true; +} + +void +nir_fixup_deref_modes(nir_shader *shader) +{ + nir_shader_instructions_pass(shader, nir_fixup_deref_modes_instr, + nir_metadata_block_index | + nir_metadata_dominance | + nir_metadata_live_ssa_defs | + nir_metadata_instr_index, NULL); } static bool -- 2.7.4