[Mesa-dev] [PATCH] nir: Add an ALU op builder kind of like ir_builder.h

Eric Anholt eric at anholt.net
Mon Feb 2 16:30:51 PST 2015


Connor Abbott <cwabbott0 at gmail.com> writes:

> I mentioned this on IRC, but it would be good to add the ability to
> append the sequence of instructions before/after an instruction as
> well as at the beginning or end of a basic block. We would need to
> store the current basic block, the current instruction, and an enum
> consisting of "insert before instruction," "insert after instruction,"
> insert at beginning of block," and "insert at end of block."

I'm skeptical of doing this without a caller.  It should be easy to add
when someone wants it, right?

> Also, why isn't there a function for initializing the builder
> structure?

I dunno, same reason we don't have functions for initializing other
structures like alu src ops?  Nobody wrote one that was simpler than
just initializing the fields?

>> +static inline nir_ssa_def *
>> +nir_build_alu(struct nir_builder *build, nir_op op, nir_ssa_def *src0,
>> +              nir_ssa_def *src1, nir_ssa_def *src2, nir_ssa_def *src3)
>> +{
>> +   nir_alu_instr *instr = nir_alu_instr_create(build->shader, op);
>> +   if (!instr)
>> +      return NULL;
>> +
>> +   instr->src[0].src = nir_src_for_ssa(src0);
>> +   if (src1)
>> +      instr->src[1].src = nir_src_for_ssa(src1);
>> +   if (src2)
>> +      instr->src[2].src = nir_src_for_ssa(src2);
>> +   if (src3)
>> +      instr->src[3].src = nir_src_for_ssa(src3);
>> +
>> +   unsigned num_components = nir_op_infos[op].output_size;
>> +   if (num_components == 0)
>> +      num_components = 4;
>
> We can and should do better here. We should look at the size
> (num_components) of the per-component (input_size == 0) inputs and
> make the output size the size of the largest input. Anything larger
> would be pointless.

This actually worked out, and it ended up being a little tiny codegen
improvement.

> - You don't need to use sorted() here, since unlike in nir_opcodes.h
> you don't care about the order.
> - You should use "for name, opcode in opcodes.iteritems(opcodes)" and
> then use the opcode directly below instead of saying opcodes[name].

I'm definitely retaining the sorted() -- code generation in hash table
order makes things a disaster for trying to look at differences in code
generation.  But I've adjusted to Ken's more pythonish style
recommendation.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 818 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/mesa-dev/attachments/20150202/10465600/attachment.sig>


More information about the mesa-dev mailing list