From b4369de27fc63222a024287af4a2ac58ee949953 Mon Sep 17 00:00:00 2001 From: "Thomas H.P. Andersen" Date: Mon, 28 Jun 2021 01:00:31 +0200 Subject: [PATCH] nir/lower_packing: use shader_instructions_pass Reviewed-by: Jason Ekstrand Part-of: --- src/compiler/nir/nir_lower_packing.c | 102 +++++++++++---------------- 1 file changed, 40 insertions(+), 62 deletions(-) diff --git a/src/compiler/nir/nir_lower_packing.c b/src/compiler/nir/nir_lower_packing.c index b162b84b31c..57bbeac49a8 100644 --- a/src/compiler/nir/nir_lower_packing.c +++ b/src/compiler/nir/nir_lower_packing.c @@ -87,80 +87,58 @@ lower_unpack_64_to_16(nir_builder *b, nir_ssa_def *src) } static bool -lower_pack_impl(nir_function_impl *impl) +lower_pack_instr(nir_builder *b, nir_instr *instr, void *data) { - nir_builder b; - nir_builder_init(&b, impl); - bool progress = false; + if (instr->type != nir_instr_type_alu) + return false; - nir_foreach_block(block, impl) { - nir_foreach_instr_safe(instr, block) { - if (instr->type != nir_instr_type_alu) - continue; + nir_alu_instr *alu_instr = (nir_alu_instr *) instr; - nir_alu_instr *alu_instr = (nir_alu_instr *) instr; + if (alu_instr->op != nir_op_pack_64_2x32 && + alu_instr->op != nir_op_unpack_64_2x32 && + alu_instr->op != nir_op_pack_64_4x16 && + alu_instr->op != nir_op_unpack_64_4x16 && + alu_instr->op != nir_op_pack_32_2x16 && + alu_instr->op != nir_op_unpack_32_2x16) - if (alu_instr->op != nir_op_pack_64_2x32 && - alu_instr->op != nir_op_unpack_64_2x32 && - alu_instr->op != nir_op_pack_64_4x16 && - alu_instr->op != nir_op_unpack_64_4x16 && - alu_instr->op != nir_op_pack_32_2x16 && - alu_instr->op != nir_op_unpack_32_2x16) - continue; + return false; - b.cursor = nir_before_instr(&alu_instr->instr); + b->cursor = nir_before_instr(&alu_instr->instr); - nir_ssa_def *src = nir_ssa_for_alu_src(&b, alu_instr, 0); - nir_ssa_def *dest; + nir_ssa_def *src = nir_ssa_for_alu_src(b, alu_instr, 0); + nir_ssa_def *dest; - switch (alu_instr->op) { - case nir_op_pack_64_2x32: - dest = lower_pack_64_from_32(&b, src); - break; - case nir_op_unpack_64_2x32: - dest = lower_unpack_64_to_32(&b, src); - break; - case nir_op_pack_64_4x16: - dest = lower_pack_64_from_16(&b, src); - break; - case nir_op_unpack_64_4x16: - dest = lower_unpack_64_to_16(&b, src); - break; - case nir_op_pack_32_2x16: - dest = lower_pack_32_from_16(&b, src); - break; - case nir_op_unpack_32_2x16: - dest = lower_unpack_32_to_16(&b, src); - break; - default: - unreachable("Impossible opcode"); - } - - nir_ssa_def_rewrite_uses(&alu_instr->dest.dest.ssa, dest); - nir_instr_remove(&alu_instr->instr); - progress = true; - } + switch (alu_instr->op) { + case nir_op_pack_64_2x32: + dest = lower_pack_64_from_32(b, src); + break; + case nir_op_unpack_64_2x32: + dest = lower_unpack_64_to_32(b, src); + break; + case nir_op_pack_64_4x16: + dest = lower_pack_64_from_16(b, src); + break; + case nir_op_unpack_64_4x16: + dest = lower_unpack_64_to_16(b, src); + break; + case nir_op_pack_32_2x16: + dest = lower_pack_32_from_16(b, src); + break; + case nir_op_unpack_32_2x16: + dest = lower_unpack_32_to_16(b, src); + break; + default: + unreachable("Impossible opcode"); } + nir_ssa_def_rewrite_uses(&alu_instr->dest.dest.ssa, dest); + nir_instr_remove(&alu_instr->instr); - if (progress) { - nir_metadata_preserve(impl, nir_metadata_block_index | - nir_metadata_dominance); - } else { - nir_metadata_preserve(impl, nir_metadata_all); - } - - return progress; + return true; } bool nir_lower_pack(nir_shader *shader) { - bool progress = false; - - nir_foreach_function(function, shader) { - if (function->impl) - progress |= lower_pack_impl(function->impl); - } - - return progress; + return nir_shader_instructions_pass(shader, lower_pack_instr, + nir_metadata_block_index | nir_metadata_dominance, NULL); }