[Mesa-dev] [PATCH 14/47] nir/lower_indirect_derefs: fixup for new foreach_block()

Connor Abbott cwabbott0 at gmail.com
Wed Apr 13 04:34:53 UTC 2016


Signed-off-by: Connor Abbott <cwabbott0 at gmail.com>
---
 src/compiler/nir/nir_lower_indirect_derefs.c | 39 ++++++++++++----------------
 1 file changed, 17 insertions(+), 22 deletions(-)

diff --git a/src/compiler/nir/nir_lower_indirect_derefs.c b/src/compiler/nir/nir_lower_indirect_derefs.c
index 62b8c84..e732986 100644
--- a/src/compiler/nir/nir_lower_indirect_derefs.c
+++ b/src/compiler/nir/nir_lower_indirect_derefs.c
@@ -159,16 +159,11 @@ deref_has_indirect(nir_deref_var *deref)
    return false;
 }
 
-struct lower_indirect_state {
-   nir_builder builder;
-   uint32_t mode_mask;
-   bool progress;
-};
-
 static bool
-lower_indirect_block(nir_block *block, void *void_state)
+lower_indirect_block(nir_block *block, nir_builder *b,
+                     uint32_t mode_mask)
 {
-   struct lower_indirect_state *state = void_state;
+   bool progress = false;
 
    nir_foreach_instr_safe(block, instr) {
       if (instr->type != nir_instr_type_intrinsic)
@@ -183,43 +178,43 @@ lower_indirect_block(nir_block *block, void *void_state)
          continue;
 
       /* Only lower variables whose mode is in the mask */
-      if (!(state->mode_mask & (1 << intrin->variables[0]->var->data.mode)))
+      if (!(mode_mask & (1 << intrin->variables[0]->var->data.mode)))
          continue;
 
-      state->builder.cursor = nir_before_instr(&intrin->instr);
+      b->cursor = nir_before_instr(&intrin->instr);
 
       if (intrin->intrinsic == nir_intrinsic_load_var) {
          nir_ssa_def *result;
-         emit_load_store(&state->builder, intrin, intrin->variables[0],
+         emit_load_store(b, intrin, intrin->variables[0],
                          &intrin->variables[0]->deref, &result, NULL);
          nir_ssa_def_rewrite_uses(&intrin->dest.ssa, nir_src_for_ssa(result));
       } else {
          assert(intrin->src[0].is_ssa);
-         emit_load_store(&state->builder, intrin, intrin->variables[0],
+         emit_load_store(b, intrin, intrin->variables[0],
                          &intrin->variables[0]->deref, NULL, intrin->src[0].ssa);
       }
       nir_instr_remove(&intrin->instr);
-      state->progress = true;
+      progress = true;
    }
 
-   return true;
+   return progress;
 }
 
 static bool
 lower_indirects_impl(nir_function_impl *impl, uint32_t mode_mask)
 {
-   struct lower_indirect_state state;
-
-   state.progress = false;
-   state.mode_mask = mode_mask;
-   nir_builder_init(&state.builder, impl);
+   nir_builder builder;
+   nir_builder_init(&builder, impl);
+   bool progress = false;
 
-   nir_foreach_block(impl, lower_indirect_block, &state);
+   nir_foreach_block(impl, block) {
+      progress |= lower_indirect_block(block, &builder, mode_mask);
+   }
 
-   if (state.progress)
+   if (progress)
       nir_metadata_preserve(impl, nir_metadata_none);
 
-   return state.progress;
+   return progress;
 }
 
 /** Lowers indirect variable loads/stores to direct loads/stores.
-- 
2.5.0



More information about the mesa-dev mailing list