X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Fcompiler%2Fnir%2Fnir_lower_regs_to_ssa.c;h=e045d97bac72317b187db017219e6797af2d6685;hb=ef142c68e1161bfa1fbe1ff19419a54cb1e8ea73;hp=76ed1287379d1256e46b46d8bacc4ce19f4f723b;hpb=6fb685fe4b762c8030f86895707516e2481e9ece;p=mesa.git diff --git a/src/compiler/nir/nir_lower_regs_to_ssa.c b/src/compiler/nir/nir_lower_regs_to_ssa.c index 76ed1287379..e045d97bac7 100644 --- a/src/compiler/nir/nir_lower_regs_to_ssa.c +++ b/src/compiler/nir/nir_lower_regs_to_ssa.c @@ -178,13 +178,7 @@ rewrite_alu_instr(nir_alu_instr *alu, struct regs_to_ssa_state *state) nir_ssa_dest_init(&alu->instr, &alu->dest.dest, num_components, reg->bit_size, reg->name); - nir_op vecN_op; - switch (reg->num_components) { - case 2: vecN_op = nir_op_vec2; break; - case 3: vecN_op = nir_op_vec3; break; - case 4: vecN_op = nir_op_vec4; break; - default: unreachable("not reached"); - } + nir_op vecN_op = nir_op_vec(reg->num_components); nir_alu_instr *vec = nir_alu_instr_create(state->shader, vecN_op); @@ -220,14 +214,16 @@ nir_lower_regs_to_ssa_impl(nir_function_impl *impl) nir_metadata_dominance); nir_index_local_regs(impl); + void *dead_ctx = ralloc_context(NULL); struct regs_to_ssa_state state; state.shader = impl->function->shader; - state.values = malloc(impl->reg_alloc * sizeof(*state.values)); + state.values = ralloc_array(dead_ctx, struct nir_phi_builder_value *, + impl->reg_alloc); struct nir_phi_builder *phi_build = nir_phi_builder_create(impl); const unsigned block_set_words = BITSET_WORDS(impl->num_blocks); - NIR_VLA(BITSET_WORD, defs, block_set_words); + BITSET_WORD *defs = ralloc_array(dead_ctx, BITSET_WORD, block_set_words); nir_foreach_register(reg, &impl->registers) { if (reg->num_array_elems != 0) { @@ -277,35 +273,21 @@ nir_lower_regs_to_ssa_impl(nir_function_impl *impl) * loops, a phi source may be a back-edge so we have to handle it as if * it were one of the last instructions in the predecessor block. */ - for (unsigned i = 0; i < ARRAY_SIZE(block->successors); i++) { - if (block->successors[i] == NULL) - continue; - - nir_foreach_instr(instr, block->successors[i]) { - if (instr->type != nir_instr_type_phi) - break; - - nir_phi_instr *phi = nir_instr_as_phi(instr); - nir_foreach_phi_src(phi_src, phi) { - if (phi_src->pred == block) - rewrite_src(&phi_src->src, &state); - } - } - } + nir_foreach_phi_src_leaving_block(block, rewrite_src, &state); } nir_phi_builder_finish(phi_build); nir_foreach_register_safe(reg, &impl->registers) { if (state.values[reg->index]) { - assert(list_empty(®->uses)); - assert(list_empty(®->if_uses)); - assert(list_empty(®->defs)); + assert(list_is_empty(®->uses)); + assert(list_is_empty(®->if_uses)); + assert(list_is_empty(®->defs)); exec_node_remove(®->node); } } - free(state.values); + ralloc_free(dead_ctx); nir_metadata_preserve(impl, nir_metadata_block_index | nir_metadata_dominance);