[Mesa-dev] [PATCH 04/11] nir: add helpers to check if we can unroll loops

Timothy Arceri timothy.arceri at collabora.com
Fri Sep 16 13:24:22 UTC 2016


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 4272051..cc8f4b6 100644
--- a/src/compiler/nir/nir.h
+++ b/src/compiler/nir/nir.h
@@ -2601,6 +2601,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



More information about the mesa-dev mailing list