nir: Use pointers for nir_src_copy and nir_dest_copy
authorJason Ekstrand <jason.ekstrand@intel.com>
Sat, 24 Jan 2015 00:57:40 +0000 (16:57 -0800)
committerJason Ekstrand <jason.ekstrand@intel.com>
Mon, 26 Jan 2015 19:24:58 +0000 (11:24 -0800)
This avoids the overhead of copying structures and better matches the newly
added nir_alu_src_copy and nir_alu_dest_copy.

Reviewed-by: Eric Anholt <eric@anholt.net>
Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
src/glsl/nir/nir.c
src/glsl/nir/nir.h
src/glsl/nir/nir_from_ssa.c
src/glsl/nir/nir_lower_atomics.c
src/glsl/nir/nir_lower_io.c
src/glsl/nir/nir_lower_locals_to_regs.c
src/glsl/nir/nir_lower_samplers.cpp
src/glsl/nir/nir_lower_system_values.c
src/glsl/nir/nir_opt_peephole_select.c
src/glsl/nir/nir_search.c

index 0f9bfd947cffa38b0f1b11ad06be429fbd1aca36..25cdac0e81507b000a5c96aa4170b78d3a72cf7f 100644 (file)
@@ -135,50 +135,44 @@ nir_function_overload_create(nir_function *func)
    return overload;
 }
 
-nir_src nir_src_copy(nir_src src, void *mem_ctx)
+void nir_src_copy(nir_src *dest, const nir_src *src, void *mem_ctx)
 {
-   nir_src ret;
-   ret.is_ssa = src.is_ssa;
-   if (ret.is_ssa) {
-      ret.ssa = src.ssa;
+   dest->is_ssa = src->is_ssa;
+   if (src->is_ssa) {
+      dest->ssa = src->ssa;
    } else {
-      ret.reg.base_offset = src.reg.base_offset;
-      ret.reg.reg = src.reg.reg;
-      if (src.reg.indirect) {
-         ret.reg.indirect = ralloc(mem_ctx, nir_src);
-         *ret.reg.indirect = *src.reg.indirect;
+      dest->reg.base_offset = src->reg.base_offset;
+      dest->reg.reg = src->reg.reg;
+      if (src->reg.indirect) {
+         dest->reg.indirect = ralloc(mem_ctx, nir_src);
+         nir_src_copy(dest->reg.indirect, src->reg.indirect, mem_ctx);
       } else {
-         ret.reg.indirect = NULL;
+         dest->reg.indirect = NULL;
       }
    }
-
-   return ret;
 }
 
-nir_dest nir_dest_copy(nir_dest dest, void *mem_ctx)
+void nir_dest_copy(nir_dest *dest, const nir_dest *src, void *mem_ctx)
 {
-   nir_dest ret;
-   ret.is_ssa = dest.is_ssa;
-   if (ret.is_ssa) {
-      ret.ssa = dest.ssa;
+   dest->is_ssa = src->is_ssa;
+   if (src->is_ssa) {
+      dest->ssa = src->ssa;
    } else {
-      ret.reg.base_offset = dest.reg.base_offset;
-      ret.reg.reg = dest.reg.reg;
-      if (dest.reg.indirect) {
-         ret.reg.indirect = ralloc(mem_ctx, nir_src);
-         *ret.reg.indirect = *dest.reg.indirect;
+      dest->reg.base_offset = src->reg.base_offset;
+      dest->reg.reg = src->reg.reg;
+      if (src->reg.indirect) {
+         dest->reg.indirect = ralloc(mem_ctx, nir_src);
+         nir_src_copy(dest->reg.indirect, src->reg.indirect, mem_ctx);
       } else {
-         ret.reg.indirect = NULL;
+         dest->reg.indirect = NULL;
       }
    }
-
-   return ret;
 }
 
 void
 nir_alu_src_copy(nir_alu_src *dest, const nir_alu_src *src, void *mem_ctx)
 {
-   dest->src = nir_src_copy(src->src, mem_ctx);
+   nir_src_copy(&dest->src, &src->src, mem_ctx);
    dest->abs = src->abs;
    dest->negate = src->negate;
    for (unsigned i = 0; i < 4; i++)
@@ -188,7 +182,7 @@ nir_alu_src_copy(nir_alu_src *dest, const nir_alu_src *src, void *mem_ctx)
 void
 nir_alu_dest_copy(nir_alu_dest *dest, const nir_alu_dest *src, void *mem_ctx)
 {
-   dest->dest = nir_dest_copy(src->dest, mem_ctx);
+   nir_dest_copy(&dest->dest, &src->dest, mem_ctx);
    dest->write_mask = src->write_mask;
    dest->saturate = src->saturate;
 }
@@ -563,7 +557,7 @@ copy_deref_array(void *mem_ctx, nir_deref_array *deref)
    ret->base_offset = deref->base_offset;
    ret->deref_array_type = deref->deref_array_type;
    if (deref->deref_array_type == nir_deref_array_type_indirect) {
-      ret->indirect = nir_src_copy(deref->indirect, mem_ctx);
+      nir_src_copy(&ret->indirect, &deref->indirect, mem_ctx);
    }
    ret->deref.type = deref->deref.type;
    if (deref->deref.child)
@@ -1829,7 +1823,7 @@ ssa_def_rewrite_uses_src(nir_src *src, void *void_state)
    struct ssa_def_rewrite_state *state = void_state;
 
    if (src->is_ssa && src->ssa == state->old)
-      *src = nir_src_copy(state->new_src, state->mem_ctx);
+      nir_src_copy(src, &state->new_src, state->mem_ctx);
 
    return true;
 }
@@ -1866,7 +1860,7 @@ nir_ssa_def_rewrite_uses(nir_ssa_def *def, nir_src new_src, void *mem_ctx)
       nir_if *if_use = (nir_if *)entry->key;
 
       _mesa_set_remove(def->if_uses, entry);
-      if_use->condition = nir_src_copy(new_src, mem_ctx);
+      nir_src_copy(&if_use->condition, &new_src, mem_ctx);
       _mesa_set_add(new_if_uses, if_use);
    }
 }
index 0ef83a174c2e81ab8c2d98f94a2fc0cfa1962f07..3fb9d3b5fbe372e215af72fb0da38d30b4784bc0 100644 (file)
@@ -521,8 +521,8 @@ nir_dest_for_reg(nir_register *reg)
    return dest;
 }
 
-nir_src nir_src_copy(nir_src src, void *mem_ctx);
-nir_dest nir_dest_copy(nir_dest dest, void *mem_ctx);
+void nir_src_copy(nir_src *dest, const nir_src *src, void *mem_ctx);
+void nir_dest_copy(nir_dest *dest, const nir_dest *src, void *mem_ctx);
 
 typedef struct {
    nir_src src;
index 840177bff7ead02ee98ed8c9f2bbad077ef96fb9..2e7add38d3125d5379a80393283af3bf8a59696b 100644 (file)
@@ -352,7 +352,7 @@ isolate_phi_nodes_block(nir_block *block, void *void_state)
                                                  nir_parallel_copy_entry);
          exec_list_push_tail(&pcopy->entries, &entry->node);
 
-         entry->src = nir_src_copy(src->src, state->dead_ctx);
+         nir_src_copy(&entry->src, &src->src, state->dead_ctx);
          _mesa_set_add(src->src.ssa->uses, &pcopy->instr);
 
          nir_ssa_dest_init(&pcopy->instr, &entry->dest,
@@ -622,7 +622,7 @@ emit_copy(nir_parallel_copy_instr *pcopy, nir_src src, nir_src dest_src,
       assert(src.reg.reg->num_components >= dest_src.reg.reg->num_components);
 
    nir_alu_instr *mov = nir_alu_instr_create(mem_ctx, nir_op_imov);
-   mov->src[0].src = nir_src_copy(src, mem_ctx);
+   nir_src_copy(&mov->src[0].src, &src, mem_ctx);
    mov->dest.dest = nir_dest_for_reg(dest_src.reg.reg);
    mov->dest.write_mask = (1 << dest_src.reg.reg->num_components) - 1;
 
index ec582f306c3acf6f9d040b344cfbb18edd54c861..6ed53778e18e1029f3f4559e05a874031dda1ce7 100644 (file)
@@ -88,7 +88,7 @@ lower_instr(nir_intrinsic_instr *instr, nir_function_impl *impl)
          nir_alu_instr *mul = nir_alu_instr_create(mem_ctx, nir_op_imul);
          nir_ssa_dest_init(&mul->instr, &mul->dest.dest, 1, NULL);
          mul->dest.write_mask = 0x1;
-         mul->src[0].src = nir_src_copy(deref_array->indirect, mem_ctx);
+         nir_src_copy(&mul->src[0].src, &deref_array->indirect, mem_ctx);
          mul->src[1].src.is_ssa = true;
          mul->src[1].src.ssa = &atomic_counter_size->def;
          nir_instr_insert_before(&instr->instr, &mul->instr);
@@ -116,7 +116,7 @@ lower_instr(nir_intrinsic_instr *instr, nir_function_impl *impl)
                                nir_src_for_ssa(&new_instr->dest.ssa),
                                mem_ctx);
    } else {
-      new_instr->dest = nir_dest_copy(instr->dest, mem_ctx);
+      nir_dest_copy(&new_instr->dest, &instr->dest, mem_ctx);
    }
 
    nir_instr_insert_before(&instr->instr, &new_instr->instr);
index 8712869a0f55f321ee566d5da30fb252605af064..ddbc249371b11eec5d350a2b8c3463627e7eb12d 100644 (file)
@@ -148,8 +148,8 @@ get_io_offset(nir_deref_var *deref, nir_instr *instr, nir_src *indirect,
                                                       nir_op_imul);
             mul->src[0].src.is_ssa = true;
             mul->src[0].src.ssa = &load_const->def;
-            mul->src[1].src = nir_src_copy(deref_array->indirect,
-                                           state->mem_ctx);
+            nir_src_copy(&mul->src[1].src, &deref_array->indirect,
+                         state->mem_ctx);
             mul->dest.write_mask = 1;
             nir_ssa_dest_init(&mul->instr, &mul->dest.dest, 1, NULL);
             nir_instr_insert_before(instr, &mul->instr);
@@ -239,7 +239,7 @@ nir_lower_io_block(nir_block *block, void *void_state)
                                      nir_src_for_ssa(&load->dest.ssa),
                                      state->mem_ctx);
          } else {
-            load->dest = nir_dest_copy(intrin->dest, state->mem_ctx);
+            nir_dest_copy(&load->dest, &intrin->dest, state->mem_ctx);
          }
 
          nir_instr_insert_before(&intrin->instr, &load->instr);
@@ -272,7 +272,7 @@ nir_lower_io_block(nir_block *block, void *void_state)
          store->const_index[0] = offset;
          store->const_index[1] = 1;
 
-         store->src[0] = nir_src_copy(intrin->src[0], state->mem_ctx);
+         nir_src_copy(&store->src[0], &intrin->src[0], state->mem_ctx);
 
          if (has_indirect)
             store->src[1] = indirect;
index c04cb559239b472af977f3edc0c6ba62f30e7bf7..8c5df7be6726aec2f7cb9a6556a67fc0197e1d5d 100644 (file)
@@ -168,14 +168,14 @@ get_deref_reg_src(nir_deref_var *deref, nir_instr *instr,
       if (deref_array->deref_array_type == nir_deref_array_type_indirect) {
          if (src.reg.indirect == NULL) {
             src.reg.indirect = ralloc(state->mem_ctx, nir_src);
-            *src.reg.indirect = nir_src_copy(deref_array->indirect,
-                                             state->mem_ctx);
+            nir_src_copy(src.reg.indirect, &deref_array->indirect,
+                         state->mem_ctx);
          } else {
             nir_alu_instr *add = nir_alu_instr_create(state->mem_ctx,
                                                       nir_op_iadd);
             add->src[0].src = *src.reg.indirect;
-            add->src[1].src = nir_src_copy(deref_array->indirect,
-                                           state->mem_ctx);
+            nir_src_copy(&add->src[1].src, &deref_array->indirect,
+                         state->mem_ctx);
             add->dest.write_mask = 1;
             nir_ssa_dest_init(&add->instr, &add->dest.dest, 1, NULL);
             nir_instr_insert_before(instr, &add->instr);
@@ -216,7 +216,7 @@ lower_locals_to_regs_block(nir_block *block, void *void_state)
                                      nir_src_for_ssa(&mov->dest.dest.ssa),
                                      state->mem_ctx);
          } else {
-            mov->dest.dest = nir_dest_copy(intrin->dest, state->mem_ctx);
+            nir_dest_copy(&mov->dest.dest, &intrin->dest, state->mem_ctx);
          }
          nir_instr_insert_before(&intrin->instr, &mov->instr);
 
@@ -232,7 +232,7 @@ lower_locals_to_regs_block(nir_block *block, void *void_state)
                                              &intrin->instr, state);
 
          nir_alu_instr *mov = nir_alu_instr_create(state->mem_ctx, nir_op_imov);
-         mov->src[0].src = nir_src_copy(intrin->src[0], state->mem_ctx);
+         nir_src_copy(&mov->src[0].src, &intrin->src[0], state->mem_ctx);
          mov->dest.write_mask = (1 << intrin->num_components) - 1;
          mov->dest.dest.is_ssa = false;
          mov->dest.dest.reg.reg = reg_src.reg.reg;
index 99f31fc028197176eef96cd6d09bcd86549f7022..dca086d709e8286fc88a7254ab79832e68fbd628 100644 (file)
@@ -102,7 +102,7 @@ lower_sampler(nir_tex_instr *instr, struct gl_shader_program *shader_program,
 
             nir_instr_rewrite_src(&instr->instr,
                                   &instr->src[instr->num_srcs - 1].src,
-                                  nir_src_copy(deref_array->indirect, mem_ctx));
+                                  deref_array->indirect);
 
             instr->sampler_array_size = glsl_get_length(deref->type);
 
index dc12f406e7c54877c45dfe2756535518f469e213..90346c975c1faf3eb4adbb8c339fd4b167b2b333 100644 (file)
@@ -76,7 +76,7 @@ convert_instr(nir_intrinsic_instr *instr)
                                nir_src_for_ssa(&new_instr->dest.ssa),
                                mem_ctx);
    } else {
-      new_instr->dest = nir_dest_copy(instr->dest, mem_ctx);
+      nir_dest_copy(&new_instr->dest, &instr->dest, mem_ctx);
    }
 
    nir_instr_insert_before(&instr->instr, &new_instr->instr);
index 21bdd263bd50ac715cdff284b5080e9ec0e06293..ab08f286f7eee79e4ad5d751bc3c43eec4b20633 100644 (file)
@@ -135,7 +135,7 @@ nir_opt_peephole_select_block(nir_block *block, void *void_state)
 
       nir_phi_instr *phi = nir_instr_as_phi(instr);
       nir_alu_instr *sel = nir_alu_instr_create(state->mem_ctx, nir_op_bcsel);
-      sel->src[0].src = nir_src_copy(if_stmt->condition, state->mem_ctx);
+      nir_src_copy(&sel->src[0].src, &if_stmt->condition, state->mem_ctx);
       /* Splat the condition to all channels */
       memset(sel->src[0].swizzle, 0, sizeof sel->src[0].swizzle);
 
@@ -156,7 +156,7 @@ nir_opt_peephole_select_block(nir_block *block, void *void_state)
 
             nir_alu_src_copy(&sel->src[idx], &mov->src[0], state->mem_ctx);
          } else {
-            sel->src[idx].src = nir_src_copy(src->src, state->mem_ctx);
+            nir_src_copy(&sel->src[idx].src, &src->src, state->mem_ctx);
          }
       }
 
index 7ef22e89ab5e76a6769451816ea37afdebef6f0f..18e0330e4aeb852ef56c03b6e8d6bc8f6398a0da 100644 (file)
@@ -233,8 +233,8 @@ construct_value(const nir_search_value *value, nir_alu_type type,
       const nir_search_variable *var = nir_search_value_as_variable(value);
       assert(state->variables_seen & (1 << var->variable));
 
-      nir_alu_src val = state->variables[var->variable];
-      val.src = nir_src_copy(val.src, mem_ctx);
+      nir_alu_src val;
+      nir_alu_src_copy(&val, &state->variables[var->variable], mem_ctx);
 
       return val;
    }