options);
nir_function *func = nir_function_create(s, "main");
- nir_function_overload *overload = nir_function_overload_create(func);
- nir_function_impl *impl = nir_function_impl_create(overload);
+ nir_function_impl *impl = nir_function_impl_create(func);
nir_builder_init(&c->build, impl);
c->build.cursor = nir_after_cf_list(&impl->body);
nir_function_impl *fxn = NULL;
/* Find the main function: */
- nir_foreach_overload(ctx->s, overload) {
- compile_assert(ctx, strcmp(overload->function->name, "main") == 0);
- compile_assert(ctx, overload->impl);
- fxn = overload->impl;
+ nir_foreach_function(ctx->s, function) {
+ compile_assert(ctx, strcmp(function->name, "main") == 0);
+ compile_assert(ctx, function->impl);
+ fxn = function->impl;
break;
}
{
bool progress = false;
- nir_foreach_overload(shader, overload) {
- if (overload->impl)
- progress |= lower_if_else_impl(overload->impl);
+ nir_foreach_function(shader, function) {
+ if (function->impl)
+ progress |= lower_if_else_impl(function->impl);
}
return progress;
void
vc4_nir_lower_blend(struct vc4_compile *c)
{
- nir_foreach_overload(c->s, overload) {
- if (overload->impl) {
- nir_foreach_block(overload->impl,
+ nir_foreach_function(c->s, function) {
+ if (function->impl) {
+ nir_foreach_block(function->impl,
vc4_nir_lower_blend_block, c);
- nir_metadata_preserve(overload->impl,
+ nir_metadata_preserve(function->impl,
nir_metadata_block_index |
nir_metadata_dominance);
}
void
vc4_nir_lower_io(struct vc4_compile *c)
{
- nir_foreach_overload(c->s, overload) {
- if (overload->impl)
- vc4_nir_lower_io_impl(c, overload->impl);
+ nir_foreach_function(c->s, function) {
+ if (function->impl)
+ vc4_nir_lower_io_impl(c, function->impl);
}
}
void
vc4_nir_lower_txf_ms(struct vc4_compile *c)
{
- nir_foreach_overload(c->s, overload) {
- if (overload->impl)
- vc4_nir_lower_txf_ms_impl(c, overload->impl);
+ nir_foreach_function(c->s, function) {
+ if (function->impl)
+ vc4_nir_lower_txf_ms_impl(c, function->impl);
}
}
ntq_setup_registers(c, &c->s->registers);
/* Find the main function and emit the body. */
- nir_foreach_overload(c->s, overload) {
- assert(strcmp(overload->function->name, "main") == 0);
- assert(overload->impl);
- ntq_emit_impl(c, overload->impl);
+ nir_foreach_function(c->s, function) {
+ assert(strcmp(function->name, "main") == 0);
+ assert(function->impl);
+ ntq_emit_impl(c, function->impl);
}
}
count_nir_instrs(nir_shader *nir)
{
int count = 0;
- nir_foreach_overload(nir, overload) {
- if (!overload->impl)
+ nir_foreach_function(nir, function) {
+ if (!function->impl)
continue;
- nir_foreach_block(overload->impl, count_nir_instrs_in_block, &count);
+ nir_foreach_block(function->impl, count_nir_instrs_in_block, &count);
}
return count;
}
virtual void visit(ir_dereference_array *);
virtual void visit(ir_barrier *);
- void create_function(ir_function *ir);
+ void create_function(ir_function_signature *ir);
private:
- void create_overload(ir_function_signature *ir, nir_function *function);
void add_instr(nir_instr *instr, unsigned num_components);
nir_ssa_def *evaluate_rvalue(ir_rvalue *ir);
ir_visitor_status
nir_function_visitor::visit_enter(ir_function *ir)
{
- visitor->create_function(ir);
- return visit_continue_with_parent;
-}
-
-
-void
-nir_visitor::create_function(ir_function *ir)
-{
- nir_function *func = nir_function_create(this->shader, ir->name);
foreach_in_list(ir_function_signature, sig, &ir->signatures) {
- create_overload(sig, func);
+ visitor->create_function(sig);
}
+ return visit_continue_with_parent;
}
-
-
void
-nir_visitor::create_overload(ir_function_signature *ir, nir_function *function)
+nir_visitor::create_function(ir_function_signature *ir)
{
if (ir->is_intrinsic)
return;
- nir_function_overload *overload = nir_function_overload_create(function);
+ nir_function *func = nir_function_create(shader, ir->function_name());
unsigned num_params = ir->parameters.length();
- overload->num_params = num_params;
- overload->params = ralloc_array(shader, nir_parameter, num_params);
+ func->num_params = num_params;
+ func->params = ralloc_array(shader, nir_parameter, num_params);
unsigned i = 0;
foreach_in_list(ir_variable, param, &ir->parameters) {
switch (param->data.mode) {
case ir_var_function_in:
- overload->params[i].param_type = nir_parameter_in;
+ func->params[i].param_type = nir_parameter_in;
break;
case ir_var_function_out:
- overload->params[i].param_type = nir_parameter_out;
+ func->params[i].param_type = nir_parameter_out;
break;
case ir_var_function_inout:
- overload->params[i].param_type = nir_parameter_inout;
+ func->params[i].param_type = nir_parameter_inout;
break;
default:
unreachable("not reached");
}
- overload->params[i].type = param->type;
+ func->params[i].type = param->type;
i++;
}
- overload->return_type = ir->return_type;
+ func->return_type = ir->return_type;
- _mesa_hash_table_insert(this->overload_table, ir, overload);
+ _mesa_hash_table_insert(this->overload_table, ir, func);
}
void
_mesa_hash_table_search(this->overload_table, ir);
assert(entry);
- nir_function_overload *overload = (nir_function_overload *) entry->data;
+ nir_function *func = (nir_function *) entry->data;
if (ir->is_defined) {
- nir_function_impl *impl = nir_function_impl_create(overload);
+ nir_function_impl *impl = nir_function_impl_create(func);
this->impl = impl;
- unsigned num_params = overload->num_params;
+ unsigned num_params = func->num_params;
impl->num_params = num_params;
impl->params = ralloc_array(this->shader, nir_variable *, num_params);
unsigned i = 0;
i++;
}
- if (overload->return_type == glsl_type::void_type) {
+ if (func->return_type == glsl_type::void_type) {
impl->return_var = NULL;
} else {
impl->return_var = ralloc(this->shader, nir_variable);
impl->return_var->name = ralloc_strdup(impl->return_var,
"return_var");
- impl->return_var->type = overload->return_type;
+ impl->return_var->type = func->return_type;
}
this->is_global = false;
this->is_global = true;
} else {
- overload->impl = NULL;
+ func->impl = NULL;
}
}
struct hash_entry *entry =
_mesa_hash_table_search(this->overload_table, ir->callee);
assert(entry);
- nir_function_overload *callee = (nir_function_overload *) entry->data;
+ nir_function *callee = (nir_function *) entry->data;
nir_call_instr *instr = nir_call_instr_create(this->shader, callee);
nir_local_variable_create(nir_function_impl *impl,
const struct glsl_type *type, const char *name)
{
- nir_variable *var = rzalloc(impl->overload->function->shader, nir_variable);
+ nir_variable *var = rzalloc(impl->function->shader, nir_variable);
var->name = ralloc_strdup(var, name);
var->type = type;
var->data.mode = nir_var_local;
nir_function *func = ralloc(shader, nir_function);
exec_list_push_tail(&shader->functions, &func->node);
- exec_list_make_empty(&func->overload_list);
+
func->name = ralloc_strdup(func, name);
func->shader = shader;
+ func->num_params = 0;
+ func->params = NULL;
+ func->return_type = glsl_void_type();
+ func->impl = NULL;
return func;
}
-nir_function_overload *
-nir_function_overload_create(nir_function *func)
-{
- void *mem_ctx = ralloc_parent(func);
-
- nir_function_overload *overload = ralloc(mem_ctx, nir_function_overload);
-
- overload->num_params = 0;
- overload->params = NULL;
- overload->return_type = glsl_void_type();
- overload->impl = NULL;
-
- exec_list_push_tail(&func->overload_list, &overload->node);
- overload->function = func;
-
- return overload;
-}
-
void nir_src_copy(nir_src *dest, const nir_src *src, void *mem_ctx)
{
dest->is_ssa = src->is_ssa;
}
nir_function_impl *
-nir_function_impl_create(nir_function_overload *overload)
+nir_function_impl_create(nir_function *function)
{
- assert(overload->impl == NULL);
+ assert(function->impl == NULL);
- void *mem_ctx = ralloc_parent(overload);
+ void *mem_ctx = ralloc_parent(function);
nir_function_impl *impl = ralloc(mem_ctx, nir_function_impl);
- overload->impl = impl;
- impl->overload = overload;
+ function->impl = impl;
+ impl->function = function;
cf_init(&impl->cf_node, nir_cf_node_function);
}
nir_call_instr *
-nir_call_instr_create(nir_shader *shader, nir_function_overload *callee)
+nir_call_instr_create(nir_shader *shader, nir_function *callee)
{
nir_call_instr *instr = ralloc(shader, nir_call_instr);
instr_init(&instr->instr, nir_instr_type_call);
return exec_node_data(out_type, parent, field); \
}
-struct nir_function_overload;
struct nir_function;
struct nir_shader;
struct nir_instr;
nir_deref_var **params;
nir_deref_var *return_deref;
- struct nir_function_overload *callee;
+ struct nir_function *callee;
} nir_call_instr;
#define INTRINSIC(name, num_srcs, src_components, has_dest, dest_components, \
typedef struct {
nir_cf_node cf_node;
- /** pointer to the overload of which this is an implementation */
- struct nir_function_overload *overload;
+ /** pointer to the function of which this is an implementation */
+ struct nir_function *function;
struct exec_list body; /** < list of nir_cf_node */
const struct glsl_type *type;
} nir_parameter;
-typedef struct nir_function_overload {
+typedef struct nir_function {
struct exec_node node;
+ const char *name;
+ struct nir_shader *shader;
+
unsigned num_params;
nir_parameter *params;
const struct glsl_type *return_type;
- nir_function_impl *impl; /** < NULL if the overload is only declared yet */
-
- /** pointer to the function of which this is an overload */
- struct nir_function *function;
-} nir_function_overload;
-
-typedef struct nir_function {
- struct exec_node node;
-
- struct exec_list overload_list; /** < list of nir_function_overload */
- const char *name;
- struct nir_shader *shader;
+ /** The implementation of this function.
+ *
+ * If the function is only declared and not implemented, this is NULL.
+ */
+ nir_function_impl *impl;
} nir_function;
-#define nir_function_first_overload(func) \
- exec_node_data(nir_function_overload, \
- exec_list_get_head(&(func)->overload_list), node)
-
typedef struct nir_shader_compiler_options {
bool lower_ffma;
bool lower_flrp;
gl_shader_stage stage;
} nir_shader;
-#define nir_foreach_overload(shader, overload) \
- foreach_list_typed(nir_function, func, node, &(shader)->functions) \
- foreach_list_typed(nir_function_overload, overload, node, \
- &(func)->overload_list)
+#define nir_foreach_function(shader, func) \
+ foreach_list_typed(nir_function, func, node, &(shader)->functions)
nir_shader *nir_shader_create(void *mem_ctx,
gl_shader_stage stage,
/** creates a function and adds it to the shader's list of functions */
nir_function *nir_function_create(nir_shader *shader, const char *name);
-/** creates a null function returning null */
-nir_function_overload *nir_function_overload_create(nir_function *func);
-
-nir_function_impl *nir_function_impl_create(nir_function_overload *func);
+nir_function_impl *nir_function_impl_create(nir_function *func);
nir_block *nir_block_create(nir_shader *shader);
nir_if *nir_if_create(nir_shader *shader);
nir_intrinsic_op op);
nir_call_instr *nir_call_instr_create(nir_shader *shader,
- nir_function_overload *callee);
+ nir_function *callee);
nir_tex_instr *nir_tex_instr_create(nir_shader *shader, unsigned num_srcs);
condition_flags[${index}] = ${condition};
% endfor
- nir_foreach_overload(shader, overload) {
- if (overload->impl)
- progress |= ${pass_name}_impl(overload->impl, condition_flags);
+ nir_foreach_function(shader, function) {
+ if (function->impl)
+ progress |= ${pass_name}_impl(function->impl, condition_flags);
}
return progress;
{
memset(build, 0, sizeof(*build));
build->impl = impl;
- build->shader = impl->overload->function->shader;
+ build->shader = impl->function->shader;
}
static inline void
static nir_call_instr *
clone_call(clone_state *state, const nir_call_instr *call)
{
- nir_function_overload *ncallee = lookup_ptr(state, call->callee);
+ nir_function *ncallee = lookup_ptr(state, call->callee);
nir_call_instr *ncall = nir_call_instr_create(state->ns, ncallee);
for (unsigned i = 0; i < ncall->num_params; i++)
static nir_function_impl *
clone_function_impl(clone_state *state, const nir_function_impl *fi,
- nir_function_overload *nfo)
+ nir_function *nfxn)
{
- nir_function_impl *nfi = nir_function_impl_create(nfo);
+ nir_function_impl *nfi = nir_function_impl_create(nfxn);
clone_var_list(state, &nfi->locals, &fi->locals);
clone_reg_list(state, &nfi->registers, &fi->registers);
return nfi;
}
-static nir_function_overload *
-clone_function_overload(clone_state *state, const nir_function_overload *fo,
- nir_function *nfxn)
+static nir_function *
+clone_function(clone_state *state, const nir_function *fxn, nir_shader *ns)
{
- nir_function_overload *nfo = nir_function_overload_create(nfxn);
+ assert(ns == state->ns);
+ nir_function *nfxn = nir_function_create(ns, fxn->name);
/* Needed for call instructions */
- store_ptr(state, nfo, fo);
+ store_ptr(state, nfxn, fxn);
- nfo->num_params = fo->num_params;
- nfo->params = ralloc_array(state->ns, nir_parameter, fo->num_params);
- memcpy(nfo->params, fo->params, sizeof(nir_parameter) * fo->num_params);
+ nfxn->num_params = fxn->num_params;
+ nfxn->params = ralloc_array(state->ns, nir_parameter, fxn->num_params);
+ memcpy(nfxn->params, fxn->params, sizeof(nir_parameter) * fxn->num_params);
- nfo->return_type = fo->return_type;
+ nfxn->return_type = fxn->return_type;
/* At first glance, it looks like we should clone the function_impl here.
* However, call instructions need to be able to reference at least the
- * overload and those will get processed as we clone the function_impl's.
+ * function and those will get processed as we clone the function_impl's.
* We stop here and do function_impls as a second pass.
*/
- return nfo;
-}
-
-static nir_function *
-clone_function(clone_state *state, const nir_function *fxn, nir_shader *ns)
-{
- assert(ns == state->ns);
- nir_function *nfxn = nir_function_create(ns, fxn->name);
-
- foreach_list_typed(nir_function_overload, fo, node, &fxn->overload_list)
- clone_function_overload(state, fo, nfxn);
-
return nfxn;
}
clone_var_list(&state, &ns->globals, &s->globals);
clone_var_list(&state, &ns->system_values, &s->system_values);
- /* Go through and clone functions and overloads */
+ /* Go through and clone functions */
foreach_list_typed(nir_function, fxn, node, &s->functions)
clone_function(&state, fxn, ns);
- /* Only after all overloads are cloned can we clone the actual function
+ /* Only after all functions are cloned can we clone the actual function
* implementations. This is because nir_call_instr's need to reference the
- * overloads of other functions and we don't know what order the functions
+ * functions of other functions and we don't know what order the functions
* will have in the list.
*/
- nir_foreach_overload(s, fo) {
- nir_function_overload *nfo = lookup_ptr(&state, fo);
- clone_function_impl(&state, fo->impl, nfo);
+ nir_foreach_function(s, fxn) {
+ nir_function *nfxn = lookup_ptr(&state, fxn);
+ clone_function_impl(&state, fxn->impl, nfxn);
}
clone_reg_list(&state, &ns->registers, &s->registers);
void
nir_calc_dominance(nir_shader *shader)
{
- nir_foreach_overload(shader, overload) {
- if (overload->impl)
- nir_calc_dominance_impl(overload->impl);
+ nir_foreach_function(shader, function) {
+ if (function->impl)
+ nir_calc_dominance_impl(function->impl);
}
}
void
nir_dump_dom_tree_impl(nir_function_impl *impl, FILE *fp)
{
- fprintf(fp, "digraph doms_%s {\n", impl->overload->function->name);
+ fprintf(fp, "digraph doms_%s {\n", impl->function->name);
nir_foreach_block(impl, dump_block_dom, fp);
fprintf(fp, "}\n\n");
}
void
nir_dump_dom_tree(nir_shader *shader, FILE *fp)
{
- nir_foreach_overload(shader, overload) {
- if (overload->impl)
- nir_dump_dom_tree_impl(overload->impl, fp);
+ nir_foreach_function(shader, function) {
+ if (function->impl)
+ nir_dump_dom_tree_impl(function->impl, fp);
}
}
void
nir_dump_dom_frontier(nir_shader *shader, FILE *fp)
{
- nir_foreach_overload(shader, overload) {
- if (overload->impl)
- nir_dump_dom_frontier_impl(overload->impl, fp);
+ nir_foreach_function(shader, function) {
+ if (function->impl)
+ nir_dump_dom_frontier_impl(function->impl, fp);
}
}
void
nir_dump_cfg_impl(nir_function_impl *impl, FILE *fp)
{
- fprintf(fp, "digraph cfg_%s {\n", impl->overload->function->name);
+ fprintf(fp, "digraph cfg_%s {\n", impl->function->name);
nir_foreach_block(impl, dump_block_succs, fp);
fprintf(fp, "}\n\n");
}
void
nir_dump_cfg(nir_shader *shader, FILE *fp)
{
- nir_foreach_overload(shader, overload) {
- if (overload->impl)
- nir_dump_cfg_impl(overload->impl, fp);
+ nir_foreach_function(shader, function) {
+ if (function->impl)
+ nir_dump_cfg_impl(function->impl, fp);
}
}
void
nir_convert_from_ssa(nir_shader *shader, bool phi_webs_only)
{
- nir_foreach_overload(shader, overload) {
- if (overload->impl)
- nir_convert_from_ssa_impl(overload->impl, phi_webs_only);
+ nir_foreach_function(shader, function) {
+ if (function->impl)
+ nir_convert_from_ssa_impl(function->impl, phi_webs_only);
}
}
{
int count = -1;
- nir_foreach_overload(shader, overload) {
- if (!overload->impl)
+ nir_foreach_function(shader, function) {
+ if (!function->impl)
continue;
/* set_vertex_count intrinsics only appear in predecessors of the
* end block. So we don't need to walk all of them.
*/
struct set_entry *entry;
- set_foreach(overload->impl->end_block->predecessors, entry) {
+ set_foreach(function->impl->end_block->predecessors, entry) {
nir_block *block = (nir_block *) entry->key;
nir_foreach_instr_reverse(block, instr) {
void
nir_lower_alu_to_scalar(nir_shader *shader)
{
- nir_foreach_overload(shader, overload) {
- if (overload->impl)
- nir_lower_alu_to_scalar_impl(overload->impl);
+ nir_foreach_function(shader, function) {
+ if (function->impl)
+ nir_lower_alu_to_scalar_impl(function->impl);
}
}
.shader_program = shader_program,
};
- nir_foreach_overload(shader, overload) {
- if (overload->impl) {
- nir_foreach_block(overload->impl, lower_block, (void *) &state);
- nir_metadata_preserve(overload->impl, nir_metadata_block_index |
+ nir_foreach_function(shader, function) {
+ if (function->impl) {
+ nir_foreach_block(function->impl, lower_block, (void *) &state);
+ nir_metadata_preserve(function->impl, nir_metadata_block_index |
nir_metadata_dominance);
}
}
.drvloc = drvloc,
};
- nir_foreach_overload(shader, overload) {
- if (overload->impl) {
- nir_foreach_block_reverse(overload->impl,
+ nir_foreach_function(shader, function) {
+ if (function->impl) {
+ nir_foreach_block_reverse(function->impl,
find_output_in_block, &state);
}
}
out[1] =
create_clipdist_var(shader, ++maxloc, true, VARYING_SLOT_CLIP_DIST1);
- nir_foreach_overload(shader, overload) {
- if (!strcmp(overload->function->name, "main"))
- lower_clip_vs(overload->impl, ucp_enables, cv, out);
+ nir_foreach_function(shader, function) {
+ if (!strcmp(function->name, "main"))
+ lower_clip_vs(function->impl, ucp_enables, cv, out);
}
}
create_clipdist_var(shader, ++maxloc, false,
VARYING_SLOT_CLIP_DIST1);
- nir_foreach_overload(shader, overload) {
- if (!strcmp(overload->function->name, "main"))
- lower_clip_fs(overload->impl, ucp_enables, in);
+ nir_foreach_function(shader, function) {
+ if (!strcmp(function->name, "main"))
+ lower_clip_fs(function->impl, ucp_enables, in);
}
}
state.var_func_table = _mesa_hash_table_create(NULL, _mesa_hash_pointer,
_mesa_key_pointer_equal);
- nir_foreach_overload(shader, overload) {
- if (overload->impl) {
- state.impl = overload->impl;
- nir_foreach_block(overload->impl, mark_global_var_uses_block, &state);
+ nir_foreach_function(shader, function) {
+ if (function->impl) {
+ state.impl = function->impl;
+ nir_foreach_block(function->impl, mark_global_var_uses_block, &state);
}
}
exec_list_push_tail(&shader->globals, &var->node);
state.vertex_count_var = var;
- nir_foreach_overload(shader, overload) {
- if (overload->impl) {
+ nir_foreach_function(shader, function) {
+ if (function->impl) {
nir_builder b;
- nir_builder_init(&b, overload->impl);
+ nir_builder_init(&b, function->impl);
state.builder = &b;
- nir_foreach_block(overload->impl, rewrite_intrinsics, &state);
+ nir_foreach_block(function->impl, rewrite_intrinsics, &state);
/* This only works because we have a single main() function. */
- append_set_vertex_count(overload->impl->end_block, &state);
+ append_set_vertex_count(function->impl->end_block, &state);
- nir_metadata_preserve(overload->impl, 0);
+ nir_metadata_preserve(function->impl, 0);
}
}
void
nir_lower_idiv(nir_shader *shader)
{
- nir_foreach_overload(shader, overload) {
- if (overload->impl)
- convert_impl(overload->impl);
+ nir_foreach_function(shader, function) {
+ if (function->impl)
+ convert_impl(function->impl);
}
}
nir_lower_io(nir_shader *shader, nir_variable_mode mode,
int (*type_size)(const struct glsl_type *))
{
- nir_foreach_overload(shader, overload) {
- if (overload->impl)
- nir_lower_io_impl(overload->impl, mode, type_size);
+ nir_foreach_function(shader, function) {
+ if (function->impl)
+ nir_lower_io_impl(function->impl, mode, type_size);
}
}
void
nir_lower_load_const_to_scalar(nir_shader *shader)
{
- nir_foreach_overload(shader, overload) {
- if (overload->impl)
- nir_lower_load_const_to_scalar_impl(overload->impl);
+ nir_foreach_function(shader, function) {
+ if (function->impl)
+ nir_lower_load_const_to_scalar_impl(function->impl);
}
}
{
struct locals_to_regs_state state;
- state.shader = impl->overload->function->shader;
+ state.shader = impl->function->shader;
state.impl = impl;
state.progress = false;
state.regs_table = _mesa_hash_table_create(NULL, hash_deref, derefs_equal);
{
bool progress = false;
- nir_foreach_overload(shader, overload) {
- if (overload->impl)
- progress = nir_lower_locals_to_regs_impl(overload->impl) || progress;
+ nir_foreach_function(shader, function) {
+ if (function->impl)
+ progress = nir_lower_locals_to_regs_impl(function->impl) || progress;
}
return progress;
exec_list_push_tail(&shader->outputs, &output->node);
}
- nir_foreach_overload(shader, overload) {
- if (overload->impl == NULL)
+ nir_foreach_function(shader, function) {
+ if (function->impl == NULL)
continue;
if (shader->stage == MESA_SHADER_GEOMETRY) {
/* For geometry shaders, we have to emit the output copies right
* before each EmitVertex call.
*/
- nir_foreach_block(overload->impl, emit_output_copies_block, &state);
- } else if (strcmp(overload->function->name, "main") == 0) {
+ nir_foreach_block(function->impl, emit_output_copies_block, &state);
+ } else if (strcmp(function->name, "main") == 0) {
/* For all other shader types, we need to do the copies right before
* the jumps to the end block.
*/
struct set_entry *block_entry;
- set_foreach(overload->impl->end_block->predecessors, block_entry) {
+ set_foreach(function->impl->end_block->predecessors, block_entry) {
struct nir_block *block = (void *)block_entry->key;
emit_output_copies(nir_after_block_before_jump(block), &state);
}
}
- nir_metadata_preserve(overload->impl, nir_metadata_block_index |
+ nir_metadata_preserve(function->impl, nir_metadata_block_index |
nir_metadata_dominance);
}
void
nir_lower_phis_to_scalar(nir_shader *shader)
{
- nir_foreach_overload(shader, overload) {
- if (overload->impl)
- lower_phis_to_scalar_impl(overload->impl);
+ nir_foreach_function(shader, function) {
+ if (function->impl)
+ lower_phis_to_scalar_impl(function->impl);
}
}
nir_lower_samplers(nir_shader *shader,
const struct gl_shader_program *shader_program)
{
- nir_foreach_overload(shader, overload) {
- if (overload->impl)
- lower_impl(overload->impl, shader_program, shader->stage);
+ nir_foreach_function(shader, function) {
+ if (function->impl)
+ lower_impl(function->impl, shader_program, shader->stage);
}
}
{
bool progress = false;
- nir_foreach_overload(shader, overload) {
- if (overload->impl)
- progress = convert_impl(overload->impl) || progress;
+ nir_foreach_function(shader, function) {
+ if (function->impl)
+ progress = convert_impl(function->impl) || progress;
}
exec_list_make_empty(&shader->system_values);
state.options = options;
state.progress = false;
- nir_foreach_overload(shader, overload) {
- if (overload->impl)
- nir_lower_tex_impl(overload->impl, &state);
+ nir_foreach_function(shader, function) {
+ if (function->impl)
+ nir_lower_tex_impl(function->impl, &state);
}
return state.progress;
void
nir_lower_to_source_mods(nir_shader *shader)
{
- nir_foreach_overload(shader, overload) {
- if (overload->impl)
- nir_lower_to_source_mods_impl(overload->impl);
+ nir_foreach_function(shader, function) {
+ if (function->impl)
+ nir_lower_to_source_mods_impl(function->impl);
}
}
if (setup_inputs(&state) != 0)
return;
- nir_foreach_overload(shader, overload) {
- if (overload->impl)
- nir_lower_two_sided_color_impl(overload->impl, &state);
+ nir_foreach_function(shader, function) {
+ if (function->impl)
+ nir_lower_two_sided_color_impl(function->impl, &state);
}
}
void
nir_lower_var_copies(nir_shader *shader)
{
- nir_foreach_overload(shader, overload) {
- if (overload->impl)
- lower_var_copies_impl(overload->impl);
+ nir_foreach_function(shader, function) {
+ if (function->impl)
+ lower_var_copies_impl(function->impl);
}
}
{
struct lower_variables_state state;
- state.shader = impl->overload->function->shader;
+ state.shader = impl->function->shader;
state.dead_ctx = ralloc_context(state.shader);
state.impl = impl;
void
nir_lower_vars_to_ssa(nir_shader *shader)
{
- nir_foreach_overload(shader, overload) {
- if (overload->impl)
- nir_lower_vars_to_ssa_impl(overload->impl);
+ nir_foreach_function(shader, function) {
+ if (function->impl)
+ nir_lower_vars_to_ssa_impl(function->impl);
}
}
{
struct vec_to_movs_state *state = void_state;
nir_function_impl *impl = state->impl;
- nir_shader *shader = impl->overload->function->shader;
+ nir_shader *shader = impl->function->shader;
nir_foreach_instr_safe(block, instr) {
if (instr->type != nir_instr_type_alu)
{
bool progress = false;
- nir_foreach_overload(shader, overload) {
- if (overload->impl)
- progress = nir_lower_vec_to_movs_impl(overload->impl) || progress;
+ nir_foreach_function(shader, function) {
+ if (function->impl)
+ progress = nir_lower_vec_to_movs_impl(function->impl) || progress;
}
return progress;
void
nir_metadata_set_validation_flag(nir_shader *shader)
{
- nir_foreach_overload(shader, overload) {
- if (overload->impl) {
- overload->impl->valid_metadata |= nir_metadata_not_properly_reset;
+ nir_foreach_function(shader, function) {
+ if (function->impl) {
+ function->impl->valid_metadata |= nir_metadata_not_properly_reset;
}
}
}
void
nir_metadata_check_validation_flag(nir_shader *shader)
{
- nir_foreach_overload(shader, overload) {
- if (overload->impl) {
- assert(!(overload->impl->valid_metadata &
+ nir_foreach_function(shader, function) {
+ if (function->impl) {
+ assert(!(function->impl->valid_metadata &
nir_metadata_not_properly_reset));
}
}
void
nir_move_vec_src_uses_to_dest(nir_shader *shader)
{
- nir_foreach_overload(shader, overload) {
- if (overload->impl)
- nir_move_vec_src_uses_to_dest_impl(shader, overload->impl);
+ nir_foreach_function(shader, function) {
+ if (function->impl)
+ nir_move_vec_src_uses_to_dest_impl(shader, function->impl);
}
}
{
bool progress = false;
- nir_foreach_overload(shader, overload) {
- if (overload->impl)
- progress = normalize_cubemap_coords_impl(overload->impl) || progress;
+ nir_foreach_function(shader, function) {
+ if (function->impl)
+ progress = normalize_cubemap_coords_impl(function->impl) || progress;
}
return progress;
{
bool progress = false;
- nir_foreach_overload(shader, overload) {
- if (overload->impl)
- progress |= nir_opt_constant_folding_impl(overload->impl);
+ nir_foreach_function(shader, function) {
+ if (function->impl)
+ progress |= nir_opt_constant_folding_impl(function->impl);
}
return progress;
{
bool progress = false;
- nir_foreach_overload(shader, overload) {
- if (overload->impl && nir_copy_prop_impl(overload->impl))
+ nir_foreach_function(shader, function) {
+ if (function->impl && nir_copy_prop_impl(function->impl))
progress = true;
}
{
bool progress = false;
- nir_foreach_overload(shader, overload) {
- if (overload->impl)
- progress |= nir_opt_cse_impl(overload->impl);
+ nir_foreach_function(shader, function) {
+ if (function->impl)
+ progress |= nir_opt_cse_impl(function->impl);
}
return progress;
nir_opt_dce(nir_shader *shader)
{
bool progress = false;
- nir_foreach_overload(shader, overload) {
- if (overload->impl && nir_opt_dce_impl(overload->impl))
+ nir_foreach_function(shader, function) {
+ if (function->impl && nir_opt_dce_impl(function->impl))
progress = true;
}
{
bool progress = false;
- nir_foreach_overload(shader, overload)
- if (overload->impl)
- progress |= opt_dead_cf_impl(overload->impl);
+ nir_foreach_function(shader, function)
+ if (function->impl)
+ progress |= opt_dead_cf_impl(function->impl);
return progress;
}
void
nir_opt_gcm(nir_shader *shader)
{
- nir_foreach_overload(shader, overload) {
- if (overload->impl)
- opt_gcm_impl(overload->impl);
+ nir_foreach_function(shader, function) {
+ if (function->impl)
+ opt_gcm_impl(function->impl);
}
}
{
bool progress = false;
- nir_foreach_overload(shader, overload) {
- if (overload->impl)
- progress |= nir_opt_peephole_select_impl(overload->impl);
+ nir_foreach_function(shader, function) {
+ if (function->impl)
+ progress |= nir_opt_peephole_select_impl(function->impl);
}
return progress;
{
bool progress = false;
- nir_foreach_overload(shader, overload)
- if (overload->impl)
- progress = remove_phis_impl(overload->impl) || progress;
+ nir_foreach_function(shader, function)
+ if (function->impl)
+ progress = remove_phis_impl(function->impl) || progress;
return progress;
}
{
bool progress = false;
- nir_foreach_overload(shader, overload) {
- if (overload->impl) {
- nir_foreach_block(overload->impl, opt_undef_block, &progress);
+ nir_foreach_function(shader, function) {
+ if (function->impl) {
+ nir_foreach_block(function->impl, opt_undef_block, &progress);
if (progress)
- nir_metadata_preserve(overload->impl,
+ nir_metadata_preserve(function->impl,
nir_metadata_block_index |
nir_metadata_dominance);
}
{
FILE *fp = state->fp;
- fprintf(fp, "call %s ", instr->callee->function->name);
+ fprintf(fp, "call %s ", instr->callee->name);
for (unsigned i = 0; i < instr->num_params; i++) {
if (i != 0)
{
FILE *fp = state->fp;
- fprintf(fp, "\nimpl %s ", impl->overload->function->name);
+ fprintf(fp, "\nimpl %s ", impl->function->name);
for (unsigned i = 0; i < impl->num_params; i++) {
if (i != 0)
}
static void
-print_function_overload(nir_function_overload *overload,
- print_state *state)
+print_function(nir_function *function, print_state *state)
{
FILE *fp = state->fp;
- fprintf(fp, "decl_overload %s ", overload->function->name);
+ fprintf(fp, "decl_function %s ", function->name);
- for (unsigned i = 0; i < overload->num_params; i++) {
+ for (unsigned i = 0; i < function->num_params; i++) {
if (i != 0)
fprintf(fp, ", ");
- switch (overload->params[i].param_type) {
+ switch (function->params[i].param_type) {
case nir_parameter_in:
fprintf(fp, "in ");
break;
unreachable("Invalid parameter type");
}
- glsl_print_type(overload->params[i].type, fp);
+ glsl_print_type(function->params[i].type, fp);
}
- if (overload->return_type != NULL) {
- if (overload->num_params != 0)
+ if (function->return_type != NULL) {
+ if (function->num_params != 0)
fprintf(fp, ", ");
fprintf(fp, "returning ");
- glsl_print_type(overload->return_type, fp);
+ glsl_print_type(function->return_type, fp);
}
fprintf(fp, "\n");
- if (overload->impl != NULL) {
- print_function_impl(overload->impl, state);
+ if (function->impl != NULL) {
+ print_function_impl(function->impl, state);
return;
}
}
-static void
-print_function(nir_function *func, print_state *state)
-{
- foreach_list_typed(nir_function_overload, overload, node, &func->overload_list) {
- print_function_overload(overload, state);
- }
-}
-
static void
init_print_state(print_state *state, nir_shader *shader, FILE *fp)
{
static void
add_var_use_shader(nir_shader *shader, struct set *live)
{
- nir_foreach_overload(shader, overload) {
- if (overload->impl) {
- nir_foreach_block(overload->impl, add_var_use_block, live);
+ nir_foreach_function(shader, function) {
+ if (function->impl) {
+ nir_foreach_block(function->impl, add_var_use_block, live);
}
}
}
progress = remove_dead_vars(&shader->globals, live) || progress;
- nir_foreach_overload(shader, overload) {
- if (overload->impl) {
- if (remove_dead_vars(&overload->impl->locals, live)) {
- nir_metadata_preserve(overload->impl, nir_metadata_block_index |
+ nir_foreach_function(shader, function) {
+ if (function->impl) {
+ if (remove_dead_vars(&function->impl->locals, live)) {
+ nir_metadata_preserve(function->impl, nir_metadata_block_index |
nir_metadata_dominance |
nir_metadata_live_ssa_defs);
progress = true;
{
bool progress = false;
- nir_foreach_overload(shader, overload) {
- if (overload->impl)
- progress = split_var_copies_impl(overload->impl) || progress;
+ nir_foreach_function(shader, function) {
+ if (function->impl)
+ progress = split_var_copies_impl(function->impl) || progress;
}
return progress;
sweep_function(nir_shader *nir, nir_function *f)
{
ralloc_steal(nir, f);
+ ralloc_steal(nir, f->params);
- foreach_list_typed(nir_function_overload, overload, node, &f->overload_list) {
- ralloc_steal(nir, overload);
- ralloc_steal(nir, overload->params);
- if (overload->impl)
- sweep_impl(nir, overload->impl);
- }
+ if (f->impl)
+ sweep_impl(nir, f->impl);
}
void
void
nir_convert_to_ssa(nir_shader *shader)
{
- nir_foreach_overload(shader, overload) {
- if (overload->impl)
- nir_convert_to_ssa_impl(overload->impl);
+ nir_foreach_function(shader, function) {
+ if (function->impl)
+ nir_convert_to_ssa_impl(function->impl);
}
}
static void
validate_function_impl(nir_function_impl *impl, validate_state *state)
{
- assert(impl->overload->impl == impl);
+ assert(impl->function->impl == impl);
assert(impl->cf_node.parent == NULL);
- assert(impl->num_params == impl->overload->num_params);
+ assert(impl->num_params == impl->function->num_params);
for (unsigned i = 0; i < impl->num_params; i++)
- assert(impl->params[i]->type == impl->overload->params[i].type);
+ assert(impl->params[i]->type == impl->function->params[i].type);
- if (glsl_type_is_void(impl->overload->return_type))
+ if (glsl_type_is_void(impl->function->return_type))
assert(impl->return_var == NULL);
else
- assert(impl->return_var->type == impl->overload->return_type);
+ assert(impl->return_var->type == impl->function->return_type);
assert(exec_list_is_empty(&impl->end_block->instr_list));
assert(impl->end_block->successors[0] == NULL);
nir_foreach_block(impl, postvalidate_ssa_defs_block, state);
}
-static void
-validate_function_overload(nir_function_overload *overload,
- validate_state *state)
-{
- if (overload->impl != NULL)
- validate_function_impl(overload->impl, state);
-}
-
static void
validate_function(nir_function *func, validate_state *state)
{
- exec_list_validate(&func->overload_list);
- foreach_list_typed(nir_function_overload, overload, node, &func->overload_list) {
- assert(overload->function == func);
- validate_function_overload(overload, state);
+ if (func->impl != NULL) {
+ assert(func->impl->function == func);
+ validate_function_impl(func->impl, state);
}
}
nir_emit_system_values();
/* get the main function and emit it */
- nir_foreach_overload(nir, overload) {
- assert(strcmp(overload->function->name, "main") == 0);
- assert(overload->impl);
- nir_emit_impl(overload->impl);
+ nir_foreach_function(nir, function) {
+ assert(strcmp(function->name, "main") == 0);
+ assert(function->impl);
+ nir_emit_impl(function->impl);
}
}
nir_system_values[i] = fs_reg();
}
- nir_foreach_overload(nir, overload) {
- assert(strcmp(overload->function->name, "main") == 0);
- assert(overload->impl);
- nir_foreach_block(overload->impl, emit_system_values_block, this);
+ nir_foreach_function(nir, function) {
+ assert(strcmp(function->name, "main") == 0);
+ assert(function->impl);
+ nir_foreach_block(function->impl, emit_system_values_block, this);
}
}
/* This pass needs actual constants */
nir_opt_constant_folding(nir);
- nir_foreach_overload(nir, overload) {
- if (overload->impl) {
- nir_builder_init(¶ms.b, overload->impl);
- nir_foreach_block(overload->impl, add_const_offset_to_base, ¶ms);
- nir_foreach_block(overload->impl, remap_vs_attrs, &inputs_read);
+ nir_foreach_function(nir, function) {
+ if (function->impl) {
+ nir_builder_init(¶ms.b, function->impl);
+ nir_foreach_block(function->impl, add_const_offset_to_base, ¶ms);
+ nir_foreach_block(function->impl, remap_vs_attrs, &inputs_read);
}
}
}
/* This pass needs actual constants */
nir_opt_constant_folding(nir);
- nir_foreach_overload(nir, overload) {
- if (overload->impl) {
- nir_builder_init(¶ms.b, overload->impl);
- nir_foreach_block(overload->impl, add_const_offset_to_base, ¶ms);
- nir_foreach_block(overload->impl, remap_inputs_with_vue_map,
+ nir_foreach_function(nir, function) {
+ if (function->impl) {
+ nir_builder_init(¶ms.b, function->impl);
+ nir_foreach_block(function->impl, add_const_offset_to_base, ¶ms);
+ nir_foreach_block(function->impl, remap_inputs_with_vue_map,
&input_vue_map);
}
}
/* This pass needs actual constants */
nir_opt_constant_folding(nir);
- nir_foreach_overload(nir, overload) {
- if (overload->impl) {
- nir_builder_init(¶ms.b, overload->impl);
- nir_foreach_block(overload->impl, add_const_offset_to_base, ¶ms);
- nir_builder_init(&state.b, overload->impl);
- nir_foreach_block(overload->impl, remap_patch_urb_offsets, &state);
+ nir_foreach_function(nir, function) {
+ if (function->impl) {
+ nir_builder_init(¶ms.b, function->impl);
+ nir_foreach_block(function->impl, add_const_offset_to_base, ¶ms);
+ nir_builder_init(&state.b, function->impl);
+ nir_foreach_block(function->impl, remap_patch_urb_offsets, &state);
}
}
break;
/* This pass needs actual constants */
nir_opt_constant_folding(nir);
- nir_foreach_overload(nir, overload) {
- if (overload->impl) {
- nir_builder_init(¶ms.b, overload->impl);
- nir_foreach_block(overload->impl, add_const_offset_to_base, ¶ms);
- nir_builder_init(&state.b, overload->impl);
- nir_foreach_block(overload->impl, remap_patch_urb_offsets, &state);
+ nir_foreach_function(nir, function) {
+ if (function->impl) {
+ nir_builder_init(¶ms.b, function->impl);
+ nir_foreach_block(function->impl, add_const_offset_to_base, ¶ms);
+ nir_builder_init(&state.b, function->impl);
+ nir_foreach_block(function->impl, remap_patch_urb_offsets, &state);
}
}
break;
if (unlikely(debug_enabled)) {
/* Re-index SSA defs so we print more sensible numbers. */
- nir_foreach_overload(nir, overload) {
- if (overload->impl)
- nir_index_ssa_defs(overload->impl);
+ nir_foreach_function(nir, function) {
+ if (function->impl)
+ nir_index_ssa_defs(function->impl);
}
fprintf(stderr, "NIR (SSA form) for %s shader:\n",
void
brw_nir_analyze_boolean_resolves(nir_shader *shader)
{
- nir_foreach_overload(shader, overload)
- if (overload->impl)
- analyze_boolean_resolves_impl(overload->impl);
+ nir_foreach_function(shader, function) {
+ if (function->impl)
+ analyze_boolean_resolves_impl(function->impl);
+ }
}
{
bool progress = false;
- nir_foreach_overload(shader, overload) {
- if (overload->impl)
- progress |= brw_nir_opt_peephole_ffma_impl(overload->impl);
+ nir_foreach_function(shader, function) {
+ if (function->impl)
+ progress |= brw_nir_opt_peephole_ffma_impl(function->impl);
}
return progress;
nir_setup_system_values();
/* get the main function and emit it */
- nir_foreach_overload(nir, overload) {
- assert(strcmp(overload->function->name, "main") == 0);
- assert(overload->impl);
- nir_emit_impl(overload->impl);
+ nir_foreach_function(nir, function) {
+ assert(strcmp(function->name, "main") == 0);
+ assert(function->impl);
+ nir_emit_impl(function->impl);
}
}
nir_system_values[i] = dst_reg();
}
- nir_foreach_overload(nir, overload) {
- assert(strcmp(overload->function->name, "main") == 0);
- assert(overload->impl);
- nir_foreach_block(overload->impl, setup_system_values_block, this);
+ nir_foreach_function(nir, function) {
+ assert(strcmp(function->name, "main") == 0);
+ assert(function->impl);
+ nir_foreach_block(function->impl, setup_system_values_block, this);
}
}
}
nir_function *func = nir_function_create(s, "main");
- nir_function_overload *overload = nir_function_overload_create(func);
- nir_function_impl *impl = nir_function_impl_create(overload);
+ nir_function_impl *impl = nir_function_impl_create(func);
c->build.shader = s;
c->build.impl = impl;