Module: Mesa Branch: master Commit: 2c8c5cc87d55546cf3b3bedaf0da5bd3ecede322 URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=2c8c5cc87d55546cf3b3bedaf0da5bd3ecede322
Author: Jason Ekstrand <[email protected]> Date: Mon May 18 15:37:30 2020 -0500 nir/clone: Re-use clone_alu for nir_alu_instr_clone All it takes are a couple small tweaks to the clone infrastructure to allow us to use it without any remap table at all. This reduces code duplication and the chances for bugs that come with it. In particular, the hand-rolled nir_alu_instr_clone didn't preserve no_[un]signed_wrap, or source/destination modifiers. Reviewed-by: Alyssa Rosenzweig <[email protected]> Reviewed-by: Rob Clark <[email protected]> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5094> --- src/compiler/nir/nir_clone.c | 38 +++++++++++++++++--------------------- 1 file changed, 17 insertions(+), 21 deletions(-) diff --git a/src/compiler/nir/nir_clone.c b/src/compiler/nir/nir_clone.c index d5ae7f17793..1aaed566e98 100644 --- a/src/compiler/nir/nir_clone.c +++ b/src/compiler/nir/nir_clone.c @@ -85,6 +85,11 @@ _lookup_ptr(clone_state *state, const void *ptr, bool global) if (!state->global_clone && global) return (void *)ptr; + if (unlikely(!state->remap_table)) { + assert(state->allow_remap_fallback); + return (void *)ptr; + } + entry = _mesa_hash_table_search(state->remap_table, ptr); if (!entry) { assert(state->allow_remap_fallback); @@ -254,7 +259,8 @@ __clone_dst(clone_state *state, nir_instr *ninstr, if (dst->is_ssa) { nir_ssa_dest_init(ninstr, ndst, dst->ssa.num_components, dst->ssa.bit_size, dst->ssa.name); - add_remap(state, &ndst->ssa, &dst->ssa); + if (likely(state->remap_table)) + add_remap(state, &ndst->ssa, &dst->ssa); } else { ndst->reg.reg = remap_reg(state, dst->reg.reg); if (dst->reg.indirect) { @@ -265,26 +271,6 @@ __clone_dst(clone_state *state, nir_instr *ninstr, } } -nir_alu_instr * -nir_alu_instr_clone(nir_shader *shader, const nir_alu_instr *orig) -{ - nir_alu_instr *clone = nir_alu_instr_create(shader, orig->op); - - clone->exact = orig->exact; - - for (unsigned i = 0; i < nir_op_infos[orig->op].num_inputs; i++) - nir_alu_src_copy(&clone->src[i], &orig->src[i], clone); - - nir_ssa_dest_init(&clone->instr, - &clone->dest.dest, - orig->dest.dest.ssa.num_components, - orig->dest.dest.ssa.bit_size, - orig->dest.dest.ssa.name); - clone->dest.write_mask = orig->dest.write_mask; - - return clone; -} - static nir_alu_instr * clone_alu(clone_state *state, const nir_alu_instr *alu) { @@ -308,6 +294,16 @@ clone_alu(clone_state *state, const nir_alu_instr *alu) return nalu; } +nir_alu_instr * +nir_alu_instr_clone(nir_shader *shader, const nir_alu_instr *orig) +{ + clone_state state = { + .allow_remap_fallback = true, + .ns = shader, + }; + return clone_alu(&state, orig); +} + static nir_deref_instr * clone_deref_instr(clone_state *state, const nir_deref_instr *deref) { _______________________________________________ mesa-commit mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/mesa-commit
