return var;
}
+nir_variable *
+nir_find_variable_with_location(nir_shader *shader,
+ nir_variable_mode mode,
+ unsigned location)
+{
+ assert(util_bitcount(mode) == 1 && mode != nir_var_function_temp);
+ nir_foreach_variable_with_modes(var, shader, mode) {
+ if (var->data.location == location)
+ return var;
+ }
+ return NULL;
+}
+
+nir_variable *
+nir_find_variable_with_driver_location(nir_shader *shader,
+ nir_variable_mode mode,
+ unsigned location)
+{
+ assert(util_bitcount(mode) == 1 && mode != nir_var_function_temp);
+ nir_foreach_variable_with_modes(var, shader, mode) {
+ if (var->data.driver_location == location)
+ return var;
+ }
+ return NULL;
+}
+
nir_function *
nir_function_create(nir_shader *shader, const char *name)
{
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);
{
nir_jump_instr *instr = ralloc(shader, nir_jump_instr);
instr_init(&instr->instr, nir_instr_type_jump);
+ src_init(&instr->condition);
instr->type = type;
+ instr->target = NULL;
+ instr->else_target = NULL;
return instr;
}
{
switch (cursor.option) {
case nir_cursor_before_block:
- assert(nir_cf_node_prev(&cursor.block->cf_node) == NULL ||
- nir_cf_node_prev(&cursor.block->cf_node)->type != nir_cf_node_block);
if (exec_list_is_empty(&cursor.block->instr_list)) {
/* Empty block. After is as good as before. */
cursor.option = nir_cursor_after_block;
return true;
}
+static bool
+visit_jump_src(nir_jump_instr *instr, nir_foreach_src_cb cb, void *state)
+{
+ if (instr->type != nir_jump_goto_if)
+ return true;
+
+ return visit_src(&instr->condition, cb, state);
+}
+
typedef struct {
void *state;
nir_foreach_src_cb cb;
return false;
break;
case nir_instr_type_jump:
+ return visit_jump_src(nir_instr_as_jump(instr), cb, state);
case nir_instr_type_ssa_undef:
return true;
return read_mask;
}
+nir_block *
+nir_block_unstructured_next(nir_block *block)
+{
+ if (block == NULL) {
+ /* nir_foreach_block_unstructured_safe() will call this function on a
+ * NULL block after the last iteration, but it won't use the result so
+ * just return NULL here.
+ */
+ return NULL;
+ }
+
+ nir_cf_node *cf_next = nir_cf_node_next(&block->cf_node);
+ if (cf_next == NULL && block->cf_node.parent->type == nir_cf_node_function)
+ return NULL;
+
+ if (cf_next && cf_next->type == nir_cf_node_block)
+ return nir_cf_node_as_block(cf_next);
+
+ return nir_block_cf_tree_next(block);
+}
+
+nir_block *
+nir_unstructured_start_block(nir_function_impl *impl)
+{
+ return nir_start_block(impl);
+}
+
nir_block *
nir_block_cf_tree_next(nir_block *block)
{
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);
if (impl->valid_metadata & nir_metadata_block_index)
return;
- nir_foreach_block(block, impl) {
+ nir_foreach_block_unstructured(block, impl) {
block->index = index++;
}
{
unsigned index = 0;
- nir_foreach_block(block, impl) {
+ nir_foreach_block_unstructured(block, impl) {
nir_foreach_instr(instr, block)
nir_foreach_ssa_def(instr, index_ssa_def_cb, &index);
}