{
nir_shader *shader = rzalloc(mem_ctx, nir_shader);
- exec_list_make_empty(&shader->uniforms);
- exec_list_make_empty(&shader->inputs);
- exec_list_make_empty(&shader->outputs);
- exec_list_make_empty(&shader->shared);
+ exec_list_make_empty(&shader->variables);
shader->options = options;
}
exec_list_make_empty(&shader->functions);
- exec_list_make_empty(&shader->globals);
- exec_list_make_empty(&shader->system_values);
shader->num_inputs = 0;
shader->num_outputs = 0;
exec_node_remove(®->node);
}
-struct exec_list *
-nir_variable_list_for_mode(nir_shader *shader, nir_variable_mode mode)
+void
+nir_shader_add_variable(nir_shader *shader, nir_variable *var)
{
- switch (mode) {
+ switch (var->data.mode) {
case nir_var_function_temp:
assert(!"nir_shader_add_variable cannot be used for local variables");
- return NULL;
+ return;
case nir_var_shader_temp:
- return &shader->globals;
-
case nir_var_shader_in:
- return &shader->inputs;
-
case nir_var_shader_out:
- return &shader->outputs;
-
case nir_var_uniform:
case nir_var_mem_ubo:
case nir_var_mem_ssbo:
- return &shader->uniforms;
-
case nir_var_mem_shared:
- assert(gl_shader_stage_is_compute(shader->info.stage));
- return &shader->shared;
+ case nir_var_system_value:
+ break;
case nir_var_mem_global:
assert(!"nir_shader_add_variable cannot be used for global memory");
- return NULL;
-
- case nir_var_system_value:
- return &shader->system_values;
+ return;
case nir_var_mem_push_const:
assert(!"nir_var_push_constant is not supposed to be used for variables");
- return NULL;
+ return;
default:
assert(!"invalid mode");
- return NULL;
+ return;
}
-}
-void
-nir_shader_add_variable(nir_shader *shader, nir_variable *var)
-{
- struct exec_list *var_list =
- nir_variable_list_for_mode(shader, var->data.mode);
- if (var_list)
- exec_list_push_tail(var_list, &var->node);
+ exec_list_push_tail(&shader->variables, &var->node);
}
nir_variable *
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);
}
return index;
}
-static void
-index_var_list(struct exec_list *list)
+unsigned
+nir_shader_index_vars(nir_shader *shader, nir_variable_mode modes)
{
- unsigned next_index = 0;
- nir_foreach_variable(var, list)
- var->index = next_index++;
+ unsigned count = 0;
+ nir_foreach_variable_with_modes(var, shader, modes)
+ var->index = count++;
+ return count;
}
-void
-nir_index_vars(nir_shader *shader, nir_function_impl *impl, nir_variable_mode modes)
+unsigned
+nir_function_impl_index_vars(nir_function_impl *impl)
{
- if ((modes & nir_var_function_temp) && impl)
- index_var_list(&impl->locals);
-
- if (modes & nir_var_shader_temp)
- index_var_list(&shader->globals);
-
- if (modes & nir_var_shader_in)
- index_var_list(&shader->inputs);
-
- if (modes & nir_var_shader_out)
- index_var_list(&shader->outputs);
-
- if (modes & (nir_var_uniform | nir_var_mem_ubo | nir_var_mem_ssbo))
- index_var_list(&shader->uniforms);
-
- if (modes & nir_var_mem_shared)
- index_var_list(&shader->shared);
-
- if (modes & nir_var_system_value)
- index_var_list(&shader->system_values);
+ unsigned count = 0;
+ nir_foreach_function_temp_variable(var, impl)
+ var->index = count++;
+ return count;
}
static nir_instr *