[Mesa-dev] [PATCH 11/13] nir: make cleanup_cf_node() accessable externally

Timothy Arceri timothy.arceri at collabora.com
Mon Aug 29 04:59:19 UTC 2016


We also allow unlinking of jumps to be skipped, this will be useful
for removing loops once they have been unrolled.
---
 src/compiler/nir/nir_control_flow.c | 23 ++++++++++++++---------
 src/compiler/nir/nir_control_flow.h |  4 ++++
 2 files changed, 18 insertions(+), 9 deletions(-)

diff --git a/src/compiler/nir/nir_control_flow.c b/src/compiler/nir/nir_control_flow.c
index ed8cd24..0429abd 100644
--- a/src/compiler/nir/nir_control_flow.c
+++ b/src/compiler/nir/nir_control_flow.c
@@ -698,8 +698,9 @@ replace_ssa_def_uses(nir_ssa_def *def, void *void_impl)
    return true;
 }
 
-static void
-cleanup_cf_node(nir_cf_node *node, nir_function_impl *impl)
+void
+nir_cleanup_cf_node(nir_cf_node *node, nir_function_impl *impl,
+                    bool unlink_jumps)
 {
    switch (node->type) {
    case nir_cf_node_block: {
@@ -707,8 +708,12 @@ cleanup_cf_node(nir_cf_node *node, nir_function_impl *impl)
       /* We need to walk the instructions and clean up defs/uses */
       nir_foreach_instr_safe(instr, block) {
          if (instr->type == nir_instr_type_jump) {
-            nir_jump_type jump_type = nir_instr_as_jump(instr)->type;
-            unlink_jump(block, jump_type, false);
+            if (unlink_jumps) {
+               nir_jump_type jump_type = nir_instr_as_jump(instr)->type;
+               unlink_jump(block, jump_type, false);
+            } else {
+               exec_node_remove(&instr->node);
+            }
          } else {
             nir_foreach_ssa_def(instr, replace_ssa_def_uses, impl);
             nir_instr_remove(instr);
@@ -720,9 +725,9 @@ cleanup_cf_node(nir_cf_node *node, nir_function_impl *impl)
    case nir_cf_node_if: {
       nir_if *if_stmt = nir_cf_node_as_if(node);
       foreach_list_typed(nir_cf_node, child, node, &if_stmt->then_list)
-         cleanup_cf_node(child, impl);
+         nir_cleanup_cf_node(child, impl, unlink_jumps);
       foreach_list_typed(nir_cf_node, child, node, &if_stmt->else_list)
-         cleanup_cf_node(child, impl);
+         nir_cleanup_cf_node(child, impl, unlink_jumps);
 
       list_del(&if_stmt->condition.use_link);
       break;
@@ -731,13 +736,13 @@ cleanup_cf_node(nir_cf_node *node, nir_function_impl *impl)
    case nir_cf_node_loop: {
       nir_loop *loop = nir_cf_node_as_loop(node);
       foreach_list_typed(nir_cf_node, child, node, &loop->body)
-         cleanup_cf_node(child, impl);
+         nir_cleanup_cf_node(child, impl, unlink_jumps);
       break;
    }
    case nir_cf_node_function: {
       nir_function_impl *impl = nir_cf_node_as_function(node);
       foreach_list_typed(nir_cf_node, child, node, &impl->body)
-         cleanup_cf_node(child, impl);
+         nir_cleanup_cf_node(child, impl, unlink_jumps);
       break;
    }
    default:
@@ -847,6 +852,6 @@ void
 nir_cf_delete(nir_cf_list *cf_list)
 {
    foreach_list_typed(nir_cf_node, node, node, &cf_list->list) {
-      cleanup_cf_node(node, cf_list->impl);
+      nir_cleanup_cf_node(node, cf_list->impl, true);
    }
 }
diff --git a/src/compiler/nir/nir_control_flow.h b/src/compiler/nir/nir_control_flow.h
index 0d97486..a7d0b81 100644
--- a/src/compiler/nir/nir_control_flow.h
+++ b/src/compiler/nir/nir_control_flow.h
@@ -138,6 +138,10 @@ typedef struct {
    nir_function_impl *impl; /* for cleaning up if the list is deleted */
 } nir_cf_list;
 
+void
+nir_cleanup_cf_node(nir_cf_node *node, nir_function_impl *impl,
+                    bool unlink_jumps);
+
 void nir_cf_extract(nir_cf_list *extracted, nir_cursor begin, nir_cursor end);
 
 void nir_cf_reinsert(nir_cf_list *cf_list, nir_cursor cursor);
-- 
2.7.4



More information about the mesa-dev mailing list