case nir_cf_node_if: {
/* Are we at the end of the if? Go to the beginning of the else */
nir_if *if_stmt = nir_cf_node_as_if(parent);
- if (&block->cf_node == nir_if_last_then_node(if_stmt))
- return nir_cf_node_as_block(nir_if_first_else_node(if_stmt));
+ if (block == nir_if_last_then_block(if_stmt))
+ return nir_if_first_else_block(if_stmt);
- assert(&block->cf_node == nir_if_last_else_node(if_stmt));
+ assert(block == nir_if_last_else_block(if_stmt));
/* fall through */
}
case nir_cf_node_if: {
/* Are we at the beginning of the else? Go to the end of the if */
nir_if *if_stmt = nir_cf_node_as_if(parent);
- if (&block->cf_node == nir_if_first_else_node(if_stmt))
- return nir_cf_node_as_block(nir_if_last_then_node(if_stmt));
+ if (block == nir_if_first_else_block(if_stmt))
+ return nir_if_last_then_block(if_stmt);
- assert(&block->cf_node == nir_if_first_then_node(if_stmt));
+ assert(block == nir_if_first_then_block(if_stmt));
/* fall through */
}
case nir_cf_node_if: {
nir_if *if_stmt = nir_cf_node_as_if(node);
- return nir_cf_node_as_block(nir_if_first_then_node(if_stmt));
+ return nir_if_first_then_block(if_stmt);
}
case nir_cf_node_loop: {
nir_loop *loop = nir_cf_node_as_loop(node);
- return nir_cf_node_as_block(nir_loop_first_cf_node(loop));
+ return nir_loop_first_block(loop);
}
case nir_cf_node_block: {
case nir_cf_node_if: {
nir_if *if_stmt = nir_cf_node_as_if(node);
- return nir_cf_node_as_block(nir_if_last_else_node(if_stmt));
+ return nir_if_last_else_block(if_stmt);
}
case nir_cf_node_loop: {
nir_loop *loop = nir_cf_node_as_loop(node);
- return nir_cf_node_as_block(nir_loop_last_cf_node(loop));
+ return nir_loop_last_block(loop);
}
case nir_cf_node_block: {
struct exec_list else_list; /** < list of nir_cf_node */
} nir_if;
-static inline nir_cf_node *
-nir_if_first_then_node(nir_if *if_stmt)
-{
- struct exec_node *head = exec_list_get_head(&if_stmt->then_list);
- return exec_node_data(nir_cf_node, head, node);
-}
-
-static inline nir_cf_node *
-nir_if_last_then_node(nir_if *if_stmt)
-{
- struct exec_node *tail = exec_list_get_tail(&if_stmt->then_list);
- return exec_node_data(nir_cf_node, tail, node);
-}
-
-static inline nir_cf_node *
-nir_if_first_else_node(nir_if *if_stmt)
-{
- struct exec_node *head = exec_list_get_head(&if_stmt->else_list);
- return exec_node_data(nir_cf_node, head, node);
-}
-
-static inline nir_cf_node *
-nir_if_last_else_node(nir_if *if_stmt)
-{
- struct exec_node *tail = exec_list_get_tail(&if_stmt->else_list);
- return exec_node_data(nir_cf_node, tail, node);
-}
-
typedef struct {
nir_cf_node cf_node;
struct exec_list body; /** < list of nir_cf_node */
} nir_loop;
-static inline nir_cf_node *
-nir_loop_first_cf_node(nir_loop *loop)
-{
- return exec_node_data(nir_cf_node, exec_list_get_head(&loop->body), node);
-}
-
-static inline nir_cf_node *
-nir_loop_last_cf_node(nir_loop *loop)
-{
- return exec_node_data(nir_cf_node, exec_list_get_tail(&loop->body), node);
-}
-
/**
* Various bits of metadata that can may be created or required by
* optimization and analysis passes
NIR_DEFINE_CAST(nir_cf_node_as_function, nir_cf_node,
nir_function_impl, cf_node, type, nir_cf_node_function)
+static inline nir_block *
+nir_if_first_then_block(nir_if *if_stmt)
+{
+ struct exec_node *head = exec_list_get_head(&if_stmt->then_list);
+ return nir_cf_node_as_block(exec_node_data(nir_cf_node, head, node));
+}
+
+static inline nir_block *
+nir_if_last_then_block(nir_if *if_stmt)
+{
+ struct exec_node *tail = exec_list_get_tail(&if_stmt->then_list);
+ return nir_cf_node_as_block(exec_node_data(nir_cf_node, tail, node));
+}
+
+static inline nir_block *
+nir_if_first_else_block(nir_if *if_stmt)
+{
+ struct exec_node *head = exec_list_get_head(&if_stmt->else_list);
+ return nir_cf_node_as_block(exec_node_data(nir_cf_node, head, node));
+}
+
+static inline nir_block *
+nir_if_last_else_block(nir_if *if_stmt)
+{
+ struct exec_node *tail = exec_list_get_tail(&if_stmt->else_list);
+ return nir_cf_node_as_block(exec_node_data(nir_cf_node, tail, node));
+}
+
+static inline nir_block *
+nir_loop_first_block(nir_loop *loop)
+{
+ struct exec_node *head = exec_list_get_head(&loop->body);
+ return nir_cf_node_as_block(exec_node_data(nir_cf_node, head, node));
+}
+
+static inline nir_block *
+nir_loop_last_block(nir_loop *loop)
+{
+ struct exec_node *tail = exec_list_get_tail(&loop->body);
+ return nir_cf_node_as_block(exec_node_data(nir_cf_node, tail, node));
+}
+
typedef enum {
nir_parameter_in,
nir_parameter_out,
nir_if *if_stmt = nir_cf_node_as_if(node);
- nir_cf_node *last_then = nir_if_last_then_node(if_stmt);
- assert(last_then->type == nir_cf_node_block);
- nir_block *last_then_block = nir_cf_node_as_block(last_then);
-
- nir_cf_node *last_else = nir_if_last_else_node(if_stmt);
- assert(last_else->type == nir_cf_node_block);
- nir_block *last_else_block = nir_cf_node_as_block(last_else);
+ 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)) {
unlink_block_successors(last_then_block);
nir_if *if_stmt = nir_cf_node_as_if(node);
- nir_cf_node *first_then = nir_if_first_then_node(if_stmt);
- assert(first_then->type == nir_cf_node_block);
- nir_block *first_then_block = nir_cf_node_as_block(first_then);
-
- nir_cf_node *first_else = nir_if_first_else_node(if_stmt);
- assert(first_else->type == nir_cf_node_block);
- nir_block *first_else_block = nir_cf_node_as_block(first_else);
+ nir_block *first_then_block = nir_if_first_then_block(if_stmt);
+ nir_block *first_else_block = nir_if_first_else_block(if_stmt);
unlink_block_successors(block);
link_blocks(block, first_then_block, first_else_block);
nir_loop *loop = nir_cf_node_as_loop(node);
- nir_cf_node *loop_header = nir_loop_first_cf_node(loop);
- assert(loop_header->type == nir_cf_node_block);
- nir_block *loop_header_block = nir_cf_node_as_block(loop_header);
+ nir_block *loop_header_block = nir_loop_first_block(loop);
unlink_block_successors(block);
link_blocks(block, loop_header_block, NULL);
} 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);
- assert(head->type == nir_cf_node_block);
- nir_block *head_block = nir_cf_node_as_block(head);
+ nir_block *head_block = nir_loop_first_block(loop);
link_blocks(block, head_block, NULL);
insert_phi_undef(head_block, block);
if (next->type == nir_cf_node_if) {
nir_if *next_if = nir_cf_node_as_if(next);
- nir_cf_node *first_then = nir_if_first_then_node(next_if);
- assert(first_then->type == nir_cf_node_block);
- nir_block *first_then_block = nir_cf_node_as_block(first_then);
-
- nir_cf_node *first_else = nir_if_first_else_node(next_if);
- assert(first_else->type == nir_cf_node_block);
- nir_block *first_else_block = nir_cf_node_as_block(first_else);
+ nir_block *first_then_block = nir_if_first_then_block(next_if);
+ nir_block *first_else_block = nir_if_first_else_block(next_if);
link_blocks(block, first_then_block, first_else_block);
} else {
assert(next->type == nir_cf_node_loop);
nir_loop *next_loop = nir_cf_node_as_loop(next);
- nir_cf_node *first = nir_loop_first_cf_node(next_loop);
- assert(first->type == nir_cf_node_block);
- nir_block *first_block = nir_cf_node_as_block(first);
+ nir_block *first_block = nir_loop_first_block(next_loop);
link_blocks(block, first_block, NULL);
insert_phi_undef(first_block, block);
nir_loop *loop = nearest_loop(&block->cf_node);
if (jump_instr->type == nir_jump_continue) {
- nir_cf_node *first_node = nir_loop_first_cf_node(loop);
- assert(first_node->type == nir_cf_node_block);
- nir_block *first_block = nir_cf_node_as_block(first_node);
+ nir_block *first_block = nir_loop_first_block(loop);
link_blocks(block, first_block, NULL);
} else {
nir_cf_node *after = nir_cf_node_next(&loop->cf_node);
then_dest->num_components, bit_size, NULL);
nir_phi_src *src0 = ralloc(phi, nir_phi_src);
- src0->pred = nir_cf_node_as_block(nir_if_last_then_node(if_stmt));
+ src0->pred = nir_if_last_then_block(if_stmt);
src0->src = nir_src_for_ssa(then_dest);
exec_list_push_tail(&phi->srcs, &src0->node);
nir_phi_src *src1 = ralloc(phi, nir_phi_src);
- src1->pred = nir_cf_node_as_block(nir_if_last_else_node(if_stmt));
+ src1->pred = nir_if_last_else_block(if_stmt);
src1->src = nir_src_for_ssa(else_dest);
exec_list_push_tail(&phi->srcs, &src1->node);
* point to the correct source.
*/
nir_block *after = nir_cf_node_as_block(nir_cf_node_next(&if_stmt->cf_node));
- nir_block *last_block =
- nir_cf_node_as_block(condition ? nir_if_last_then_node(if_stmt)
- : nir_if_last_else_node(if_stmt));
+ nir_block *last_block = condition ? nir_if_last_then_block(if_stmt)
+ : nir_if_last_else_block(if_stmt);
nir_foreach_instr_safe(instr, after) {
if (instr->type != nir_instr_type_phi)
return false;
nir_if *if_stmt = nir_cf_node_as_if(prev_node);
- nir_cf_node *then_node = nir_if_first_then_node(if_stmt);
- nir_cf_node *else_node = nir_if_first_else_node(if_stmt);
+ nir_block *then_block = nir_if_first_then_block(if_stmt);
+ nir_block *else_block = nir_if_first_else_block(if_stmt);
/* We can only have one block in each side ... */
- if (nir_if_last_then_node(if_stmt) != then_node ||
- nir_if_last_else_node(if_stmt) != else_node)
+ if (nir_if_last_then_block(if_stmt) != then_block ||
+ nir_if_last_else_block(if_stmt) != else_block)
return false;
- nir_block *then_block = nir_cf_node_as_block(then_node);
- nir_block *else_block = nir_cf_node_as_block(else_node);
-
/* ... and those blocks must only contain "allowed" instructions. */
unsigned count = 0;
if (!block_check_for_allowed_instrs(then_block, &count, limit != 0) ||
}
case nir_jump_continue: {
- nir_block *first =
- nir_cf_node_as_block(nir_loop_first_cf_node(state->loop));
+ nir_block *first = nir_loop_first_block(state->loop);
validate_assert(state, block->successors[0] == first);
break;
}
if (next == NULL) {
switch (state->parent_node->type) {
case nir_cf_node_loop: {
- nir_block *first =
- nir_cf_node_as_block(nir_loop_first_cf_node(state->loop));
+ nir_block *first = nir_loop_first_block(state->loop);
validate_assert(state, block->successors[0] == first);
/* due to the hack for infinite loops, block->successors[1] may
* point to the block after the loop.
} else {
if (next->type == nir_cf_node_if) {
nir_if *if_stmt = nir_cf_node_as_if(next);
- validate_assert(state, &block->successors[0]->cf_node ==
- nir_if_first_then_node(if_stmt));
- validate_assert(state, &block->successors[1]->cf_node ==
- nir_if_first_else_node(if_stmt));
+ validate_assert(state, block->successors[0] ==
+ nir_if_first_then_block(if_stmt));
+ validate_assert(state, block->successors[1] ==
+ nir_if_first_else_block(if_stmt));
} else {
validate_assert(state, next->type == nir_cf_node_loop);
nir_loop *loop = nir_cf_node_as_loop(next);
- validate_assert(state, &block->successors[0]->cf_node ==
- nir_loop_first_cf_node(loop));
+ validate_assert(state, block->successors[0] ==
+ nir_loop_first_block(loop));
validate_assert(state, block->successors[1] == NULL);
}
}
return false;
nir_if *if_stmt = nir_cf_node_as_if(prev_node);
- nir_cf_node *then_node = nir_if_first_then_node(if_stmt);
- nir_cf_node *else_node = nir_if_first_else_node(if_stmt);
+ nir_block *then_block = nir_if_first_then_block(if_stmt);
+ nir_block *else_block = nir_if_first_else_block(if_stmt);
/* We can only have one block in each side ... */
- if (nir_if_last_then_node(if_stmt) != then_node ||
- nir_if_last_else_node(if_stmt) != else_node)
+ if (nir_if_last_then_block(if_stmt) != then_block ||
+ nir_if_last_else_block(if_stmt) != else_block)
return false;
- nir_block *then_block = nir_cf_node_as_block(then_node);
- nir_block *else_block = nir_cf_node_as_block(else_node);
-
/* ... and those blocks must only contain "allowed" instructions. */
if (!block_check_for_allowed_instrs(then_block) ||
!block_check_for_allowed_instrs(else_block))
return;
}
- nir_cf_node *nir_first_else_node = nir_if_first_else_node(if_stmt);
- nir_cf_node *nir_last_else_node = nir_if_last_else_node(if_stmt);
- nir_block *nir_else_block = nir_cf_node_as_block(nir_first_else_node);
+ nir_block *nir_else_block = nir_if_first_else_block(if_stmt);
bool empty_else_block =
- (nir_first_else_node == nir_last_else_node &&
+ (nir_else_block == nir_if_last_else_block(if_stmt) &&
exec_list_is_empty(&nir_else_block->instr_list));
struct qblock *then_block = qir_new_block(c);