*/
#include "nir.h"
+#include "nir_builder.h"
struct lower_io_state {
+ nir_builder builder;
void *mem_ctx;
bool is_scalar;
};
bool found_indirect = false;
unsigned base_offset = 0;
+ nir_builder *b = &state->builder;
+ nir_builder_insert_before_instr(b, instr);
+
nir_deref *tail = &deref->deref;
while (tail->child != NULL) {
const struct glsl_type *parent_type = tail->type;
base_offset += size * deref_array->base_offset;
if (deref_array->deref_array_type == nir_deref_array_type_indirect) {
- nir_load_const_instr *load_const =
- nir_load_const_instr_create(state->mem_ctx, 1);
- load_const->value.u[0] = size;
- nir_instr_insert_before(instr, &load_const->instr);
-
- nir_alu_instr *mul = nir_alu_instr_create(state->mem_ctx,
- nir_op_imul);
- mul->src[0].src.is_ssa = true;
- mul->src[0].src.ssa = &load_const->def;
- nir_src_copy(&mul->src[1].src, &deref_array->indirect,
- state->mem_ctx);
- mul->dest.write_mask = 1;
- nir_ssa_dest_init(&mul->instr, &mul->dest.dest, 1, NULL);
- nir_instr_insert_before(instr, &mul->instr);
+ nir_ssa_def *mul =
+ nir_imul(b, nir_imm_int(b, size),
+ nir_ssa_for_src(b, deref_array->indirect, 1));
if (found_indirect) {
- nir_alu_instr *add = nir_alu_instr_create(state->mem_ctx,
- nir_op_iadd);
- add->src[0].src = *indirect;
- add->src[1].src.is_ssa = true;
- add->src[1].src.ssa = &mul->dest.dest.ssa;
- add->dest.write_mask = 1;
- nir_ssa_dest_init(&add->instr, &add->dest.dest, 1, NULL);
- nir_instr_insert_before(instr, &add->instr);
-
- indirect->is_ssa = true;
- indirect->ssa = &add->dest.dest.ssa;
+ indirect->ssa =
+ nir_iadd(b, nir_ssa_for_src(b, *indirect, 1), mul);
} else {
- indirect->is_ssa = true;
- indirect->ssa = &mul->dest.dest.ssa;
- found_indirect = true;
+ indirect->ssa = mul;
}
+ indirect->is_ssa = true;
+ found_indirect = true;
}
} else if (tail->deref_type == nir_deref_type_struct) {
nir_deref_struct *deref_struct = nir_deref_as_struct(tail);
{
struct lower_io_state state;
+ nir_builder_init(&state.builder, impl);
state.mem_ctx = ralloc_parent(impl);
state.is_scalar = is_scalar;