nir: use nir_shader_instructions_pass in nir_lower_alu
authorMarcin Ślusarz <marcin.slusarz@intel.com>
Fri, 6 Aug 2021 14:47:22 +0000 (16:47 +0200)
committerMarge Bot <emma+marge@anholt.net>
Mon, 26 Sep 2022 11:13:03 +0000 (11:13 +0000)
Changes:
- nir_metadata_preserve(..., nir_metadata_all) is called when pass doesn't
  make progress
- only metadata of the current function is invalidated (invalidation on
  one function was leaking to successive functions because "progress"
  was not reset)

Reviewed-by: Alyssa Rosenzweig <alyssa@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12282>

src/compiler/nir/nir_lower_alu.c

index 68dc61a..d0cc7b5 100644 (file)
 #define LOWER_MUL_HIGH (1 << 0)
 
 static bool
-lower_alu_instr(nir_alu_instr *instr, nir_builder *b)
+lower_alu_instr(nir_builder *b, nir_instr *instr_, UNUSED void *cb_data)
 {
+   if (instr_->type != nir_instr_type_alu)
+      return false;
+
+   nir_alu_instr *instr = nir_instr_as_alu(instr_);
+
    nir_ssa_def *lowered = NULL;
 
    assert(instr->dest.dest.is_ssa);
@@ -223,33 +228,12 @@ lower_alu_instr(nir_alu_instr *instr, nir_builder *b)
 bool
 nir_lower_alu(nir_shader *shader)
 {
-   bool progress = false;
-
    if (!shader->options->lower_bitfield_reverse &&
        !shader->options->lower_mul_high)
       return false;
 
-   nir_foreach_function(function, shader) {
-      if (function->impl) {
-         nir_builder builder;
-         nir_builder_init(&builder, function->impl);
-
-         nir_foreach_block(block, function->impl) {
-            nir_foreach_instr_safe(instr, block) {
-               if (instr->type == nir_instr_type_alu) {
-                  progress = lower_alu_instr(nir_instr_as_alu(instr),
-                                             &builder) || progress;
-               }
-            }
-         }
-
-         if (progress) {
-            nir_metadata_preserve(function->impl,
-                                  nir_metadata_block_index |
-                                  nir_metadata_dominance);
-         }
-      }
-   }
-
-   return progress;
+   return nir_shader_instructions_pass(shader, lower_alu_instr,
+                                       nir_metadata_block_index |
+                                       nir_metadata_dominance,
+                                       NULL);
 }