<div dir="ltr"><div>I haven't checked the details</div><div><br></div><div>Acked-by: Jason Ekstrand <<a href="mailto:jason@jlekstrand.net">jason@jlekstrand.net</a>><br></div></div><br><div class="gmail_quote"><div dir="ltr">On Thu, Dec 6, 2018 at 9:08 PM Timothy Arceri <<a href="mailto:tarceri@itsqueeze.com">tarceri@itsqueeze.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Reviewed-by: Thomas Helland <<a href="mailto:thomashelland90@gmail.com" target="_blank">thomashelland90@gmail.com</a>><br>
---<br>
 src/compiler/nir/nir_opt_loop_unroll.c | 115 ++++++++++++++-----------<br>
 1 file changed, 64 insertions(+), 51 deletions(-)<br>
<br>
diff --git a/src/compiler/nir/nir_opt_loop_unroll.c b/src/compiler/nir/nir_opt_loop_unroll.c<br>
index c267c185b6..8406880204 100644<br>
--- a/src/compiler/nir/nir_opt_loop_unroll.c<br>
+++ b/src/compiler/nir/nir_opt_loop_unroll.c<br>
@@ -236,6 +236,65 @@ get_complex_unroll_insert_location(nir_cf_node *node, bool continue_from_then)<br>
    }<br>
 }<br>
<br>
+static nir_cf_node *<br>
+complex_unroll_loop_body(nir_loop *loop, nir_loop_terminator *unlimit_term,<br>
+                         nir_cf_list *lp_header, nir_cf_list *lp_body,<br>
+                         struct hash_table *remap_table,<br>
+                         unsigned num_times_to_clone)<br>
+{<br>
+   /* In the terminator that we have no trip count for move everything after<br>
+    * the terminator into the continue from branch.<br>
+    */<br>
+   nir_cf_list loop_end;<br>
+   nir_cf_extract(&loop_end, nir_after_cf_node(&unlimit_term->nif->cf_node),<br>
+                  nir_after_block(nir_loop_last_block(loop)));<br>
+   move_cf_list_into_loop_term(&loop_end, unlimit_term);<br>
+<br>
+   /* Pluck out the loop body. */<br>
+   nir_cf_extract(lp_body, nir_before_block(nir_loop_first_block(loop)),<br>
+                  nir_after_block(nir_loop_last_block(loop)));<br>
+<br>
+   /* Set unroll_loc to the loop as we will insert the unrolled loop before it<br>
+    */<br>
+   nir_cf_node *unroll_loc = &loop->cf_node;<br>
+<br>
+   /* Temp list to store the cloned loop as we unroll */<br>
+   nir_cf_list unrolled_lp_body;<br>
+<br>
+   for (unsigned i = 0; i < num_times_to_clone; i++) {<br>
+<br>
+      nir_cursor cursor =<br>
+         get_complex_unroll_insert_location(unroll_loc,<br>
+                                            unlimit_term->continue_from_then);<br>
+<br>
+      /* Clone loop header and insert in if branch */<br>
+      nir_cf_list_clone_and_reinsert(lp_header, loop->cf_node.parent,<br>
+                                     cursor, remap_table);<br>
+<br>
+      cursor =<br>
+         get_complex_unroll_insert_location(unroll_loc,<br>
+                                            unlimit_term->continue_from_then);<br>
+<br>
+      /* Clone loop body */<br>
+      nir_cf_list_clone(&unrolled_lp_body, lp_body, loop->cf_node.parent,<br>
+                        remap_table);<br>
+<br>
+      unroll_loc = exec_node_data(nir_cf_node,<br>
+                                  exec_list_get_tail(&unrolled_lp_body.list),<br>
+                                  node);<br>
+      assert(unroll_loc->type == nir_cf_node_block &&<br>
+             exec_list_is_empty(&nir_cf_node_as_block(unroll_loc)->instr_list));<br>
+<br>
+      /* Get the unrolled if node */<br>
+      unroll_loc = nir_cf_node_prev(unroll_loc);<br>
+<br>
+      /* Insert unrolled loop body */<br>
+      nir_cf_reinsert(&unrolled_lp_body, cursor);<br>
+   }<br>
+<br>
+   return unroll_loc;<br>
+}<br>
+<br>
 /**<br>
  * Unroll a loop with two exists when the trip count of one of the exits is<br>
  * unknown.  If continue_from_then is true, the loop is repeated only when the<br>
@@ -358,60 +417,14 @@ complex_unroll(nir_loop *loop, nir_loop_terminator *unlimit_term,<br>
       num_times_to_clone = loop->info->max_trip_count;<br>
    }<br>
<br>
-   /* In the terminator that we have no trip count for move everything after<br>
-    * the terminator into the continue from branch.<br>
-    */<br>
-   nir_cf_list loop_end;<br>
-   nir_cf_extract(&loop_end, nir_after_cf_node(&unlimit_term->nif->cf_node),<br>
-                  nir_after_block(nir_loop_last_block(loop)));<br>
-   move_cf_list_into_loop_term(&loop_end, unlimit_term);<br>
-<br>
-   /* Pluck out the loop body. */<br>
-   nir_cf_list loop_body;<br>
-   nir_cf_extract(&loop_body, nir_before_block(nir_loop_first_block(loop)),<br>
-                  nir_after_block(nir_loop_last_block(loop)));<br>
-<br>
    struct hash_table *remap_table =<br>
       _mesa_hash_table_create(NULL, _mesa_hash_pointer,<br>
                               _mesa_key_pointer_equal);<br>
<br>
-   /* Set unroll_loc to the loop as we will insert the unrolled loop before it<br>
-    */<br>
-   nir_cf_node *unroll_loc = &loop->cf_node;<br>
-<br>
-   /* Temp lists to store the cloned loop as we unroll */<br>
-   nir_cf_list unrolled_lp_body;<br>
-<br>
-   for (unsigned i = 0; i < num_times_to_clone; i++) {<br>
-<br>
-      nir_cursor cursor =<br>
-         get_complex_unroll_insert_location(unroll_loc,<br>
-                                            unlimit_term->continue_from_then);<br>
-<br>
-      /* Clone loop header and insert in if branch */<br>
-      nir_cf_list_clone_and_reinsert(&lp_header, loop->cf_node.parent,<br>
-                                     cursor, remap_table);<br>
-<br>
-      cursor =<br>
-         get_complex_unroll_insert_location(unroll_loc,<br>
-                                            unlimit_term->continue_from_then);<br>
-<br>
-      /* Clone loop body */<br>
-      nir_cf_list_clone(&unrolled_lp_body, &loop_body, loop->cf_node.parent,<br>
-                        remap_table);<br>
-<br>
-      unroll_loc = exec_node_data(nir_cf_node,<br>
-                                  exec_list_get_tail(&unrolled_lp_body.list),<br>
-                                  node);<br>
-      assert(unroll_loc->type == nir_cf_node_block &&<br>
-             exec_list_is_empty(&nir_cf_node_as_block(unroll_loc)->instr_list));<br>
-<br>
-      /* Get the unrolled if node */<br>
-      unroll_loc = nir_cf_node_prev(unroll_loc);<br>
-<br>
-      /* Insert unrolled loop body */<br>
-      nir_cf_reinsert(&unrolled_lp_body, cursor);<br>
-   }<br>
+   nir_cf_list lp_body;<br>
+   nir_cf_node *unroll_loc =<br>
+      complex_unroll_loop_body(loop, unlimit_term, &lp_header, &lp_body,<br>
+                               remap_table, num_times_to_clone);<br>
<br>
    if (!limiting_term_second) {<br>
       assert(unroll_loc->type == nir_cf_node_if);<br>
@@ -442,7 +455,7 @@ complex_unroll(nir_loop *loop, nir_loop_terminator *unlimit_term,<br>
<br>
    /* Delete the original loop header and body */<br>
    nir_cf_delete(&lp_header);<br>
-   nir_cf_delete(&loop_body);<br>
+   nir_cf_delete(&lp_body);<br>
<br>
    _mesa_hash_table_destroy(remap_table, NULL);<br>
 }<br>
-- <br>
2.19.2<br>
<br>
_______________________________________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org" target="_blank">mesa-dev@lists.freedesktop.org</a><br>
<a href="https://lists.freedesktop.org/mailman/listinfo/mesa-dev" rel="noreferrer" target="_blank">https://lists.freedesktop.org/mailman/listinfo/mesa-dev</a><br>
</blockquote></div>