nir: Add and use initializer #defines for nir_src and nir_dest
authorJason Ekstrand <jason.ekstrand@intel.com>
Wed, 22 Apr 2015 01:00:21 +0000 (18:00 -0700)
committerJason Ekstrand <jason.ekstrand@intel.com>
Sat, 9 May 2015 00:16:13 +0000 (17:16 -0700)
Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
src/glsl/nir/glsl_to_nir.cpp
src/glsl/nir/nir.h
src/glsl/nir/nir_builder.h
src/glsl/nir/nir_lower_samplers.cpp
src/glsl/nir/nir_lower_tex_projector.c
src/glsl/nir/nir_search.c

index 74cfb55394caeb4d3aa0d0d05bcb71392ad67d90..7a20e1a36f528972eaa1b982c235a24504d1b9bb 100644 (file)
@@ -824,7 +824,7 @@ nir_visitor::evaluate_rvalue(ir_rvalue* ir)
    nir_dest *dest = get_instr_dest(this->result);
 
    assert(dest->is_ssa);
-   nir_src src;
+   nir_src src = NIR_SRC_INIT;
    src.is_ssa = true;
    src.ssa = &dest->ssa;
 
index 98b0ec3287c71fd91e016e5fbbec83073535b0d9..a174666e0e4b31206d098d96154f80db85e1886a 100644 (file)
@@ -497,6 +497,8 @@ typedef struct nir_src {
    bool is_ssa;
 } nir_src;
 
+#define NIR_SRC_INIT (nir_src) { { { NULL } } }
+
 typedef struct {
    union {
       nir_reg_dest reg;
@@ -506,10 +508,12 @@ typedef struct {
    bool is_ssa;
 } nir_dest;
 
+#define NIR_DEST_INIT (nir_dest) { { { NULL } } }
+
 static inline nir_src
 nir_src_for_ssa(nir_ssa_def *def)
 {
-   nir_src src;
+   nir_src src = NIR_SRC_INIT;
 
    src.is_ssa = true;
    src.ssa = def;
@@ -520,7 +524,7 @@ nir_src_for_ssa(nir_ssa_def *def)
 static inline nir_src
 nir_src_for_reg(nir_register *reg)
 {
-   nir_src src;
+   nir_src src = NIR_SRC_INIT;
 
    src.is_ssa = false;
    src.reg.reg = reg;
@@ -543,12 +547,9 @@ nir_src_get_parent_instr(const nir_src *src)
 static inline nir_dest
 nir_dest_for_reg(nir_register *reg)
 {
-   nir_dest dest;
+   nir_dest dest = NIR_DEST_INIT;
 
-   dest.is_ssa = false;
    dest.reg.reg = reg;
-   dest.reg.indirect = NULL;
-   dest.reg.base_offset = 0;
 
    return dest;
 }
index d1419ee2114c6c6bf7f0904cf711a3d21d0c4193..9223e838095cc3ca3a61ae3168cfdbdb0f9c55ab 100644 (file)
@@ -231,8 +231,7 @@ static inline nir_ssa_def *
 nir_swizzle(nir_builder *build, nir_ssa_def *src, unsigned swiz[4],
             unsigned num_components, bool use_fmov)
 {
-   nir_alu_src alu_src;
-   memset(&alu_src, 0, sizeof(alu_src));
+   nir_alu_src alu_src = { NIR_SRC_INIT };
    alu_src.src = nir_src_for_ssa(src);
    for (int i = 0; i < 4; i++)
       alu_src.swizzle[i] = swiz[i];
@@ -251,8 +250,7 @@ nir_ssa_for_src(nir_builder *build, nir_src src, int num_components)
    if (src.is_ssa && src.ssa->num_components == num_components)
       return src.ssa;
 
-   nir_alu_src alu;
-   memset(&alu, 0, sizeof(alu));
+   nir_alu_src alu = { NIR_SRC_INIT };
    alu.src = src;
    for (int j = 0; j < 4; j++)
       alu.swizzle[j] = j;
index cf8ab832516b2b4d04265056d621c840fc319d0e..e9e152f6cbf82878a8cfa41589c65b507789c478 100644 (file)
@@ -95,9 +95,8 @@ lower_sampler(nir_tex_instr *instr, const struct gl_shader_program *shader_progr
 
             instr->sampler_array_size = glsl_get_length(deref->type);
 
-            nir_src empty;
-            memset(&empty, 0, sizeof empty);
-            nir_instr_rewrite_src(&instr->instr, &deref_array->indirect, empty);
+            nir_instr_rewrite_src(&instr->instr, &deref_array->indirect,
+                                  NIR_SRC_INIT);
 
             if (deref_array->deref.child)
                ralloc_strcat(&name, "[0]");
index 6b0e9c340a98437c962a4cee305fcb673044a51e..6e2cc803fb8a0f46585439615211a939e3be1674 100644 (file)
@@ -109,9 +109,8 @@ nir_lower_tex_projector_block(nir_block *block, void *void_state)
       /* Now move the later tex sources down the array so that the projector
        * disappears.
        */
-      nir_src dead;
-      memset(&dead, 0, sizeof dead);
-      nir_instr_rewrite_src(&tex->instr, &tex->src[proj_index].src, dead);
+      nir_instr_rewrite_src(&tex->instr, &tex->src[proj_index].src,
+                            NIR_SRC_INIT);
       memmove(&tex->src[proj_index],
               &tex->src[proj_index + 1],
               (tex->num_srcs - proj_index) * sizeof(*tex->src));
index 5ba016085fcecad311f0ba351ace4e72e27f2bcc..490b31ffe8a108d8c02d5b4a8bda08c87a83c2df 100644 (file)
@@ -276,7 +276,7 @@ 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;
+      nir_alu_src val = { NIR_SRC_INIT };
       nir_alu_src_copy(&val, &state->variables[var->variable], mem_ctx);
 
       assert(!var->is_constant);