Mesa (master): nir/opt_undef: Convert to use nir_shader_instructions_pass().

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Thu Aug 27 23:24:26 UTC 2020


Module: Mesa
Branch: master
Commit: dfb8465341707970e557a96f7989cfc17bba4edc
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=dfb8465341707970e557a96f7989cfc17bba4edc

Author: Eric Anholt <eric at anholt.net>
Date:   Thu Aug 20 11:56:04 2020 -0700

nir/opt_undef: Convert to use nir_shader_instructions_pass().

We can't use nir_lower_instructions because we operate on stores which
don't have an SSA def.

Reviewed-By: Mike Blumenkrantz <michael.blumenkrantz at gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6412>

---

 src/compiler/nir/nir_opt_undef.c | 50 +++++++++++++++-------------------------
 1 file changed, 19 insertions(+), 31 deletions(-)

diff --git a/src/compiler/nir/nir_opt_undef.c b/src/compiler/nir/nir_opt_undef.c
index d12354e0245..c5f8ead0234 100644
--- a/src/compiler/nir/nir_opt_undef.c
+++ b/src/compiler/nir/nir_opt_undef.c
@@ -167,38 +167,26 @@ opt_undef_store(nir_intrinsic_instr *intrin)
    return true;
 }
 
-bool
-nir_opt_undef(nir_shader *shader)
+static bool
+nir_opt_undef_instr(nir_builder *b, nir_instr *instr, void *data)
 {
-   nir_builder b;
-   bool progress = false;
-
-   nir_foreach_function(function, shader) {
-      if (function->impl) {
-         nir_builder_init(&b, function->impl);
-         nir_foreach_block(block, function->impl) {
-            nir_foreach_instr_safe(instr, block) {
-               if (instr->type == nir_instr_type_alu) {
-                  nir_alu_instr *alu = nir_instr_as_alu(instr);
-
-                  progress = opt_undef_csel(alu) || progress;
-                  progress = opt_undef_vecN(&b, alu) || progress;
-               } else if (instr->type == nir_instr_type_intrinsic) {
-                  nir_intrinsic_instr *intrin = nir_instr_as_intrinsic(instr);
-                  progress = opt_undef_store(intrin) || progress;
-               }
-            }
-         }
-
-         if (progress) {
-            nir_metadata_preserve(function->impl,
-                                  nir_metadata_block_index |
-                                  nir_metadata_dominance);
-         } else {
-            nir_metadata_preserve(function->impl, nir_metadata_all);
-         }
-      }
+   if (instr->type == nir_instr_type_alu) {
+      nir_alu_instr *alu = nir_instr_as_alu(instr);
+      return opt_undef_csel(alu) || opt_undef_vecN(b, alu);
+   } else if (instr->type == nir_instr_type_intrinsic) {
+      nir_intrinsic_instr *intrin = nir_instr_as_intrinsic(instr);
+      return opt_undef_store(intrin);
    }
 
-   return progress;
+   return false;
+}
+
+bool
+nir_opt_undef(nir_shader *shader)
+{
+   return nir_shader_instructions_pass(shader,
+                                       nir_opt_undef_instr,
+                                       nir_metadata_block_index |
+                                       nir_metadata_dominance,
+                                       NULL);
 }



More information about the mesa-commit mailing list