nir/cf: add split_block_before_instr()
authorConnor Abbott <cwabbott0@gmail.com>
Wed, 22 Jul 2015 02:54:31 +0000 (19:54 -0700)
committerKenneth Graunke <kenneth@whitecape.org>
Mon, 24 Aug 2015 20:31:42 +0000 (13:31 -0700)
Signed-off-by: Connor Abbott <connor.w.abbott@intel.com>
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
src/glsl/nir/nir_control_flow.c

index 9ae113f3959d385f25d0dbc19c65cc4e79d1d484..fcdabc75a82713e5187185e5130adbf51cfc8f96 100644 (file)
@@ -376,6 +376,24 @@ split_block_end(nir_block *block)
    return new_block;
 }
 
+static nir_block *
+split_block_before_instr(nir_instr *instr)
+{
+   assert(instr->type != nir_instr_type_phi);
+   nir_block *new_block = split_block_beginning(instr->block);
+
+   nir_foreach_instr_safe(instr->block, cur_instr) {
+      if (cur_instr == instr)
+         break;
+
+      exec_node_remove(&cur_instr->node);
+      cur_instr->block = new_block;
+      exec_list_push_tail(&new_block->instr_list, &cur_instr->node);
+   }
+
+   return new_block;
+}
+
 /**
  * Inserts a non-basic block between two basic blocks and links them together.
  */