Module: Mesa
Branch: main
Commit: 97c79cdf19d63e8dad59c29cf12cae234739b4a2
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=97c79cdf19d63e8dad59c29cf12cae234739b4a2

Author: Caio Oliveira <[email protected]>
Date:   Tue Jul 18 11:55:01 2023 -0700

nir: Use instructions_pass() for nir_fixup_deref_modes()

Reviewed-by: Faith Ekstrand <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24220>

---

 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 0ffc40beee8..03c272888fe 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

Reply via email to