This will be used by the loop unroll and lcssa passes. V2: - Check instruction count is not too large for unrolling - Add helper for complex loop unrolling --- src/compiler/nir/nir.h | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+)
diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h index 49e8cd8..3a2a13a 100644 --- a/src/compiler/nir/nir.h +++ b/src/compiler/nir/nir.h @@ -2590,6 +2590,37 @@ bool nir_normalize_cubemap_coords(nir_shader *shader); void nir_live_ssa_defs_impl(nir_function_impl *impl); +static inline bool +is_loop_small_enough_to_unroll(nir_shader *shader, nir_loop_info *li) +{ + unsigned max_iter = shader->options->max_unroll_iterations; + + if (li->trip_count > max_iter) + return false; + + if (li->force_unroll) + return true; + + bool loop_not_too_large = + li->num_instructions * li->trip_count <= max_iter * 25; + + return loop_not_too_large; +} + +static inline bool +is_complex_loop(nir_shader *shader, nir_loop_info *li) +{ + unsigned num_lt = list_length(&li->loop_terminator_list); + return is_loop_small_enough_to_unroll(shader, li) && num_lt == 2; +} + +static inline bool +is_simple_loop(nir_shader *shader, nir_loop_info *li) +{ + return li->is_trip_count_known && + is_loop_small_enough_to_unroll(shader, li); +} + void nir_loop_analyze_impl(nir_function_impl *impl, nir_variable_mode indirect_mask); -- 2.7.4 _______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev