[Mesa-dev] [PATCH 04/11] nir: Add a function for rewriting instruction destinations

Jason Ekstrand jason at jlekstrand.net
Thu Sep 10 11:30:01 PDT 2015


On Thu, Sep 10, 2015 at 3:01 AM, Michael Schellenberger Costa
<schellenberger at inb.uni-luebeck.de> wrote:
> Hi,
> Am 10/09/2015 um 02:50 schrieb Jason Ekstrand:
>> ---
>>  src/glsl/nir/nir.c | 24 ++++++++++++++++++++++++
>>  src/glsl/nir/nir.h |  2 ++
>>  2 files changed, 26 insertions(+)
>>
>> diff --git a/src/glsl/nir/nir.c b/src/glsl/nir/nir.c
>> index e173b21..0090b08 100644
>> --- a/src/glsl/nir/nir.c
>> +++ b/src/glsl/nir/nir.c
>> @@ -1175,6 +1175,30 @@ nir_if_rewrite_condition(nir_if *if_stmt, nir_src new_src)
>>  }
>>
>>  void
>> +nir_instr_rewrite_dest(nir_instr *instr, nir_dest *dest, nir_dest new_dest)
>> +{
>> +   if (dest->is_ssa) {
>> +      /* We can only overwrite an SSA destination if it has no uses. */
>> +      assert(list_empty(&dest->ssa.uses) && list_empty(&dest->ssa.if_uses));
>> +   } else {
>> +      list_del(&dest->reg.def_link);
>> +      if (dest->reg.indirect)
>> +         src_remove_all_uses(dest->reg.indirect);
>> +   }
>> +
>> +   /* We can't re-write with an SSA def */
>> +   assert(!new_dest.is_ssa);
> Wouldn't it make more sense to check that assert first, as the if clause
> above may include some work

Meh.  It won't save us anything in release mode and we do so much
extra work in debug mode that it won't matter.  If you really want to
see it moved, I guess I'm not opposed.
--Jason

> Michael
>> +
>> +   nir_dest_copy(dest, &new_dest, instr);
>> +
>> +   dest->reg.parent_instr = instr;
>> +   list_addtail(&dest->reg.def_link, &new_dest.reg.reg->defs);
>> +
>> +   if (dest->reg.indirect)
>> +      src_add_all_uses(dest->reg.indirect, instr, NULL);
>> +}
>> +
>> +void
>>  nir_ssa_def_init(nir_instr *instr, nir_ssa_def *def,
>>                   unsigned num_components, const char *name)
>>  {
>> diff --git a/src/glsl/nir/nir.h b/src/glsl/nir/nir.h
>> index 32c338c..a8e7363 100644
>> --- a/src/glsl/nir/nir.h
>> +++ b/src/glsl/nir/nir.h
>> @@ -1725,6 +1725,8 @@ bool nir_srcs_equal(nir_src src1, nir_src src2);
>>  void nir_instr_rewrite_src(nir_instr *instr, nir_src *src, nir_src new_src);
>>  void nir_instr_move_src(nir_instr *dest_instr, nir_src *dest, nir_src *src);
>>  void nir_if_rewrite_condition(nir_if *if_stmt, nir_src new_src);
>> +void nir_instr_rewrite_dest(nir_instr *instr, nir_dest *dest,
>> +                            nir_dest new_dest);
>>
>>  void nir_ssa_dest_init(nir_instr *instr, nir_dest *dest,
>>                         unsigned num_components, const char *name);
>>
>


More information about the mesa-dev mailing list