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

Connor Abbott cwabbott0 at gmail.com
Wed Apr 13 04:35:08 UTC 2016


Signed-off-by: Connor Abbott <cwabbott0 at gmail.com>
---
 src/compiler/nir/nir_opt_constant_folding.c | 29 ++++++++++++++---------------
 1 file changed, 14 insertions(+), 15 deletions(-)

diff --git a/src/compiler/nir/nir_opt_constant_folding.c b/src/compiler/nir/nir_opt_constant_folding.c
index e64ca36..983034b 100644
--- a/src/compiler/nir/nir_opt_constant_folding.c
+++ b/src/compiler/nir/nir_opt_constant_folding.c
@@ -173,22 +173,22 @@ constant_fold_tex_instr(nir_tex_instr *instr)
 }
 
 static bool
-constant_fold_block(nir_block *block, void *void_state)
+constant_fold_block(nir_block *block, void *mem_ctx)
 {
-   struct constant_fold_state *state = void_state;
+   bool progress = false;
 
    nir_foreach_instr_safe(block, instr) {
       switch (instr->type) {
       case nir_instr_type_alu:
-         state->progress |= constant_fold_alu_instr(nir_instr_as_alu(instr),
-                                                    state->mem_ctx);
+         progress |= constant_fold_alu_instr(nir_instr_as_alu(instr),
+                                             mem_ctx);
          break;
       case nir_instr_type_intrinsic:
-         state->progress |=
+         progress |=
             constant_fold_intrinsic_instr(nir_instr_as_intrinsic(instr));
          break;
       case nir_instr_type_tex:
-         state->progress |= constant_fold_tex_instr(nir_instr_as_tex(instr));
+         progress |= constant_fold_tex_instr(nir_instr_as_tex(instr));
          break;
       default:
          /* Don't know how to constant fold */
@@ -196,25 +196,24 @@ constant_fold_block(nir_block *block, void *void_state)
       }
    }
 
-   return true;
+   return progress;
 }
 
 static bool
 nir_opt_constant_folding_impl(nir_function_impl *impl)
 {
-   struct constant_fold_state state;
-
-   state.mem_ctx = ralloc_parent(impl);
-   state.impl = impl;
-   state.progress = false;
+   void *mem_ctx = ralloc_parent(impl);
+   bool progress = false;
 
-   nir_foreach_block(impl, constant_fold_block, &state);
+   nir_foreach_block(impl, block) {
+      progress |= constant_fold_block(block, mem_ctx);
+   }
 
-   if (state.progress)
+   if (progress)
       nir_metadata_preserve(impl, nir_metadata_block_index |
                                   nir_metadata_dominance);
 
-   return state.progress;
+   return progress;
 }
 
 bool
-- 
2.5.0



More information about the mesa-dev mailing list