nir: Add a pass for fixing deref modes
authorJason Ekstrand <jason.ekstrand@intel.com>
Thu, 15 Mar 2018 22:37:50 +0000 (15:37 -0700)
committerJason Ekstrand <jason.ekstrand@intel.com>
Sat, 23 Jun 2018 03:15:54 +0000 (20:15 -0700)
This will be needed by anything which changes variable modes without
rewriting derefs.

Reviewed-by: Caio Marcelo de Oliveira Filho <caio.oliveira@intel.com>
Acked-by: Rob Clark <robdclark@gmail.com>
Acked-by: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Acked-by: Dave Airlie <airlied@redhat.com>
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
src/compiler/nir/nir.h
src/compiler/nir/nir_deref.c

index 0b9508623342ac1dd57d73434e2db4dfeb870a1e..3ba2ddfeb02393fdcf396b42b05fbfd319ad1578 100644 (file)
@@ -2701,6 +2701,8 @@ bool nir_lower_deref_instrs(nir_shader *shader,
 void nir_lower_var_copy_instr(nir_intrinsic_instr *copy, nir_shader *shader);
 bool nir_lower_var_copies(nir_shader *shader);
 
+void nir_fixup_deref_modes(nir_shader *shader);
+
 bool nir_lower_global_vars_to_local(nir_shader *shader);
 
 bool nir_lower_indirect_derefs(nir_shader *shader, nir_variable_mode modes);
index d7b4bbcdcd683c93471201bd629c2e53356b532c..762b21833cf0aae8e59982ea3edb0de7ab2c2eae 100644 (file)
@@ -354,3 +354,33 @@ nir_lower_deref_instrs(nir_shader *shader,
 
    return progress;
 }
+
+void
+nir_fixup_deref_modes(nir_shader *shader)
+{
+   nir_foreach_function(function, shader) {
+      if (!function->impl)
+         continue;
+
+      nir_foreach_block(block, function->impl) {
+         nir_foreach_instr(instr, block) {
+            if (instr->type != nir_instr_type_deref)
+               continue;
+
+            nir_deref_instr *deref = nir_instr_as_deref(instr);
+
+            nir_variable_mode parent_mode;
+            if (deref->deref_type == nir_deref_type_var) {
+               parent_mode = deref->var->data.mode;
+            } else {
+               assert(deref->parent.is_ssa);
+               nir_deref_instr *parent =
+                  nir_instr_as_deref(deref->parent.ssa->parent_instr);
+               parent_mode = parent->mode;
+            }
+
+            deref->mode = parent_mode;
+         }
+      }
+   }
+}