[Mesa-dev] [PATCH v3 016/104] nir: Use nir_builder in lower_io_to_temporaries

Jason Ekstrand jason at jlekstrand.net
Tue Apr 3 18:32:43 UTC 2018


---
 src/compiler/nir/nir_lower_io_to_temporaries.c | 37 ++++++++++++--------------
 1 file changed, 17 insertions(+), 20 deletions(-)

diff --git a/src/compiler/nir/nir_lower_io_to_temporaries.c b/src/compiler/nir/nir_lower_io_to_temporaries.c
index 301ba65..9d3072b 100644
--- a/src/compiler/nir/nir_lower_io_to_temporaries.c
+++ b/src/compiler/nir/nir_lower_io_to_temporaries.c
@@ -31,6 +31,7 @@
  */
 
 #include "nir.h"
+#include "nir_builder.h"
 
 struct lower_io_state {
    nir_shader *shader;
@@ -40,8 +41,8 @@ struct lower_io_state {
 };
 
 static void
-emit_copies(nir_cursor cursor, nir_shader *shader, struct exec_list *new_vars,
-          struct exec_list *old_vars)
+emit_copies(nir_builder *b, struct exec_list *new_vars,
+            struct exec_list *old_vars)
 {
    assert(exec_list_length(new_vars) == exec_list_length(old_vars));
 
@@ -64,18 +65,16 @@ emit_copies(nir_cursor cursor, nir_shader *shader, struct exec_list *new_vars,
       if (newv->data.read_only)
          continue;
 
-      nir_intrinsic_instr *copy =
-         nir_intrinsic_instr_create(shader, nir_intrinsic_copy_var);
-      copy->variables[0] = nir_deref_var_create(copy, newv);
-      copy->variables[1] = nir_deref_var_create(copy, temp);
-
-      nir_instr_insert(cursor, &copy->instr);
+      nir_copy_var(b, newv, temp);
    }
 }
 
 static void
 emit_output_copies_impl(struct lower_io_state *state, nir_function_impl *impl)
 {
+   nir_builder b;
+   nir_builder_init(&b, impl);
+
    if (state->shader->info.stage == MESA_SHADER_GEOMETRY) {
       /* For geometry shaders, we have to emit the output copies right
        * before each EmitVertex call.
@@ -87,16 +86,14 @@ emit_output_copies_impl(struct lower_io_state *state, nir_function_impl *impl)
 
             nir_intrinsic_instr *intrin = nir_instr_as_intrinsic(instr);
             if (intrin->intrinsic == nir_intrinsic_emit_vertex) {
-               nir_cursor cursor = nir_before_instr(&intrin->instr);
-               emit_copies(cursor, state->shader, &state->shader->outputs,
-                           &state->old_outputs);
+               b.cursor = nir_before_instr(&intrin->instr);
+               emit_copies(&b, &state->shader->outputs, &state->old_outputs);
             }
          }
       }
    } else if (impl == state->entrypoint) {
-      nir_cursor cursor = nir_before_block(nir_start_block(impl));
-      emit_copies(cursor, state->shader, &state->old_outputs,
-                  &state->shader->outputs);
+      b.cursor = nir_before_block(nir_start_block(impl));
+      emit_copies(&b, &state->old_outputs, &state->shader->outputs);
 
       /* For all other shader types, we need to do the copies right before
        * the jumps to the end block.
@@ -104,9 +101,8 @@ emit_output_copies_impl(struct lower_io_state *state, nir_function_impl *impl)
       struct set_entry *block_entry;
       set_foreach(impl->end_block->predecessors, block_entry) {
          struct nir_block *block = (void *)block_entry->key;
-         nir_cursor cursor = nir_after_block_before_jump(block);
-         emit_copies(cursor, state->shader, &state->shader->outputs,
-                     &state->old_outputs);
+         b.cursor = nir_after_block_before_jump(block);
+         emit_copies(&b, &state->shader->outputs, &state->old_outputs);
       }
    }
 }
@@ -115,9 +111,10 @@ static void
 emit_input_copies_impl(struct lower_io_state *state, nir_function_impl *impl)
 {
    if (impl == state->entrypoint) {
-      nir_cursor cursor = nir_before_block(nir_start_block(impl));
-      emit_copies(cursor, state->shader, &state->old_inputs,
-                  &state->shader->inputs);
+      nir_builder b;
+      nir_builder_init(&b, impl);
+      b.cursor = nir_before_block(nir_start_block(impl));
+      emit_copies(&b, &state->old_inputs, &state->shader->inputs);
    }
 }
 
-- 
2.5.0.400.gff86faf



More information about the mesa-dev mailing list