return true;
}
+static void
+add_ssa_def(nir_instr *instr, nir_ssa_def *def)
+{
+ if (instr->block && def->index == UINT_MAX) {
+ nir_function_impl *impl =
+ nir_cf_node_get_function(&instr->block->cf_node);
+
+ def->index = impl->ssa_alloc++;
+ }
+}
+
static bool
add_def_cb(nir_dest *dest, void *state)
{
nir_instr *instr = (nir_instr *) state;
- if (dest->is_ssa)
- return true;
-
- nir_register *reg = dest->reg.reg;
-
- _mesa_set_add(reg->defs, _mesa_hash_pointer(instr), instr);
+ if (dest->is_ssa) {
+ add_ssa_def(instr, &dest->ssa);
+ } else {
+ _mesa_set_add(dest->reg.reg->defs, _mesa_hash_pointer(instr), instr);
+ }
return true;
}
static void
add_defs_uses(nir_instr *instr)
{
- nir_foreach_src(instr, add_use_cb, instr);
- nir_foreach_dest(instr, add_def_cb, instr);
+ if (instr->type == nir_instr_type_ssa_undef) {
+ add_ssa_def(instr, &nir_instr_as_ssa_undef(instr)->def);
+ } else {
+ nir_foreach_src(instr, add_use_cb, instr);
+ nir_foreach_dest(instr, add_def_cb, instr);
+ }
}
void
}
void
-nir_ssa_def_init(nir_function_impl *impl, nir_instr *instr, nir_ssa_def *def,
+nir_ssa_def_init(nir_instr *instr, nir_ssa_def *def,
unsigned num_components, const char *name)
{
void *mem_ctx = ralloc_parent(instr);
def->name = name;
- def->index = impl->ssa_alloc++;
def->parent_instr = instr;
def->uses = _mesa_set_create(mem_ctx, _mesa_key_pointer_equal);
def->if_uses = _mesa_set_create(mem_ctx, _mesa_key_pointer_equal);
def->num_components = num_components;
+
+ if (instr->block) {
+ nir_function_impl *impl =
+ nir_cf_node_get_function(&instr->block->cf_node);
+
+ def->index = impl->ssa_alloc++;
+ } else {
+ def->index = UINT_MAX;
+ }
}
struct ssa_def_rewrite_state {
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_ssa_def_init(nir_function_impl *impl, nir_instr *instr,
- nir_ssa_def *def, unsigned num_components,
- const char *name);
+void nir_ssa_def_init(nir_instr *instr, nir_ssa_def *def,
+ unsigned num_components, const char *name);
void nir_ssa_def_rewrite_uses(nir_ssa_def *def, nir_src new_src, void *mem_ctx);
/* visits basic blocks in source-code order */
_mesa_hash_pointer(&pcopy->instr), &pcopy->instr);
copy->dest.is_ssa = true;
- nir_ssa_def_init(state->impl, &pcopy->instr, ©->dest.ssa,
+ nir_ssa_def_init(&pcopy->instr, ©->dest.ssa,
phi->dest.ssa.num_components, src->src.ssa->name);
struct set_entry *entry = _mesa_set_search(src->src.ssa->uses,
exec_list_push_tail(&block_pcopy->copies, ©->node);
copy->dest.is_ssa = true;
- nir_ssa_def_init(state->impl, &block_pcopy->instr, ©->dest.ssa,
+ nir_ssa_def_init(&block_pcopy->instr, ©->dest.ssa,
phi->dest.ssa.num_components, phi->dest.ssa.name);
nir_src copy_dest_src = {
struct peephole_ffma_state {
void *mem_ctx;
- nir_function_impl *impl;
bool progress;
};
if (add->dest.dest.is_ssa) {
ffma->dest.dest.is_ssa = true;
- nir_ssa_def_init(state->impl, &ffma->instr, &ffma->dest.dest.ssa,
+ nir_ssa_def_init(&ffma->instr, &ffma->dest.dest.ssa,
add->dest.dest.ssa.num_components,
add->dest.dest.ssa.name);
struct peephole_ffma_state state;
state.mem_ctx = ralloc_parent(impl);
- state.impl = impl;
state.progress = false;
nir_foreach_block(impl, nir_opt_peephole_ffma_block, &state);
struct peephole_select_state {
void *mem_ctx;
- nir_function_impl *impl;
bool progress;
};
}
sel->dest.dest.is_ssa = true;
- nir_ssa_def_init(state->impl, &sel->instr, &sel->dest.dest.ssa,
+ nir_ssa_def_init(&sel->instr, &sel->dest.dest.ssa,
phi->dest.ssa.num_components, phi->dest.ssa.name);
sel->dest.write_mask = (1 << phi->dest.ssa.num_components) - 1;
state.mem_ctx = ralloc_parent(impl);
state.progress = false;
- state.impl = impl;
nir_foreach_block(impl, nir_opt_peephole_select_block, &state);
* to preserve the information that this source is undefined
*/
nir_ssa_undef_instr *instr = nir_ssa_undef_instr_create(state->mem_ctx);
- nir_ssa_def_init(state->impl, &instr->instr, &instr->def,
+ nir_ssa_def_init(&instr->instr, &instr->def,
reg->num_components, NULL);
/*
name = ralloc_asprintf(state->mem_ctx, "%s_%u", dest->reg.reg->name,
state->states[index].num_defs);
- nir_ssa_def_init(state->impl, state->parent_instr, &dest->ssa,
+ nir_ssa_def_init(state->parent_instr, &dest->ssa,
reg->num_components, name);
/* push our SSA destination on the stack */
instr->dest.write_mask = (1 << num_components) - 1;
instr->dest.dest.is_ssa = true;
- nir_ssa_def_init(state->impl, &instr->instr, &instr->dest.dest.ssa,
+ nir_ssa_def_init(&instr->instr, &instr->dest.dest.ssa,
num_components, name);
if (nir_op_infos[instr->op].output_size == 0) {