[Mesa-dev] [PATCH 1/3] nir/inline: Make the rewrite_param_derefs helper work on instructions

Jason Ekstrand jason at jlekstrand.net
Wed May 25 17:53:26 UTC 2016


Now that we have the better nir_foreach_block macro, there's no reason to
use the archaic block version for everything.
---
 src/compiler/nir/nir_inline_functions.c | 53 ++++++++++++++++-----------------
 1 file changed, 25 insertions(+), 28 deletions(-)

diff --git a/src/compiler/nir/nir_inline_functions.c b/src/compiler/nir/nir_inline_functions.c
index 4641e8c..e124a77 100644
--- a/src/compiler/nir/nir_inline_functions.c
+++ b/src/compiler/nir/nir_inline_functions.c
@@ -27,40 +27,36 @@
 
 static bool inline_function_impl(nir_function_impl *impl, struct set *inlined);
 
-static bool
-rewrite_param_derefs_block(nir_block *block, nir_call_instr *call)
+static void
+rewrite_param_derefs(nir_instr *instr, nir_call_instr *call)
 {
-   nir_foreach_instr_safe(instr, block) {
-      if (instr->type != nir_instr_type_intrinsic)
-         continue;
-
-      nir_intrinsic_instr *intrin = nir_instr_as_intrinsic(instr);
+   if (instr->type != nir_instr_type_intrinsic)
+      return;
 
-      for (unsigned i = 0;
-           i < nir_intrinsic_infos[intrin->intrinsic].num_variables; i++) {
-         if (intrin->variables[i]->var->data.mode != nir_var_param)
-            continue;
+   nir_intrinsic_instr *intrin = nir_instr_as_intrinsic(instr);
 
-         int param_idx = intrin->variables[i]->var->data.location;
+   for (unsigned i = 0;
+        i < nir_intrinsic_infos[intrin->intrinsic].num_variables; i++) {
+      if (intrin->variables[i]->var->data.mode != nir_var_param)
+         continue;
 
-         nir_deref_var *call_deref;
-         if (param_idx >= 0) {
-            assert(param_idx < call->callee->num_params);
-            call_deref = call->params[param_idx];
-         } else {
-            call_deref = call->return_deref;
-         }
-         assert(call_deref);
+      int param_idx = intrin->variables[i]->var->data.location;
 
-         nir_deref_var *new_deref = nir_deref_as_var(nir_copy_deref(intrin, &call_deref->deref));
-         nir_deref *new_tail = nir_deref_tail(&new_deref->deref);
-         new_tail->child = intrin->variables[i]->deref.child;
-         ralloc_steal(new_tail, new_tail->child);
-         intrin->variables[i] = new_deref;
+      nir_deref_var *call_deref;
+      if (param_idx >= 0) {
+         assert(param_idx < call->callee->num_params);
+         call_deref = call->params[param_idx];
+      } else {
+         call_deref = call->return_deref;
       }
-   }
+      assert(call_deref);
 
-   return true;
+      nir_deref_var *new_deref = nir_deref_as_var(nir_copy_deref(intrin, &call_deref->deref));
+      nir_deref *new_tail = nir_deref_tail(&new_deref->deref);
+      new_tail->child = intrin->variables[i]->deref.child;
+      ralloc_steal(new_tail, new_tail->child);
+      intrin->variables[i] = new_deref;
+   }
 }
 
 static void
@@ -184,7 +180,8 @@ inline_functions_block(nir_block *block, nir_builder *b,
       }
 
       nir_foreach_block(block, callee_copy) {
-         rewrite_param_derefs_block(block, call);
+         nir_foreach_instr_safe(instr, block)
+            rewrite_param_derefs(instr, call);
       }
 
       /* Pluck the body out of the function and place it here */
-- 
2.5.0.400.gff86faf



More information about the mesa-dev mailing list