nir/cf: reimplement nir_cf_node_remove() using the new API
authorConnor Abbott <cwabbott0@gmail.com>
Wed, 22 Jul 2015 02:54:35 +0000 (19:54 -0700)
committerKenneth Graunke <kenneth@whitecape.org>
Mon, 24 Aug 2015 20:31:42 +0000 (13:31 -0700)
This gives us some testing of it. Also, the old nir_cf_node_remove()
wasn't handling phi nodes correctly and was calling cleanup_cf_node()
too late.

Signed-off-by: Connor Abbott <connor.w.abbott@intel.com>
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
src/glsl/nir/nir_control_flow.c
src/glsl/nir/nir_control_flow.h

index 786413843b66a258c871226e6668f1ced2f9f004..86c7ca2bebaf63a66a35a42451654e5430c8e457 100644 (file)
@@ -708,37 +708,6 @@ cleanup_cf_node(nir_cf_node *node, nir_function_impl *impl)
    }
 }
 
-void
-nir_cf_node_remove(nir_cf_node *node)
-{
-   nir_function_impl *impl = nir_cf_node_get_function(node);
-   nir_metadata_preserve(impl, nir_metadata_none);
-
-   if (node->type == nir_cf_node_block) {
-      /*
-       * Basic blocks can't really be removed by themselves, since they act as
-       * padding between the non-basic blocks. So all we do here is empty the
-       * block of instructions.
-       *
-       * TODO: could we assert here?
-       */
-      exec_list_make_empty(&nir_cf_node_as_block(node)->instr_list);
-   } else {
-      nir_cf_node *before = nir_cf_node_prev(node);
-      assert(before->type == nir_cf_node_block);
-      nir_block *before_block = nir_cf_node_as_block(before);
-
-      nir_cf_node *after = nir_cf_node_next(node);
-      assert(after->type == nir_cf_node_block);
-      nir_block *after_block = nir_cf_node_as_block(after);
-
-      exec_node_remove(&node->node);
-      stitch_blocks(before_block, after_block);
-   }
-
-   cleanup_cf_node(node, impl);
-}
-
 void
 nir_cf_extract(nir_cf_list *extracted, nir_cursor begin, nir_cursor end)
 {
index 45aff3e61be653b8cb99132c5e3b8097a324c7c2..5efd41caadff208e90ce97da75f753b657fffc42 100644 (file)
@@ -167,8 +167,6 @@ nir_cf_node_insert_end(struct exec_list *list, nir_cf_node *node)
    nir_cf_node_insert(nir_after_cf_list(list), node);
 }
 
-/** removes a control flow node, doing any cleanup necessary */
-void nir_cf_node_remove(nir_cf_node *node);
 
 /** Control flow motion.
  *
@@ -239,6 +237,15 @@ nir_cf_list_extract(nir_cf_list *extracted, struct exec_list *cf_list)
                   nir_after_cf_list(cf_list));
 }
 
+/** removes a control flow node, doing any cleanup necessary */
+static inline void
+nir_cf_node_remove(nir_cf_node *node)
+{
+   nir_cf_list list;
+   nir_cf_extract(&list, nir_before_cf_node(node), nir_after_cf_node(node));
+   nir_cf_delete(&list);
+}
+
 #ifdef __cplusplus
 }
 #endif