nir: allow specifying a set of opcodes in lower_alu_to_scalar

This can be used by both etnaviv and freedreno/a2xx as they are both vec4
architectures with some instructions being scalar-only.

Signed-off-by: Jonathan Marek <jonathan@marek.ca>
Reviewed-by: Christian Gmeiner <christian.gmeiner@gmail.com>
Reviewed-by: Eric Anholt <eric@anholt.net>
This commit is contained in:
Jonathan Marek
2019-05-08 12:45:48 -04:00
parent f8bda81887
commit d0bff89159
12 changed files with 24 additions and 19 deletions

View File

@@ -150,7 +150,7 @@ radv_optimize_nir(struct nir_shader *shader, bool optimize_conservatively,
NIR_PASS(progress, shader, nir_opt_copy_prop_vars);
NIR_PASS(progress, shader, nir_opt_dead_write_vars);
NIR_PASS_V(shader, nir_lower_alu_to_scalar);
NIR_PASS_V(shader, nir_lower_alu_to_scalar, NULL);
NIR_PASS_V(shader, nir_lower_phis_to_scalar);
NIR_PASS(progress, shader, nir_copy_prop);

View File

@@ -1310,7 +1310,7 @@ v3d_optimize_nir(struct nir_shader *s)
progress = false;
NIR_PASS_V(s, nir_lower_vars_to_ssa);
NIR_PASS(progress, s, nir_lower_alu_to_scalar);
NIR_PASS(progress, s, nir_lower_alu_to_scalar, NULL);
NIR_PASS(progress, s, nir_lower_phis_to_scalar);
NIR_PASS(progress, s, nir_copy_prop);
NIR_PASS(progress, s, nir_opt_remove_phis);

View File

@@ -3178,7 +3178,7 @@ bool nir_lower_alu(nir_shader *shader);
bool nir_lower_flrp(nir_shader *shader, unsigned lowering_mask,
bool always_precise, bool have_ffma);
bool nir_lower_alu_to_scalar(nir_shader *shader);
bool nir_lower_alu_to_scalar(nir_shader *shader, BITSET_WORD *lower_set);
bool nir_lower_bool_to_float(nir_shader *shader);
bool nir_lower_bool_to_int32(nir_shader *shader);
bool nir_lower_int_to_float(nir_shader *shader);

View File

@@ -74,7 +74,7 @@ lower_reduction(nir_alu_instr *instr, nir_op chan_op, nir_op merge_op,
}
static bool
lower_alu_instr_scalar(nir_alu_instr *instr, nir_builder *b)
lower_alu_instr_scalar(nir_alu_instr *instr, nir_builder *b, BITSET_WORD *lower_set)
{
unsigned num_src = nir_op_infos[instr->op].num_inputs;
unsigned i, chan;
@@ -85,6 +85,9 @@ lower_alu_instr_scalar(nir_alu_instr *instr, nir_builder *b)
b->cursor = nir_before_instr(&instr->instr);
b->exact = instr->exact;
if (lower_set && !BITSET_TEST(lower_set, instr->op))
return false;
#define LOWER_REDUCTION(name, chan, merge) \
case name##2: \
case name##3: \
@@ -254,7 +257,7 @@ lower_alu_instr_scalar(nir_alu_instr *instr, nir_builder *b)
}
static bool
nir_lower_alu_to_scalar_impl(nir_function_impl *impl)
nir_lower_alu_to_scalar_impl(nir_function_impl *impl, BITSET_WORD *lower_set)
{
nir_builder builder;
nir_builder_init(&builder, impl);
@@ -264,7 +267,8 @@ nir_lower_alu_to_scalar_impl(nir_function_impl *impl)
nir_foreach_instr_safe(instr, block) {
if (instr->type == nir_instr_type_alu) {
progress = lower_alu_instr_scalar(nir_instr_as_alu(instr),
&builder) || progress;
&builder,
lower_set) || progress;
}
}
}
@@ -276,13 +280,14 @@ nir_lower_alu_to_scalar_impl(nir_function_impl *impl)
}
bool
nir_lower_alu_to_scalar(nir_shader *shader)
nir_lower_alu_to_scalar(nir_shader *shader, BITSET_WORD *lower_set)
{
bool progress = false;
nir_foreach_function(function, shader) {
if (function->impl)
progress = nir_lower_alu_to_scalar_impl(function->impl) || progress;
progress = nir_lower_alu_to_scalar_impl(function->impl,
lower_set) || progress;
}
return progress;

View File

@@ -126,7 +126,7 @@ ir3_optimize_loop(nir_shader *s)
OPT_V(s, nir_lower_vars_to_ssa);
progress |= OPT(s, nir_opt_copy_prop_vars);
progress |= OPT(s, nir_opt_dead_write_vars);
progress |= OPT(s, nir_lower_alu_to_scalar);
progress |= OPT(s, nir_lower_alu_to_scalar, NULL);
progress |= OPT(s, nir_lower_phis_to_scalar);
progress |= OPT(s, nir_copy_prop);

View File

@@ -2050,7 +2050,7 @@ ttn_optimize_nir(nir_shader *nir, bool scalar)
NIR_PASS_V(nir, nir_lower_vars_to_ssa);
if (scalar) {
NIR_PASS_V(nir, nir_lower_alu_to_scalar);
NIR_PASS_V(nir, nir_lower_alu_to_scalar, NULL);
NIR_PASS_V(nir, nir_lower_phis_to_scalar);
}

View File

@@ -97,7 +97,7 @@ lima_program_optimize_vs_nir(struct nir_shader *s)
progress = false;
NIR_PASS_V(s, nir_lower_vars_to_ssa);
NIR_PASS(progress, s, nir_lower_alu_to_scalar);
NIR_PASS(progress, s, nir_lower_alu_to_scalar, NULL);
NIR_PASS(progress, s, nir_lower_phis_to_scalar);
NIR_PASS(progress, s, nir_copy_prop);
NIR_PASS(progress, s, nir_opt_remove_phis);
@@ -135,7 +135,7 @@ lima_program_optimize_fs_nir(struct nir_shader *s)
progress = false;
NIR_PASS_V(s, nir_lower_vars_to_ssa);
//NIR_PASS(progress, s, nir_lower_alu_to_scalar);
//NIR_PASS(progress, s, nir_lower_alu_to_scalar, NULL);
NIR_PASS(progress, s, nir_lower_phis_to_scalar);
NIR_PASS(progress, s, nir_copy_prop);
NIR_PASS(progress, s, nir_opt_remove_phis);

View File

@@ -3437,7 +3437,7 @@ Converter::run()
NIR_PASS_V(nir, nir_lower_regs_to_ssa);
NIR_PASS_V(nir, nir_lower_load_const_to_scalar);
NIR_PASS_V(nir, nir_lower_vars_to_ssa);
NIR_PASS_V(nir, nir_lower_alu_to_scalar);
NIR_PASS_V(nir, nir_lower_alu_to_scalar, NULL);
NIR_PASS_V(nir, nir_lower_phis_to_scalar);
do {

View File

@@ -828,7 +828,7 @@ si_nir_opts(struct nir_shader *nir)
NIR_PASS(progress, nir, nir_opt_copy_prop_vars);
NIR_PASS(progress, nir, nir_opt_dead_write_vars);
NIR_PASS_V(nir, nir_lower_alu_to_scalar);
NIR_PASS_V(nir, nir_lower_alu_to_scalar, NULL);
NIR_PASS_V(nir, nir_lower_phis_to_scalar);
/* (Constant) copy propagation is needed for txf with offsets. */

View File

@@ -1536,7 +1536,7 @@ vc4_optimize_nir(struct nir_shader *s)
progress = false;
NIR_PASS_V(s, nir_lower_vars_to_ssa);
NIR_PASS(progress, s, nir_lower_alu_to_scalar);
NIR_PASS(progress, s, nir_lower_alu_to_scalar, NULL);
NIR_PASS(progress, s, nir_lower_phis_to_scalar);
NIR_PASS(progress, s, nir_copy_prop);
NIR_PASS(progress, s, nir_opt_remove_phis);

View File

@@ -561,7 +561,7 @@ brw_nir_optimize(nir_shader *nir, const struct brw_compiler *compiler,
OPT(nir_opt_combine_stores, nir_var_all);
if (is_scalar) {
OPT(nir_lower_alu_to_scalar);
OPT(nir_lower_alu_to_scalar, NULL);
}
OPT(nir_copy_prop);
@@ -701,7 +701,7 @@ brw_preprocess_nir(const struct brw_compiler *compiler, nir_shader *nir,
const bool is_scalar = compiler->scalar_stage[nir->info.stage];
if (is_scalar) {
OPT(nir_lower_alu_to_scalar);
OPT(nir_lower_alu_to_scalar, NULL);
}
if (nir->info.stage == MESA_SHADER_GEOMETRY)

View File

@@ -315,7 +315,7 @@ st_nir_opts(nir_shader *nir, bool scalar)
NIR_PASS_V(nir, nir_lower_vars_to_ssa);
if (scalar) {
NIR_PASS_V(nir, nir_lower_alu_to_scalar);
NIR_PASS_V(nir, nir_lower_alu_to_scalar, NULL);
NIR_PASS_V(nir, nir_lower_phis_to_scalar);
}
@@ -431,7 +431,7 @@ st_glsl_to_nir(struct st_context *st, struct gl_program *prog,
NIR_PASS_V(nir, nir_lower_var_copies);
if (is_scalar) {
NIR_PASS_V(nir, nir_lower_alu_to_scalar);
NIR_PASS_V(nir, nir_lower_alu_to_scalar, NULL);
}
/* before buffers and vars_to_ssa */