From 300d72943675a49091ecb49597b56f7bdfefd22d Mon Sep 17 00:00:00 2001 From: Jason Ekstrand Date: Tue, 21 Apr 2015 18:00:21 -0700 Subject: [PATCH] nir: Add and use initializer #defines for nir_src and nir_dest Reviewed-by: Connor Abbott --- src/glsl/nir/glsl_to_nir.cpp | 2 +- src/glsl/nir/nir.h | 13 +++++++------ src/glsl/nir/nir_builder.h | 6 ++---- src/glsl/nir/nir_lower_samplers.cpp | 5 ++--- src/glsl/nir/nir_lower_tex_projector.c | 5 ++--- src/glsl/nir/nir_search.c | 2 +- 6 files changed, 15 insertions(+), 18 deletions(-) diff --git a/src/glsl/nir/glsl_to_nir.cpp b/src/glsl/nir/glsl_to_nir.cpp index 74cfb55394c..7a20e1a36f5 100644 --- a/src/glsl/nir/glsl_to_nir.cpp +++ b/src/glsl/nir/glsl_to_nir.cpp @@ -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; diff --git a/src/glsl/nir/nir.h b/src/glsl/nir/nir.h index 98b0ec3287c..a174666e0e4 100644 --- a/src/glsl/nir/nir.h +++ b/src/glsl/nir/nir.h @@ -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; } diff --git a/src/glsl/nir/nir_builder.h b/src/glsl/nir/nir_builder.h index d1419ee2114..9223e838095 100644 --- a/src/glsl/nir/nir_builder.h +++ b/src/glsl/nir/nir_builder.h @@ -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; diff --git a/src/glsl/nir/nir_lower_samplers.cpp b/src/glsl/nir/nir_lower_samplers.cpp index cf8ab832516..e9e152f6cbf 100644 --- a/src/glsl/nir/nir_lower_samplers.cpp +++ b/src/glsl/nir/nir_lower_samplers.cpp @@ -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]"); diff --git a/src/glsl/nir/nir_lower_tex_projector.c b/src/glsl/nir/nir_lower_tex_projector.c index 6b0e9c340a9..6e2cc803fb8 100644 --- a/src/glsl/nir/nir_lower_tex_projector.c +++ b/src/glsl/nir/nir_lower_tex_projector.c @@ -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)); diff --git a/src/glsl/nir/nir_search.c b/src/glsl/nir/nir_search.c index 5ba016085fc..490b31ffe8a 100644 --- a/src/glsl/nir/nir_search.c +++ b/src/glsl/nir/nir_search.c @@ -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); -- 2.30.2