nir: Stop using designated initializers
authorJason Ekstrand <jason.ekstrand@intel.com>
Wed, 21 Jan 2015 19:11:03 +0000 (11:11 -0800)
committerJason Ekstrand <jason.ekstrand@intel.com>
Thu, 22 Jan 2015 03:55:02 +0000 (19:55 -0800)
Designated initializers with anonymous unions don't work in MSVC or
GCC < 4.6.  With a couple of constructor methods, we don't need them any
more and the code is actually cleaner.

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=88467
Reviewed-by: Connor Abbot <cwabbott0@gmail.com>
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_system_values.c
src/glsl/nir/nir_lower_vars_to_ssa.c
src/glsl/nir/nir_opt_constant_folding.c
src/glsl/nir/nir_opt_cse.c
src/glsl/nir/nir_opt_peephole_select.c
src/glsl/nir/nir_search.c

index 9728b9980cce2faac7631102d879b791c45b5fc2..8b8f0f5ac758dc327e0f79ba2024b1301620cfa9 100644 (file)
@@ -382,12 +382,9 @@ isolate_phi_nodes_block(nir_block *block, void *void_state)
       entry->dest.is_ssa = true;
       nir_ssa_def_init(&block_pcopy->instr, &entry->dest.ssa,
                        phi->dest.ssa.num_components, phi->dest.ssa.name);
-
-      nir_src entry_dest_src = {
-         .ssa = &entry->dest.ssa,
-         .is_ssa = true,
-      };
-      nir_ssa_def_rewrite_uses(&phi->dest.ssa, entry_dest_src, state->mem_ctx);
+      nir_ssa_def_rewrite_uses(&phi->dest.ssa,
+                               nir_src_for_ssa(&entry->dest.ssa),
+                               state->mem_ctx);
 
       entry->src.is_ssa = true;
       entry->src.ssa = &phi->dest.ssa;
@@ -620,22 +617,16 @@ emit_copy(nir_parallel_copy_instr *pcopy, nir_src src, nir_src dest_src,
    assert(!dest_src.is_ssa &&
           dest_src.reg.indirect == NULL &&
           dest_src.reg.base_offset == 0);
-   nir_dest dest = {
-      .reg.reg = dest_src.reg.reg,
-      .reg.indirect = NULL,
-      .reg.base_offset = 0,
-      .is_ssa = false,
-   };
 
    if (src.is_ssa)
-      assert(src.ssa->num_components >= dest.reg.reg->num_components);
+      assert(src.ssa->num_components >= dest_src.reg.reg->num_components);
    else
-      assert(src.reg.reg->num_components >= dest.reg.reg->num_components);
+      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);
-   mov->dest.dest = nir_dest_copy(dest, mem_ctx);
-   mov->dest.write_mask = (1 << dest.reg.reg->num_components) - 1;
+   mov->dest.dest = nir_dest_for_reg(dest_src.reg.reg);
+   mov->dest.write_mask = (1 << dest_src.reg.reg->num_components) - 1;
 
    nir_instr_insert_before(&pcopy->instr, &mov->instr);
 }
@@ -720,12 +711,7 @@ resolve_parallel_copy(nir_parallel_copy_instr *pcopy,
          values[src_idx] = entry->src;
       }
 
-      nir_src dest_src = {
-         .reg.reg = entry->dest.reg.reg,
-         .reg.indirect = NULL,
-         .reg.base_offset = 0,
-         .is_ssa = false,
-      };
+      nir_src dest_src = nir_src_for_reg(entry->dest.reg.reg);
 
       int dest_idx = -1;
       for (int i = 0; i < num_vals; ++i) {
index 874c5347634f4976ecce48a45b69a74da1180885..c45b397afba8355f113bfaf023fd836c372c086f 100644 (file)
@@ -115,11 +115,9 @@ lower_instr(nir_intrinsic_instr *instr, nir_function_impl *impl)
       new_instr->dest.is_ssa = true;
       nir_ssa_def_init(&new_instr->instr, &new_instr->dest.ssa,
                        instr->dest.ssa.num_components, NULL);
-      nir_src new_dest_src = {
-         .is_ssa = true,
-         .ssa = &new_instr->dest.ssa,
-      };
-      nir_ssa_def_rewrite_uses(&instr->dest.ssa, new_dest_src, mem_ctx);
+      nir_ssa_def_rewrite_uses(&instr->dest.ssa,
+                               nir_src_for_ssa(&new_instr->dest.ssa),
+                               mem_ctx);
    } else {
       new_instr->dest = nir_dest_copy(instr->dest, mem_ctx);
    }
index af87c13e17a6a5d0a54ca7e0ee3cfb41ffc5e0f7..c35058c14dcf9ae71f404cac3c562a537f4b21db 100644 (file)
@@ -238,13 +238,8 @@ nir_lower_io_block(nir_block *block, void *void_state)
             load->dest.is_ssa = true;
             nir_ssa_def_init(&load->instr, &load->dest.ssa,
                              intrin->num_components, NULL);
-
-            nir_src new_src = {
-               .is_ssa = true,
-               .ssa = &load->dest.ssa,
-            };
-
-            nir_ssa_def_rewrite_uses(&intrin->dest.ssa, new_src,
+            nir_ssa_def_rewrite_uses(&intrin->dest.ssa,
+                                     nir_src_for_ssa(&load->dest.ssa),
                                      state->mem_ctx);
          } else {
             load->dest = nir_dest_copy(intrin->dest, state->mem_ctx);
index b187541405a0a284757ff291f0edb8fee82de928..f50533f95753d72187fa3bc436c8b3ff0b1b6594 100644 (file)
@@ -215,13 +215,8 @@ lower_locals_to_regs_block(nir_block *block, void *void_state)
             mov->dest.dest.is_ssa = true;
             nir_ssa_def_init(&mov->instr, &mov->dest.dest.ssa,
                              intrin->num_components, NULL);
-
-            nir_src new_src = {
-               .is_ssa = true,
-               .ssa = &mov->dest.dest.ssa,
-            };
-
-            nir_ssa_def_rewrite_uses(&intrin->dest.ssa, new_src,
+            nir_ssa_def_rewrite_uses(&intrin->dest.ssa,
+                                     nir_src_for_ssa(&mov->dest.dest.ssa),
                                      state->mem_ctx);
          } else {
             mov->dest.dest = nir_dest_copy(intrin->dest, state->mem_ctx);
index d1b4d26e2aeca88f83d39fce7b58054e7ad910b5..f681a6ce9344ea353ff673e607507618373f6b7f 100644 (file)
@@ -74,11 +74,9 @@ convert_instr(nir_intrinsic_instr *instr)
       new_instr->dest.is_ssa = true;
       nir_ssa_def_init(&new_instr->instr, &new_instr->dest.ssa,
                        instr->dest.ssa.num_components, NULL);
-      nir_src new_dest_src = {
-         .is_ssa = true,
-         .ssa = &new_instr->dest.ssa,
-      };
-      nir_ssa_def_rewrite_uses(&instr->dest.ssa, new_dest_src, mem_ctx);
+      nir_ssa_def_rewrite_uses(&instr->dest.ssa,
+                               nir_src_for_ssa(&new_instr->dest.ssa),
+                               mem_ctx);
    } else {
       new_instr->dest = nir_dest_copy(instr->dest, mem_ctx);
    }
index 4df9bdd88973449b80c838a20dd19f4f8e2809e5..061dbce1782adab9ae276cb42b082dafb915f5f2 100644 (file)
@@ -765,12 +765,8 @@ rename_variables_block(nir_block *block, struct lower_variables_state *state)
                nir_instr_insert_before(&intrin->instr, &undef->instr);
                nir_instr_remove(&intrin->instr);
 
-               nir_src new_src = {
-                  .is_ssa = true,
-                  .ssa = &undef->def,
-               };
-
-               nir_ssa_def_rewrite_uses(&intrin->dest.ssa, new_src,
+               nir_ssa_def_rewrite_uses(&intrin->dest.ssa,
+                                        nir_src_for_ssa(&undef->def),
                                         state->mem_ctx);
                continue;
             }
@@ -795,12 +791,8 @@ rename_variables_block(nir_block *block, struct lower_variables_state *state)
             nir_instr_insert_before(&intrin->instr, &mov->instr);
             nir_instr_remove(&intrin->instr);
 
-            nir_src new_src = {
-               .is_ssa = true,
-               .ssa = &mov->dest.dest.ssa,
-            };
-
-            nir_ssa_def_rewrite_uses(&intrin->dest.ssa, new_src,
+            nir_ssa_def_rewrite_uses(&intrin->dest.ssa,
+                                     nir_src_for_ssa(&mov->dest.dest.ssa),
                                      state->mem_ctx);
             break;
          }
index 6c02582ed01ef0da0e52a9777276e288c50cb64f..878436b5252589ded37570df2de11c4da0f7bada 100644 (file)
@@ -216,12 +216,8 @@ constant_fold_alu_instr(nir_alu_instr *instr, void *mem_ctx)
 
    nir_instr_insert_before(&instr->instr, &dest->instr);
 
-   nir_src new_src = {
-      .is_ssa = true,
-      .ssa = &dest->def,
-   };
-
-   nir_ssa_def_rewrite_uses(&instr->dest.dest.ssa, new_src, mem_ctx);
+   nir_ssa_def_rewrite_uses(&instr->dest.dest.ssa, nir_src_for_ssa(&dest->def),
+                            mem_ctx);
 
    nir_instr_remove(&instr->instr);
    ralloc_free(instr);
@@ -248,12 +244,8 @@ constant_fold_deref(nir_instr *instr, nir_deref_var *deref)
 
          arr->base_offset += indirect->value.u[0];
 
-         nir_src empty = {
-            .is_ssa = true,
-            .ssa = NULL,
-         };
-
-         nir_instr_rewrite_src(instr, &arr->indirect, empty);
+         /* Clear out the source */
+         nir_instr_rewrite_src(instr, &arr->indirect, nir_src_for_ssa(NULL));
 
          arr->deref_array_type = nir_deref_array_type_direct;
 
index 89d78c8d34e483d224ab38a3a9a5d7fea791c87b..a33ebdd9981c2ea6f53b75acf4db7becbd85403c 100644 (file)
@@ -187,12 +187,10 @@ nir_opt_cse_instr(nir_instr *instr, struct cse_state *state)
         !exec_node_is_head_sentinel(node); node = node->prev) {
       nir_instr *other = exec_node_data(nir_instr, node, node);
       if (nir_instrs_equal(instr, other)) {
-         nir_src other_dest_src = {
-            .is_ssa = true,
-            .ssa = nir_instr_get_dest_ssa_def(other),
-         };
+         nir_ssa_def *other_def = nir_instr_get_dest_ssa_def(other);
          nir_ssa_def_rewrite_uses(nir_instr_get_dest_ssa_def(instr),
-                                  other_dest_src, state->mem_ctx);
+                                  nir_src_for_ssa(other_def),
+                                  state->mem_ctx);
          nir_instr_remove(instr);
          state->progress = true;
          return;
@@ -203,12 +201,10 @@ nir_opt_cse_instr(nir_instr *instr, struct cse_state *state)
         block != NULL; block = block->imm_dom) {
       nir_foreach_instr_reverse(block, other) {
          if (nir_instrs_equal(instr, other)) {
-            nir_src other_dest_src = {
-               .is_ssa = true,
-               .ssa = nir_instr_get_dest_ssa_def(other),
-            };
+            nir_ssa_def *other_def = nir_instr_get_dest_ssa_def(other);
             nir_ssa_def_rewrite_uses(nir_instr_get_dest_ssa_def(instr),
-                                     other_dest_src, state->mem_ctx);
+                                     nir_src_for_ssa(other_def),
+                                     state->mem_ctx);
             nir_instr_remove(instr);
             state->progress = true;
             return;
index 5d2f5d6208dffeddebce73594ddfc62ddf32a030..a0b19c2ef253f62197ffe45469b85196a70b88c2 100644 (file)
@@ -168,11 +168,9 @@ nir_opt_peephole_select_block(nir_block *block, void *void_state)
                        phi->dest.ssa.num_components, phi->dest.ssa.name);
       sel->dest.write_mask = (1 << phi->dest.ssa.num_components) - 1;
 
-      nir_src sel_dest_src = {
-         .is_ssa = true,
-         .ssa = &sel->dest.dest.ssa,
-      };
-      nir_ssa_def_rewrite_uses(&phi->dest.ssa, sel_dest_src, state->mem_ctx);
+      nir_ssa_def_rewrite_uses(&phi->dest.ssa,
+                               nir_src_for_ssa(&sel->dest.dest.ssa),
+                               state->mem_ctx);
 
       nir_instr_insert_before(&phi->instr, &sel->instr);
       nir_instr_remove(&phi->instr);
index 35323f92a6b555f292dcb487f825587d73ca329d..e69fdfd431c8f70f2a231eed5f2465cb6bbcb27e 100644 (file)
@@ -221,13 +221,11 @@ construct_value(const nir_search_value *value, nir_alu_type type,
 
       nir_instr_insert_before(instr, &alu->instr);
 
-      nir_alu_src val = {
-         .src.is_ssa = true,
-         .src.ssa = &alu->dest.dest.ssa,
-         .negate = false,
-         .abs = false,
-         .swizzle = { 0, 1, 2, 3 }
-      };
+      nir_alu_src val;
+      val.src = nir_src_for_ssa(&alu->dest.dest.ssa);
+      val.negate = false;
+      val.abs = false,
+      memcpy(val.swizzle, identity_swizzle, sizeof val.swizzle);
 
       return val;
    }
@@ -265,13 +263,11 @@ construct_value(const nir_search_value *value, nir_alu_type type,
 
       nir_instr_insert_before(instr, &load->instr);
 
-      nir_alu_src val = {
-         .src.is_ssa = true,
-         .src.ssa = &load->def,
-         .negate = false,
-         .abs = false,
-         .swizzle = { 0, 0, 0, 0 } /* Splatted scalar */
-      };
+      nir_alu_src val;
+      val.src = nir_src_for_ssa(&load->def);
+      val.negate = false;
+      val.abs = false,
+      memset(val.swizzle, 0, sizeof val.swizzle);
 
       return val;
    }
@@ -314,12 +310,8 @@ nir_replace_instr(nir_alu_instr *instr, const nir_search_expression *search,
                                  &instr->instr, mem_ctx);
    nir_instr_insert_before(&instr->instr, &mov->instr);
 
-   nir_src replace_src = {
-      .is_ssa = true,
-      .ssa = &mov->dest.dest.ssa,
-   };
-
-   nir_ssa_def_rewrite_uses(&instr->dest.dest.ssa, replace_src, mem_ctx);
+   nir_ssa_def_rewrite_uses(&instr->dest.dest.ssa,
+                            nir_src_for_ssa(&mov->dest.dest.ssa), mem_ctx);
 
    /* We know this one has no more uses because we just rewrote them all,
     * so we can remove it.  The rest of the matched expression, however, we