nir: Don't require a function in ssa_def_init
Instead, we give SSA definitions a temporary index of 0xFFFFFFFF if the instruction does not have a block and a proper index when it actually gets added to the list. Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
This commit is contained in:
@@ -1188,17 +1188,27 @@ add_use_cb(nir_src *src, void *state)
|
||||
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;
|
||||
}
|
||||
@@ -1206,8 +1216,12 @@ add_def_cb(nir_dest *dest, void *state)
|
||||
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
|
||||
@@ -1748,17 +1762,25 @@ 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,
|
||||
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 {
|
||||
|
@@ -1318,9 +1318,8 @@ bool nir_foreach_src(nir_instr *instr, nir_foreach_src_cb cb, void *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 */
|
||||
|
@@ -314,7 +314,7 @@ isolate_phi_nodes_block(nir_block *block, void *void_state)
|
||||
_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,
|
||||
@@ -339,7 +339,7 @@ isolate_phi_nodes_block(nir_block *block, void *void_state)
|
||||
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 = {
|
||||
|
@@ -34,7 +34,6 @@
|
||||
|
||||
struct peephole_ffma_state {
|
||||
void *mem_ctx;
|
||||
nir_function_impl *impl;
|
||||
bool progress;
|
||||
};
|
||||
|
||||
@@ -135,7 +134,7 @@ nir_opt_peephole_ffma_block(nir_block *block, void *void_state)
|
||||
|
||||
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);
|
||||
|
||||
@@ -165,7 +164,6 @@ nir_opt_peephole_ffma_impl(nir_function_impl *impl)
|
||||
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);
|
||||
|
@@ -48,7 +48,6 @@
|
||||
|
||||
struct peephole_select_state {
|
||||
void *mem_ctx;
|
||||
nir_function_impl *impl;
|
||||
bool progress;
|
||||
};
|
||||
|
||||
@@ -163,7 +162,7 @@ nir_opt_peephole_select_block(nir_block *block, void *void_state)
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
@@ -190,7 +189,6 @@ nir_opt_peephole_select_impl(nir_function_impl *impl)
|
||||
|
||||
state.mem_ctx = ralloc_parent(impl);
|
||||
state.progress = false;
|
||||
state.impl = impl;
|
||||
|
||||
nir_foreach_block(impl, nir_opt_peephole_select_block, &state);
|
||||
|
||||
|
@@ -163,7 +163,7 @@ static nir_ssa_def *get_ssa_src(nir_register *reg, rewrite_state *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);
|
||||
|
||||
/*
|
||||
@@ -246,7 +246,7 @@ rewrite_def_forwards(nir_dest *dest, void *_state)
|
||||
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 */
|
||||
@@ -312,7 +312,7 @@ rewrite_alu_instr_forward(nir_alu_instr *instr, rewrite_state *state)
|
||||
|
||||
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) {
|
||||
|
Reference in New Issue
Block a user