From ea39efe9b803cbe493678e4f9ba3f8516df98c6b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Marcin=20=C5=9Alusarz?= Date: Mon, 9 Aug 2021 13:56:07 +0200 Subject: [PATCH] nir: use nir_shader_instructions_pass in nir_lower_bool_to_int32 No functional changes. Reviewed-by: Alyssa Rosenzweig Part-of: --- src/compiler/nir/nir_lower_bool_to_int32.c | 84 ++++++++++++------------------ 1 file changed, 34 insertions(+), 50 deletions(-) diff --git a/src/compiler/nir/nir_lower_bool_to_int32.c b/src/compiler/nir/nir_lower_bool_to_int32.c index c1afed4..4f1ac15 100644 --- a/src/compiler/nir/nir_lower_bool_to_int32.c +++ b/src/compiler/nir/nir_lower_bool_to_int32.c @@ -22,6 +22,7 @@ */ #include "nir.h" +#include "nir_builder.h" static bool assert_ssa_def_is_not_1bit(nir_ssa_def *def, UNUSED void *unused) @@ -131,65 +132,48 @@ lower_tex_instr(nir_tex_instr *tex) } static bool -nir_lower_bool_to_int32_impl(nir_function_impl *impl) +nir_lower_bool_to_int32_instr(UNUSED nir_builder *b, + nir_instr *instr, + UNUSED void *cb_data) { - bool progress = false; - - nir_foreach_block(block, impl) { - nir_foreach_instr_safe(instr, block) { - switch (instr->type) { - case nir_instr_type_alu: - progress |= lower_alu_instr(nir_instr_as_alu(instr)); - break; - - case nir_instr_type_load_const: { - nir_load_const_instr *load = nir_instr_as_load_const(instr); - if (load->def.bit_size == 1) { - nir_const_value *value = load->value; - for (unsigned i = 0; i < load->def.num_components; i++) - load->value[i].u32 = value[i].b ? NIR_TRUE : NIR_FALSE; - load->def.bit_size = 32; - progress = true; - } - break; - } - - case nir_instr_type_intrinsic: - case nir_instr_type_ssa_undef: - case nir_instr_type_phi: - nir_foreach_ssa_def(instr, rewrite_1bit_ssa_def_to_32bit, - &progress); - break; - - case nir_instr_type_tex: - progress |= lower_tex_instr(nir_instr_as_tex(instr)); - break; - - default: - nir_foreach_ssa_def(instr, assert_ssa_def_is_not_1bit, NULL); - } + switch (instr->type) { + case nir_instr_type_alu: + return lower_alu_instr(nir_instr_as_alu(instr)); + + case nir_instr_type_load_const: { + nir_load_const_instr *load = nir_instr_as_load_const(instr); + if (load->def.bit_size == 1) { + nir_const_value *value = load->value; + for (unsigned i = 0; i < load->def.num_components; i++) + load->value[i].u32 = value[i].b ? NIR_TRUE : NIR_FALSE; + load->def.bit_size = 32; + return true; } + return false; } - if (progress) { - nir_metadata_preserve(impl, nir_metadata_block_index | - nir_metadata_dominance); - } else { - nir_metadata_preserve(impl, nir_metadata_all); + case nir_instr_type_intrinsic: + case nir_instr_type_ssa_undef: + case nir_instr_type_phi: { + bool progress = false; + nir_foreach_ssa_def(instr, rewrite_1bit_ssa_def_to_32bit, &progress); + return progress; } - return progress; + case nir_instr_type_tex: + return lower_tex_instr(nir_instr_as_tex(instr)); + + default: + nir_foreach_ssa_def(instr, assert_ssa_def_is_not_1bit, NULL); + return false; + } } bool nir_lower_bool_to_int32(nir_shader *shader) { - bool progress = false; - - nir_foreach_function(function, shader) { - if (function->impl && nir_lower_bool_to_int32_impl(function->impl)) - progress = true; - } - - return progress; + return nir_shader_instructions_pass(shader, nir_lower_bool_to_int32_instr, + nir_metadata_block_index | + nir_metadata_dominance, + NULL); } -- 2.7.4