nir_shader *
brw_nir_optimize(nir_shader *nir, const struct brw_compiler *compiler,
- bool is_scalar)
+ bool is_scalar, bool allow_copies)
{
nir_variable_mode indirect_mask =
brw_nir_no_indirect_mask(compiler, nir->info.stage);
OPT(nir_split_array_vars, nir_var_local);
OPT(nir_shrink_vec_array_vars, nir_var_local);
OPT(nir_lower_vars_to_ssa);
+ if (allow_copies) {
+ /* Only run this pass in the first call to brw_nir_optimize. Later
+ * calls assume that we've lowered away any copy_deref instructions
+ * and we don't want to introduce any more.
+ */
+ OPT(nir_opt_find_array_copies);
+ }
OPT(nir_opt_copy_prop_vars);
if (is_scalar) {
nir_lower_isign64 |
nir_lower_divmod64);
- nir = brw_nir_optimize(nir, compiler, is_scalar);
+ nir = brw_nir_optimize(nir, compiler, is_scalar, true);
/* This needs to be run after the first optimization pass but before we
* lower indirect derefs away
nir_lower_indirect_derefs(nir, indirect_mask);
/* Get rid of split copies */
- nir = brw_nir_optimize(nir, compiler, is_scalar);
+ nir = brw_nir_optimize(nir, compiler, is_scalar, false);
OPT(nir_remove_dead_variables, nir_var_local);
nir_validate_shader(*producer);
nir_validate_shader(*consumer);
+ const bool p_is_scalar =
+ compiler->scalar_stage[(*producer)->info.stage];
+ const bool c_is_scalar =
+ compiler->scalar_stage[(*consumer)->info.stage];
+
+ if (p_is_scalar && c_is_scalar) {
+ NIR_PASS_V(*producer, nir_lower_io_to_scalar_early, nir_var_shader_out);
+ NIR_PASS_V(*consumer, nir_lower_io_to_scalar_early, nir_var_shader_in);
+ *producer = brw_nir_optimize(*producer, compiler, p_is_scalar, false);
+ *consumer = brw_nir_optimize(*consumer, compiler, c_is_scalar, false);
+ }
+
NIR_PASS_V(*producer, nir_remove_dead_variables, nir_var_shader_out);
NIR_PASS_V(*consumer, nir_remove_dead_variables, nir_var_shader_in);
NIR_PASS_V(*consumer, nir_lower_indirect_derefs,
brw_nir_no_indirect_mask(compiler, (*consumer)->info.stage));
- const bool p_is_scalar =
- compiler->scalar_stage[(*producer)->info.stage];
- *producer = brw_nir_optimize(*producer, compiler, p_is_scalar);
-
- const bool c_is_scalar =
- compiler->scalar_stage[(*consumer)->info.stage];
- *consumer = brw_nir_optimize(*consumer, compiler, c_is_scalar);
+ *producer = brw_nir_optimize(*producer, compiler, p_is_scalar, false);
+ *consumer = brw_nir_optimize(*consumer, compiler, c_is_scalar, false);
}
}
OPT(nir_opt_algebraic_before_ffma);
} while (progress);
- nir = brw_nir_optimize(nir, compiler, is_scalar);
+ nir = brw_nir_optimize(nir, compiler, is_scalar, false);
if (devinfo->gen >= 6) {
/* Try and fuse multiply-adds */
if (nir_lower_tex(nir, &tex_options)) {
nir_validate_shader(nir);
- nir = brw_nir_optimize(nir, compiler, is_scalar);
+ nir = brw_nir_optimize(nir, compiler, is_scalar, false);
}
return nir;