nir: Make some helpers for copying ALU src/dests.
authorEric Anholt <eric@anholt.net>
Wed, 21 Jan 2015 23:55:23 +0000 (15:55 -0800)
committerEric Anholt <eric@anholt.net>
Sat, 24 Jan 2015 00:37:16 +0000 (16:37 -0800)
There aren't many users yet, but I wanted to do this from my scalarizing
pass.

v2: Constify the src arguments.

Reviewed-by: Jason Ekstrand <jason.ekstrand@intel.com>
src/glsl/nir/nir.c
src/glsl/nir/nir.h
src/glsl/nir/nir_lower_vec_to_movs.c
src/glsl/nir/nir_opt_peephole_select.c

index 16ad2da945c58691b0477b422076e858680a2be4..0f9bfd947cffa38b0f1b11ad06be429fbd1aca36 100644 (file)
@@ -175,6 +175,24 @@ nir_dest nir_dest_copy(nir_dest dest, void *mem_ctx)
    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);
+   dest->abs = src->abs;
+   dest->negate = src->negate;
+   for (unsigned i = 0; i < 4; i++)
+      dest->swizzle[i] = src->swizzle[i];
+}
+
+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);
+   dest->write_mask = src->write_mask;
+   dest->saturate = src->saturate;
+}
+
 static inline void
 block_add_pred(nir_block *block, nir_block *pred)
 {
index 15f8f465f19d22ee05d329792af8f39ba7c404f4..b3e6dfab3405f116a7cce63290b248716b1d8f28 100644 (file)
@@ -569,6 +569,10 @@ typedef struct {
    unsigned write_mask : 4; /* ignored if dest.is_ssa is true */
 } nir_alu_dest;
 
+void 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);
+
 #define OPCODE(name, num_inputs, output_size, output_type, \
                input_sizes, input_types, algebraic_props) \
    nir_op_##name,
index a3120b666359f889b12b033d7b53a51ecdf2dc36..022889e8d6fd45d29a948c70f7eb36ce77f14793 100644 (file)
@@ -57,15 +57,12 @@ lower_vec_to_movs_block(nir_block *block, void *mem_ctx)
          assert(src_idx < nir_op_infos[vec->op].num_inputs);
 
          nir_alu_instr *mov = nir_alu_instr_create(mem_ctx, nir_op_imov);
-         mov->src[0].src = nir_src_copy(vec->src[src_idx].src, mem_ctx);
-         mov->src[0].negate = vec->src[src_idx].negate;
-         mov->src[0].abs = vec->src[src_idx].abs;
+         nir_alu_src_copy(&mov->src[0], &vec->src[src_idx], mem_ctx);
 
          /* We only care about the one swizzle */
          mov->src[0].swizzle[i] = vec->src[src_idx].swizzle[0];
 
-         mov->dest.dest = nir_dest_copy(vec->dest.dest, mem_ctx);
-         mov->dest.saturate = vec->dest.saturate;
+         nir_alu_dest_copy(&mov->dest, &vec->dest, mem_ctx);
          mov->dest.write_mask = (1u << i);
 
          nir_instr_insert_before(&vec->instr, &mov->instr);
index 9f541fef19d85bc2749e164a71b0dfc31f16f1a7..21bdd263bd50ac715cdff284b5080e9ec0e06293 100644 (file)
@@ -154,10 +154,7 @@ nir_opt_peephole_select_block(nir_block *block, void *void_state)
             assert(mov->instr.type == nir_instr_type_alu);
             assert(mov->op == nir_op_fmov || mov->op == nir_op_imov);
 
-            sel->src[idx].src = nir_src_copy(mov->src[0].src, state->mem_ctx);
-            sel->src[idx].negate = mov->src[0].negate;
-            sel->src[idx].abs = mov->src[0].abs;
-            memcpy(sel->src[idx].swizzle, mov->src[0].swizzle, 4);
+            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);
          }