nir/builder: Merge nir_[if]mov_alu into one nir_mov_alu helper
authorJason Ekstrand <jason@jlekstrand.net>
Mon, 6 May 2019 16:26:27 +0000 (11:26 -0500)
committerJason Ekstrand <jason@jlekstrand.net>
Fri, 24 May 2019 13:38:11 +0000 (08:38 -0500)
Unless source modifiers are present, fmov and imov are the same.
There's no good reason for having two helpers.

Reviewed-by: Kristian H. Kristensen <hoegsberg@google.com>
Acked-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
src/compiler/nir/nir_builder.h
src/compiler/nir/nir_lower_double_ops.c
src/compiler/nir/nir_opt_remove_phis.c
src/compiler/nir/nir_search.c
src/gallium/auxiliary/nir/tgsi_to_nir.c
src/mesa/program/prog_to_nir.c

index 68cf886fa1c9fe44114b22b036763c3af90bddfe..e14151ab7b56e0fb61775db8f31c189076f8875c 100644 (file)
@@ -492,26 +492,10 @@ nir_vec(nir_builder *build, nir_ssa_def **comp, unsigned num_components)
    return nir_build_alu_src_arr(build, nir_op_vec(num_components), comp);
 }
 
-/**
- * Similar to nir_fmov, but takes a nir_alu_src instead of a nir_ssa_def.
- */
-static inline nir_ssa_def *
-nir_fmov_alu(nir_builder *build, nir_alu_src src, unsigned num_components)
-{
-   nir_alu_instr *mov = nir_alu_instr_create(build->shader, nir_op_fmov);
-   nir_ssa_dest_init(&mov->instr, &mov->dest.dest, num_components,
-                     nir_src_bit_size(src.src), NULL);
-   mov->exact = build->exact;
-   mov->dest.write_mask = (1 << num_components) - 1;
-   mov->src[0] = src;
-   nir_builder_instr_insert(build, &mov->instr);
-
-   return &mov->dest.dest.ssa;
-}
-
 static inline nir_ssa_def *
-nir_imov_alu(nir_builder *build, nir_alu_src src, unsigned num_components)
+nir_mov_alu(nir_builder *build, nir_alu_src src, unsigned num_components)
 {
+   assert(!src.abs && !src.negate);
    nir_alu_instr *mov = nir_alu_instr_create(build->shader, nir_op_imov);
    nir_ssa_dest_init(&mov->instr, &mov->dest.dest, num_components,
                      nir_src_bit_size(src.src), NULL);
@@ -544,7 +528,7 @@ nir_swizzle(nir_builder *build, nir_ssa_def *src, const unsigned *swiz,
    if (num_components == src->num_components && is_identity_swizzle)
       return src;
 
-   return nir_imov_alu(build, alu_src, num_components);
+   return nir_mov_alu(build, alu_src, num_components);
 }
 
 /* Selects the right fdot given the number of components in each source. */
@@ -838,7 +822,7 @@ nir_ssa_for_src(nir_builder *build, nir_src src, int num_components)
    for (int j = 0; j < 4; j++)
       alu.swizzle[j] = j;
 
-   return nir_imov_alu(build, alu, num_components);
+   return nir_mov_alu(build, alu, num_components);
 }
 
 /**
@@ -859,7 +843,7 @@ nir_ssa_for_alu_src(nir_builder *build, nir_alu_instr *instr, unsigned srcn)
        (memcmp(src->swizzle, trivial_swizzle, num_components) == 0))
       return src->src.ssa;
 
-   return nir_imov_alu(build, *src, num_components);
+   return nir_mov_alu(build, *src, num_components);
 }
 
 static inline unsigned
index 04ec2a82801ff1b613c7808d31b3802e66828489..4ddd91f9054e9f06319950b007ce1be97202da16 100644 (file)
@@ -581,7 +581,7 @@ lower_doubles_instr_to_soft(nir_builder *b, nir_alu_instr *instr,
    assert(nir_op_infos[instr->op].num_inputs + 1 == func->num_params);
    for (unsigned i = 0; i < nir_op_infos[instr->op].num_inputs; i++) {
       assert(i + 1 < ARRAY_SIZE(params));
-      params[i + 1] = nir_imov_alu(b, instr->src[i], 1);
+      params[i + 1] = nir_mov_alu(b, instr->src[i], 1);
    }
 
    nir_inline_function_impl(b, func->impl, params);
@@ -633,8 +633,8 @@ lower_doubles_instr(nir_builder *b, nir_alu_instr *instr,
 
    b->cursor = nir_before_instr(&instr->instr);
 
-   nir_ssa_def *src = nir_fmov_alu(b, instr->src[0],
-                                   instr->dest.dest.ssa.num_components);
+   nir_ssa_def *src = nir_mov_alu(b, instr->src[0],
+                                  instr->dest.dest.ssa.num_components);
 
    nir_ssa_def *result;
 
@@ -665,8 +665,8 @@ lower_doubles_instr(nir_builder *b, nir_alu_instr *instr,
       break;
 
    case nir_op_fmod: {
-      nir_ssa_def *src1 = nir_fmov_alu(b, instr->src[1],
-                                       instr->dest.dest.ssa.num_components);
+      nir_ssa_def *src1 = nir_mov_alu(b, instr->src[1],
+                                      instr->dest.dest.ssa.num_components);
       result = lower_mod(b, src, src1);
    }
       break;
index 9efbf422624f10540f38dbb67ec615a1f278ecaa..3643112d976323ff3cd2c0c02fb0600d950d305a 100644 (file)
@@ -124,9 +124,7 @@ remove_phis_block(nir_block *block, nir_builder *b)
           */
 
          b->cursor = nir_after_phis(block);
-         def = mov->op == nir_op_imov ?
-            nir_imov_alu(b, mov->src[0], def->num_components) :
-            nir_fmov_alu(b, mov->src[0], def->num_components);
+         def = nir_mov_alu(b, mov->src[0], def->num_components);
       }
 
       assert(phi->dest.is_ssa);
index 4838825d7b4d73f021e20a50491bbba4fd26fe92..b8bedaa2013466c3c7e60adec0bc13355b96b740 100644 (file)
@@ -669,7 +669,7 @@ nir_replace_instr(nir_builder *build, nir_alu_instr *instr,
     * and rewrite swizzles ourselves.
     */
    nir_ssa_def *ssa_val =
-      nir_imov_alu(build, val, instr->dest.dest.ssa.num_components);
+      nir_mov_alu(build, val, instr->dest.dest.ssa.num_components);
    nir_ssa_def_rewrite_uses(&instr->dest.dest.ssa, nir_src_for_ssa(ssa_val));
 
    /* We know this one has no more uses because we just rewrote them all,
index aae741118403eb9e4a7246bf3b2bf63f93c315e1..94d863d6815a53d48db578dbf983f832c6b8b33a 100644 (file)
@@ -177,7 +177,7 @@ ttn_src_for_dest(nir_builder *b, nir_alu_dest *dest)
    for (int i = 0; i < 4; i++)
       src.swizzle[i] = i;
 
-   return nir_fmov_alu(b, src, 4);
+   return nir_mov_alu(b, src, 4);
 }
 
 static enum glsl_interp_mode
@@ -681,7 +681,7 @@ ttn_src_for_indirect(struct ttn_compile *c, struct tgsi_ind_register *indirect)
                                         indirect->File,
                                         indirect->Index,
                                         NULL, NULL, NULL);
-   return nir_imov_alu(b, src, 1);
+   return nir_mov_alu(b, src, 1);
 }
 
 static nir_alu_dest
@@ -793,7 +793,7 @@ ttn_get_src(struct ttn_compile *c, struct tgsi_full_src_register *tgsi_fsrc,
    src.swizzle[2] = tgsi_src->SwizzleZ;
    src.swizzle[3] = tgsi_src->SwizzleW;
 
-   nir_ssa_def *def = nir_fmov_alu(b, src, 4);
+   nir_ssa_def *def = nir_mov_alu(b, src, 4);
 
    if (tgsi_src->Absolute) {
       if (src_is_float)
@@ -1446,7 +1446,7 @@ ttn_tex(struct ttn_compile *c, nir_alu_dest dest, nir_ssa_def **src)
 
       instr->src[src_number].src_type = nir_tex_src_offset;
       instr->src[src_number].src = nir_src_for_ssa(
-         nir_fmov_alu(b, src, nir_tex_instr_src_size(instr, src_number)));
+         nir_mov_alu(b, src, nir_tex_instr_src_size(instr, src_number)));
       src_number++;
    }
 
index 36e9b689b6b54c747df8362bcaabf66513c2c389..9e45181beed134c287add9cb4e02fc03d2f7bdf4 100644 (file)
@@ -83,7 +83,7 @@ ptn_src_for_dest(struct ptn_compile *c, nir_alu_dest *dest)
    for (int i = 0; i < 4; i++)
       src.swizzle[i] = i;
 
-   return nir_fmov_alu(b, src, 4);
+   return nir_mov_alu(b, src, 4);
 }
 
 static nir_alu_dest
@@ -205,7 +205,7 @@ ptn_get_src(struct ptn_compile *c, const struct prog_src_register *prog_src)
       for (int i = 0; i < 4; i++)
          src.swizzle[i] = GET_SWZ(prog_src->Swizzle, i);
 
-      def = nir_fmov_alu(b, src, 4);
+      def = nir_mov_alu(b, src, 4);
 
       if (prog_src->Negate)
          def = nir_fneg(b, def);