nir/control_flow: Handle relinking top-level blocks
authorJason Ekstrand <jason.ekstrand@intel.com>
Fri, 18 Dec 2015 19:27:00 +0000 (11:27 -0800)
committerJason Ekstrand <jason.ekstrand@intel.com>
Wed, 23 Dec 2015 21:49:56 +0000 (13:49 -0800)
This can happen if a function ends in a return instruction and you remove
the return.

src/glsl/nir/nir_control_flow.c

index 96395a4161564c66cf22a3445e2e2b51d6d01b11..ecd9cbd41739a4d46560e393a6dd80d2692c8551 100644 (file)
@@ -336,8 +336,7 @@ block_add_normal_succs(nir_block *block)
          nir_block *next_block = nir_cf_node_as_block(next);
 
          link_blocks(block, next_block, NULL);
-      } else {
-         assert(parent->type == nir_cf_node_loop);
+      } else if (parent->type == nir_cf_node_loop) {
          nir_loop *loop = nir_cf_node_as_loop(parent);
 
          nir_cf_node *head = nir_loop_first_cf_node(loop);
@@ -346,6 +345,10 @@ block_add_normal_succs(nir_block *block)
 
          link_blocks(block, head_block, NULL);
          insert_phi_undef(head_block, block);
+      } else {
+         assert(parent->type == nir_cf_node_function);
+         nir_function_impl *impl = nir_cf_node_as_function(parent);
+         link_blocks(block, impl->end_block, NULL);
       }
    } else {
       nir_cf_node *next = nir_cf_node_next(&block->cf_node);