impl->reg_alloc = 0;
impl->ssa_alloc = 0;
impl->valid_metadata = nir_metadata_none;
+ impl->structured = true;
/* create start & end blocks */
nir_block *start_block = nir_block_create(shader);
return NULL;
}
+ assert(nir_cf_node_get_function(&block->cf_node)->structured);
+
nir_cf_node *cf_next = nir_cf_node_next(&block->cf_node);
if (cf_next)
return nir_cf_node_cf_tree_first(cf_next);
return NULL;
}
+ assert(nir_cf_node_get_function(&block->cf_node)->structured);
+
nir_cf_node *cf_prev = nir_cf_node_prev(&block->cf_node);
if (cf_prev)
return nir_cf_node_cf_tree_last(cf_prev);
static void
write_function_impl(write_ctx *ctx, const nir_function_impl *fi)
{
+ blob_write_uint8(ctx->blob, fi->structured);
+
write_var_list(ctx, &fi->locals);
write_reg_list(ctx, &fi->registers);
blob_write_uint32(ctx->blob, fi->reg_alloc);
nir_function_impl *fi = nir_function_impl_create_bare(ctx->nir);
fi->function = fxn;
+ fi->structured = blob_read_uint8(ctx->blob);
+
read_var_list(ctx, &fi->locals);
read_reg_list(ctx, &fi->registers);
fi->reg_alloc = blob_read_uint32(ctx->blob);
break;
case nir_jump_break:
+ validate_assert(state, state->impl->structured);
validate_assert(state, state->loop != NULL);
if (state->loop) {
nir_block *after =
break;
case nir_jump_continue:
+ validate_assert(state, state->impl->structured);
validate_assert(state, state->loop != NULL);
if (state->loop) {
nir_block *first = nir_loop_first_block(state->loop);
pred->successors[1] == block);
}
- if (!nir_block_ends_in_jump(block)) {
+ if (!state->impl->structured) {
+ validate_assert(state, nir_block_ends_in_jump(block));
+ } else if (!nir_block_ends_in_jump(block)) {
nir_cf_node *next = nir_cf_node_next(&block->cf_node);
if (next == NULL) {
switch (state->parent_node->type) {
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);
+ } else if (next->type == nir_cf_node_loop) {
nir_loop *loop = nir_cf_node_as_loop(next);
validate_assert(state, block->successors[0] ==
nir_loop_first_block(loop));
validate_assert(state, block->successors[1] == NULL);
+ } else {
+ validate_assert(state,
+ !"Structured NIR cannot have consecutive blocks");
}
}
}
static void
validate_if(nir_if *if_stmt, validate_state *state)
{
+ validate_assert(state, state->impl->structured);
+
state->if_stmt = if_stmt;
validate_assert(state, !exec_node_is_head_sentinel(if_stmt->cf_node.node.prev));
static void
validate_loop(nir_loop *loop, validate_state *state)
{
+ validate_assert(state, state->impl->structured);
+
validate_assert(state, !exec_node_is_head_sentinel(loop->cf_node.node.prev));
nir_cf_node *prev_node = nir_cf_node_prev(&loop->cf_node);
validate_assert(state, prev_node->type == nir_cf_node_block);