nir: allow specifying a set of opcodes in lower_alu_to_scalar
authorJonathan Marek <jonathan@marek.ca>
Wed, 8 May 2019 16:45:48 +0000 (12:45 -0400)
committerJonathan Marek <jonathan@marek.ca>
Fri, 10 May 2019 15:10:41 +0000 (15:10 +0000)
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>
12 files changed:
src/amd/vulkan/radv_shader.c
src/broadcom/compiler/nir_to_vir.c
src/compiler/nir/nir.h
src/compiler/nir/nir_lower_alu_to_scalar.c
src/freedreno/ir3/ir3_nir.c
src/gallium/auxiliary/nir/tgsi_to_nir.c
src/gallium/drivers/lima/lima_program.c
src/gallium/drivers/nouveau/codegen/nv50_ir_from_nir.cpp
src/gallium/drivers/radeonsi/si_shader_nir.c
src/gallium/drivers/vc4/vc4_program.c
src/intel/compiler/brw_nir.c
src/mesa/state_tracker/st_glsl_to_nir.cpp

index f60daf6d03d3a0167f2f7578c92a8a383ccc81c6..17d6c5bc33adeff28116e7354b0fbdfb08368129 100644 (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(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);
                 NIR_PASS_V(shader, nir_lower_phis_to_scalar);
 
                 NIR_PASS(progress, shader, nir_copy_prop);
index 67747b14bb078e4a5fbdaea922e362aefe8ce3fc..f392d431a4d1973240cad54a98c8c3be8b132275 100644 (file)
@@ -1310,7 +1310,7 @@ v3d_optimize_nir(struct nir_shader *s)
                 progress = false;
 
                 NIR_PASS_V(s, nir_lower_vars_to_ssa);
                 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);
                 NIR_PASS(progress, s, nir_lower_phis_to_scalar);
                 NIR_PASS(progress, s, nir_copy_prop);
                 NIR_PASS(progress, s, nir_opt_remove_phis);
index 301cc76e401474cb5fc8486b646daa387c291e21..8441c9f26c5fcc6cf12254ef275e862ce5ea608d 100644 (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_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);
 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);
index 9b175878c1549a042fd515db2db98b41bed5f32c..71389c2f0c38ff8a18ee1671b718502988db5870 100644 (file)
@@ -74,7 +74,7 @@ lower_reduction(nir_alu_instr *instr, nir_op chan_op, nir_op merge_op,
 }
 
 static bool
 }
 
 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;
 {
    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;
 
    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: \
 #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
 }
 
 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);
 {
    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),
       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
 }
 
 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)
 {
    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;
    }
 
    return progress;
index c692274d8e31a9fdabc4bd2e4b5102ef9f088ec3..8d2eef94e57cbd8d8571c98040a99d8b544fd404 100644 (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);
                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);
                progress |= OPT(s, nir_lower_phis_to_scalar);
 
                progress |= OPT(s, nir_copy_prop);
index c55e8b84a41140148b38ef3112ab9836c6b34440..aa9321f2be4f1cdb8faecf54de66e95270478f6c 100644 (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_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);
       }
 
          NIR_PASS_V(nir, nir_lower_phis_to_scalar);
       }
 
index e56912d8e218d7f3300ecee47ce0f79e5107066c..08bedb1dd32d9ce92afae9ffed6cd36ec58fd8f7 100644 (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);
       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);
       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);
       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);
       NIR_PASS(progress, s, nir_lower_phis_to_scalar);
       NIR_PASS(progress, s, nir_copy_prop);
       NIR_PASS(progress, s, nir_opt_remove_phis);
index 27381ee5ea667ff21147abd0d8af891eedb42eb0..02ae5d73b996cd106e9d91beda8150b93bc6579f 100644 (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_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 {
    NIR_PASS_V(nir, nir_lower_phis_to_scalar);
 
    do {
index 8468ae90dde658de50ad8050fc2b077b606c8f47..10e72fd9f4d244f14928650aedc0bd1bc1fc50d0 100644 (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(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. */
                NIR_PASS_V(nir, nir_lower_phis_to_scalar);
 
                /* (Constant) copy propagation is needed for txf with offsets. */
index 456af3a33d2ccc13f2cda84de07db3ded320ef0a..ca94619826f5b2d21723a6976e1ecf388e5b7653 100644 (file)
@@ -1536,7 +1536,7 @@ vc4_optimize_nir(struct nir_shader *s)
                 progress = false;
 
                 NIR_PASS_V(s, nir_lower_vars_to_ssa);
                 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);
                 NIR_PASS(progress, s, nir_lower_phis_to_scalar);
                 NIR_PASS(progress, s, nir_copy_prop);
                 NIR_PASS(progress, s, nir_opt_remove_phis);
index e1f5b28d874a62d9cbdc5b9ae6c63e58861b5277..a057f286ea865ca7d16829b6a70525f8d356ed8a 100644 (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_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);
       }
 
       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) {
    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)
    }
 
    if (nir->info.stage == MESA_SHADER_GEOMETRY)
index 57064251313c2dc23a40e953ca9f9485717926cf..a87284ef2a7e899b61714b8e0e778e5e7f07b793 100644 (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_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);
       }
 
          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_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 */
    }
 
    /* before buffers and vars_to_ssa */