nir: Add an initialization function for SSA definitions
Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
This commit is contained in:
@@ -1597,6 +1597,20 @@ nir_foreach_src(nir_instr *instr, nir_foreach_src_cb cb, void *state)
|
|||||||
return nir_foreach_dest(instr, visit_dest_indirect, &dest_state);
|
return nir_foreach_dest(instr, visit_dest_indirect, &dest_state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
nir_ssa_def_init(nir_function_impl *impl, 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static bool foreach_cf_node(nir_cf_node *node, nir_foreach_block_cb cb,
|
static bool foreach_cf_node(nir_cf_node *node, nir_foreach_block_cb cb,
|
||||||
bool reverse, void *state);
|
bool reverse, void *state);
|
||||||
|
@@ -1278,6 +1278,10 @@ typedef bool (*nir_foreach_src_cb)(nir_src *src, void *state);
|
|||||||
bool nir_foreach_dest(nir_instr *instr, nir_foreach_dest_cb cb, void *state);
|
bool nir_foreach_dest(nir_instr *instr, nir_foreach_dest_cb cb, void *state);
|
||||||
bool nir_foreach_src(nir_instr *instr, nir_foreach_src_cb cb, void *state);
|
bool nir_foreach_src(nir_instr *instr, nir_foreach_src_cb cb, void *state);
|
||||||
|
|
||||||
|
void nir_ssa_def_init(nir_function_impl *impl, nir_instr *instr,
|
||||||
|
nir_ssa_def *def, unsigned num_components,
|
||||||
|
const char *name);
|
||||||
|
|
||||||
/* visits basic blocks in source-code order */
|
/* visits basic blocks in source-code order */
|
||||||
typedef bool (*nir_foreach_block_cb)(nir_block *block, void *state);
|
typedef bool (*nir_foreach_block_cb)(nir_block *block, void *state);
|
||||||
bool nir_foreach_block(nir_function_impl *impl, nir_foreach_block_cb cb,
|
bool nir_foreach_block(nir_function_impl *impl, nir_foreach_block_cb cb,
|
||||||
|
@@ -163,12 +163,9 @@ static nir_ssa_def *get_ssa_src(nir_register *reg, rewrite_state *state)
|
|||||||
* to preserve the information that this source is undefined
|
* to preserve the information that this source is undefined
|
||||||
*/
|
*/
|
||||||
nir_ssa_undef_instr *instr = nir_ssa_undef_instr_create(state->mem_ctx);
|
nir_ssa_undef_instr *instr = nir_ssa_undef_instr_create(state->mem_ctx);
|
||||||
instr->def.index = state->impl->ssa_alloc++;
|
nir_ssa_def_init(state->impl, &instr->instr, &instr->def,
|
||||||
instr->def.num_components = reg->num_components;
|
reg->num_components, NULL);
|
||||||
instr->def.uses = _mesa_set_create(state->mem_ctx,
|
|
||||||
_mesa_key_pointer_equal);
|
|
||||||
instr->def.if_uses = _mesa_set_create(state->mem_ctx,
|
|
||||||
_mesa_key_pointer_equal);
|
|
||||||
/*
|
/*
|
||||||
* We could just insert the undefined instruction before the instruction
|
* We could just insert the undefined instruction before the instruction
|
||||||
* we're rewriting, but we could be rewriting a phi source in which case
|
* we're rewriting, but we could be rewriting a phi source in which case
|
||||||
@@ -254,13 +251,8 @@ rewrite_def_forwards(nir_dest *dest, void *_state)
|
|||||||
name = ralloc_asprintf(state->mem_ctx, "%s_%u", dest->reg.reg->name,
|
name = ralloc_asprintf(state->mem_ctx, "%s_%u", dest->reg.reg->name,
|
||||||
state->states[index].num_defs);
|
state->states[index].num_defs);
|
||||||
|
|
||||||
dest->ssa.index = state->impl->ssa_alloc++;
|
nir_ssa_def_init(state->impl, state->parent_instr, &dest->ssa,
|
||||||
dest->ssa.num_components = reg->num_components;
|
reg->num_components, name);
|
||||||
dest->ssa.parent_instr = state->parent_instr;
|
|
||||||
dest->ssa.uses = _mesa_set_create(state->mem_ctx, _mesa_key_pointer_equal);
|
|
||||||
dest->ssa.if_uses = _mesa_set_create(state->mem_ctx,
|
|
||||||
_mesa_key_pointer_equal);
|
|
||||||
dest->ssa.name = name;
|
|
||||||
|
|
||||||
/* push our SSA destination on the stack */
|
/* push our SSA destination on the stack */
|
||||||
state->states[index].index++;
|
state->states[index].index++;
|
||||||
@@ -327,14 +319,8 @@ rewrite_alu_instr_forward(nir_alu_instr *instr, rewrite_state *state)
|
|||||||
|
|
||||||
instr->dest.write_mask = (1 << num_components) - 1;
|
instr->dest.write_mask = (1 << num_components) - 1;
|
||||||
instr->dest.dest.is_ssa = true;
|
instr->dest.dest.is_ssa = true;
|
||||||
instr->dest.dest.ssa.index = state->impl->ssa_alloc++;
|
nir_ssa_def_init(state->impl, &instr->instr, &instr->dest.dest.ssa,
|
||||||
instr->dest.dest.ssa.num_components = num_components;
|
num_components, name);
|
||||||
instr->dest.dest.ssa.name = name;
|
|
||||||
instr->dest.dest.ssa.parent_instr = &instr->instr;
|
|
||||||
instr->dest.dest.ssa.uses = _mesa_set_create(state->mem_ctx,
|
|
||||||
_mesa_key_pointer_equal);
|
|
||||||
instr->dest.dest.ssa.if_uses = _mesa_set_create(state->mem_ctx,
|
|
||||||
_mesa_key_pointer_equal);
|
|
||||||
|
|
||||||
if (nir_op_infos[instr->op].output_size == 0) {
|
if (nir_op_infos[instr->op].output_size == 0) {
|
||||||
/*
|
/*
|
||||||
|
Reference in New Issue
Block a user