[Mesa-dev] [PATCH 2/2] nir: Stop using designated initializers
Jason Ekstrand
jason at jlekstrand.net
Wed Jan 21 12:19:55 PST 2015
On Wed, Jan 21, 2015 at 12:19 PM, Connor Abbott <cwabbott0 at gmail.com> wrote:
> Assuming this actually compiles with GCC 4.4...
>
I don't know for sure, but it certainly gets us closer
--Jason
>
> Reviewed-by: Connor Abbott <cwabbott0 at gmail.com>
>
> On Wed, Jan 21, 2015 at 2:14 PM, Jason Ekstrand <jason at jlekstrand.net>
> wrote:
> > 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
> > ---
> > src/glsl/nir/nir_from_ssa.c | 30
> ++++++++----------------------
> > src/glsl/nir/nir_lower_atomics.c | 8 +++-----
> > src/glsl/nir/nir_lower_io.c | 9 ++-------
> > src/glsl/nir/nir_lower_locals_to_regs.c | 9 ++-------
> > src/glsl/nir/nir_lower_system_values.c | 8 +++-----
> > src/glsl/nir/nir_lower_vars_to_ssa.c | 16 ++++------------
> > src/glsl/nir/nir_opt_constant_folding.c | 16 ++++------------
> > src/glsl/nir/nir_opt_cse.c | 16 ++++++----------
> > src/glsl/nir/nir_opt_peephole_select.c | 8 +++-----
> > src/glsl/nir/nir_search.c | 8 ++------
> > 10 files changed, 37 insertions(+), 91 deletions(-)
> >
> > diff --git a/src/glsl/nir/nir_from_ssa.c b/src/glsl/nir/nir_from_ssa.c
> > index 9728b99..8b8f0f5 100644
> > --- a/src/glsl/nir/nir_from_ssa.c
> > +++ b/src/glsl/nir/nir_from_ssa.c
> > @@ -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) {
> > diff --git a/src/glsl/nir/nir_lower_atomics.c
> b/src/glsl/nir/nir_lower_atomics.c
> > index 874c534..c45b397 100644
> > --- a/src/glsl/nir/nir_lower_atomics.c
> > +++ b/src/glsl/nir/nir_lower_atomics.c
> > @@ -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);
> > }
> > diff --git a/src/glsl/nir/nir_lower_io.c b/src/glsl/nir/nir_lower_io.c
> > index af87c13..c35058c 100644
> > --- a/src/glsl/nir/nir_lower_io.c
> > +++ b/src/glsl/nir/nir_lower_io.c
> > @@ -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);
> > diff --git a/src/glsl/nir/nir_lower_locals_to_regs.c
> b/src/glsl/nir/nir_lower_locals_to_regs.c
> > index b187541..f50533f 100644
> > --- a/src/glsl/nir/nir_lower_locals_to_regs.c
> > +++ b/src/glsl/nir/nir_lower_locals_to_regs.c
> > @@ -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);
> > diff --git a/src/glsl/nir/nir_lower_system_values.c
> b/src/glsl/nir/nir_lower_system_values.c
> > index d1b4d26..f681a6c 100644
> > --- a/src/glsl/nir/nir_lower_system_values.c
> > +++ b/src/glsl/nir/nir_lower_system_values.c
> > @@ -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);
> > }
> > diff --git a/src/glsl/nir/nir_lower_vars_to_ssa.c
> b/src/glsl/nir/nir_lower_vars_to_ssa.c
> > index 4df9bdd..061dbce 100644
> > --- a/src/glsl/nir/nir_lower_vars_to_ssa.c
> > +++ b/src/glsl/nir/nir_lower_vars_to_ssa.c
> > @@ -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;
> > }
> > diff --git a/src/glsl/nir/nir_opt_constant_folding.c
> b/src/glsl/nir/nir_opt_constant_folding.c
> > index 6c02582..878436b 100644
> > --- a/src/glsl/nir/nir_opt_constant_folding.c
> > +++ b/src/glsl/nir/nir_opt_constant_folding.c
> > @@ -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;
> >
> > diff --git a/src/glsl/nir/nir_opt_cse.c b/src/glsl/nir/nir_opt_cse.c
> > index 89d78c8..a33ebdd 100644
> > --- a/src/glsl/nir/nir_opt_cse.c
> > +++ b/src/glsl/nir/nir_opt_cse.c
> > @@ -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;
> > diff --git a/src/glsl/nir/nir_opt_peephole_select.c
> b/src/glsl/nir/nir_opt_peephole_select.c
> > index 5d2f5d6..a0b19c2 100644
> > --- a/src/glsl/nir/nir_opt_peephole_select.c
> > +++ b/src/glsl/nir/nir_opt_peephole_select.c
> > @@ -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);
> > diff --git a/src/glsl/nir/nir_search.c b/src/glsl/nir/nir_search.c
> > index 35323f9..a7bd051 100644
> > --- a/src/glsl/nir/nir_search.c
> > +++ b/src/glsl/nir/nir_search.c
> > @@ -314,12 +314,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
> > --
> > 2.2.1
> >
> > _______________________________________________
> > mesa-dev mailing list
> > mesa-dev at lists.freedesktop.org
> > http://lists.freedesktop.org/mailman/listinfo/mesa-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/mesa-dev/attachments/20150121/5ea85664/attachment-0001.html>
More information about the mesa-dev
mailing list