nir/lower_vec_to_movs: Convert to use nir_shader_instructions_pass().

Less pass code, less indenting, should be the same perf.

Reviewed-By: Mike Blumenkrantz <michael.blumenkrantz@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6412>
This commit is contained in:
Eric Anholt
2020-08-20 11:51:13 -07:00
committed by Marge Bot
parent a62098fff2
commit e5d4bbd840

View File

@@ -26,6 +26,7 @@
*/
#include "nir.h"
#include "nir_builder.h"
/*
* Implements a simple pass that lowers vecN instructions to a series of
@@ -210,14 +211,10 @@ try_coalesce(nir_alu_instr *vec, unsigned start_idx)
}
static bool
lower_vec_to_movs_block(nir_block *block, nir_function_impl *impl)
nir_lower_vec_to_movs_instr(nir_builder *b, nir_instr *instr, void *data)
{
bool progress = false;
nir_shader *shader = impl->function->shader;
nir_foreach_instr_safe(instr, block) {
if (instr->type != nir_instr_type_alu)
continue;
return false;
nir_alu_instr *vec = nir_instr_as_alu(instr);
@@ -227,13 +224,13 @@ lower_vec_to_movs_block(nir_block *block, nir_function_impl *impl)
case nir_op_vec4:
break;
default:
continue; /* The loop */
return false;
}
bool vec_had_ssa_dest = vec->dest.dest.is_ssa;
if (vec->dest.dest.is_ssa) {
/* Since we insert multiple MOVs, we have a register destination. */
nir_register *reg = nir_local_reg_create(impl);
nir_register *reg = nir_local_reg_create(b->impl);
reg->num_components = vec->dest.dest.ssa.num_components;
reg->bit_size = vec->dest.dest.ssa.bit_size;
@@ -254,7 +251,7 @@ lower_vec_to_movs_block(nir_block *block, nir_function_impl *impl)
continue;
if (src_matches_dest_reg(&vec->dest.dest, &vec->src[i].src)) {
finished_write_mask |= insert_mov(vec, i, shader);
finished_write_mask |= insert_mov(vec, i, b->shader);
break;
}
}
@@ -272,45 +269,21 @@ lower_vec_to_movs_block(nir_block *block, nir_function_impl *impl)
finished_write_mask |= try_coalesce(vec, i);
if (!(finished_write_mask & (1 << i)))
finished_write_mask |= insert_mov(vec, i, shader);
finished_write_mask |= insert_mov(vec, i, b->shader);
}
nir_instr_remove(&vec->instr);
ralloc_free(vec);
progress = true;
}
return progress;
}
static bool
nir_lower_vec_to_movs_impl(nir_function_impl *impl)
{
bool progress = false;
nir_foreach_block(block, impl) {
progress |= lower_vec_to_movs_block(block, impl);
}
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_vec_to_movs(nir_shader *shader)
{
bool progress = false;
nir_foreach_function(function, shader) {
if (function->impl)
progress = nir_lower_vec_to_movs_impl(function->impl) || progress;
}
return progress;
return nir_shader_instructions_pass(shader,
nir_lower_vec_to_movs_instr,
nir_metadata_block_index |
nir_metadata_dominance,
NULL);
}