*/
/*@{*/
-static bool
-block_ends_in_jump(nir_block *block)
-{
- return !exec_list_is_empty(&block->instr_list) &&
- nir_block_last_instr(block)->type == nir_instr_type_jump;
-}
-
static inline void
block_add_pred(nir_block *block, nir_block *pred)
{
nir_block *last_then_block = nir_if_last_then_block(if_stmt);
nir_block *last_else_block = nir_if_last_else_block(if_stmt);
- if (!block_ends_in_jump(last_then_block)) {
+ if (!nir_block_ends_in_jump(last_then_block)) {
unlink_block_successors(last_then_block);
link_blocks(last_then_block, block, NULL);
}
- if (!block_ends_in_jump(last_else_block)) {
+ if (!nir_block_ends_in_jump(last_else_block)) {
unlink_block_successors(last_else_block);
link_blocks(last_else_block, block, NULL);
}
new_block->cf_node.parent = block->cf_node.parent;
exec_node_insert_node_before(&block->cf_node.node, &new_block->cf_node.node);
- struct set_entry *entry;
set_foreach(block->predecessors, entry) {
nir_block *pred = (nir_block *) entry->key;
replace_successor(pred, block, new_block);
}
/* Any phi nodes must stay part of the new block, or else their
- * sourcse will be messed up. This will reverse the order of the phis, but
- * order shouldn't matter.
+ * sources will be messed up.
*/
nir_foreach_instr_safe(instr, block) {
if (instr->type != nir_instr_type_phi)
exec_node_remove(&instr->node);
instr->block = new_block;
- exec_list_push_head(&new_block->instr_list, &instr->node);
+ exec_list_push_tail(&new_block->instr_list, &instr->node);
}
return new_block;
new_block->cf_node.parent = block->cf_node.parent;
exec_node_insert_after(&block->cf_node.node, &new_block->cf_node.node);
- if (block_ends_in_jump(block)) {
+ if (nir_block_ends_in_jump(block)) {
/* Figure out what successor block would've had if it didn't have a jump
* instruction, and make new_block have that successor.
*/
return nir_cf_node_as_loop(node);
}
+static void
+remove_phi_src(nir_block *block, nir_block *pred)
+{
+ nir_foreach_instr(instr, block) {
+ if (instr->type != nir_instr_type_phi)
+ break;
+
+ nir_phi_instr *phi = nir_instr_as_phi(instr);
+ nir_foreach_phi_src_safe(src, phi) {
+ if (src->pred == pred) {
+ list_del(&src->src.use_link);
+ exec_node_remove(&src->node);
+ }
+ }
+ }
+}
+
/*
* update the CFG after a jump instruction has been added to the end of a block
*/
nir_instr *instr = nir_block_last_instr(block);
nir_jump_instr *jump_instr = nir_instr_as_jump(instr);
+ if (block->successors[0])
+ remove_phi_src(block->successors[0], block);
+ if (block->successors[1])
+ remove_phi_src(block->successors[1], block);
unlink_block_successors(block);
nir_function_impl *impl = nir_cf_node_get_function(&block->cf_node);
}
}
-static void
-remove_phi_src(nir_block *block, nir_block *pred)
-{
- nir_foreach_instr(instr, block) {
- if (instr->type != nir_instr_type_phi)
- break;
-
- nir_phi_instr *phi = nir_instr_as_phi(instr);
- nir_foreach_phi_src_safe(src, phi) {
- if (src->pred == pred) {
- list_del(&src->src.use_link);
- exec_node_remove(&src->node);
- }
- }
- }
-}
-
/* Removes the successor of a block with a jump. Note that the jump to be
* eliminated may be free-floating.
*/
* TODO: special case when before is empty and after isn't?
*/
- if (block_ends_in_jump(before)) {
+ if (nir_block_ends_in_jump(before)) {
assert(exec_list_is_empty(&after->instr_list));
if (after->successors[0])
remove_phi_src(after->successors[0], after);
* already been setup with the correct successors, so we need to set
* up jumps here as the block is being inserted.
*/
- if (block_ends_in_jump(block))
+ if (nir_block_ends_in_jump(block))
nir_handle_add_jump(block);
stitch_blocks(block, after);