diff options
author | Jason Ekstrand <[email protected]> | 2018-03-22 16:41:18 -0700 |
---|---|---|
committer | Jason Ekstrand <[email protected]> | 2018-06-22 20:15:58 -0700 |
commit | c11833ab24dcba26de1b0a5805e35a5d6761514e (patch) | |
tree | 724a419f448204358d7dd732d51b724dea80bc17 /src/compiler/nir/nir.c | |
parent | 58799b6a5b3e281365bce91fac2e54903fbd2c41 (diff) |
nir,spirv: Rework function calls
This commit completely reworks function calls in NIR. Instead of having
a set of variables for the parameters and return value, nir_call_instr
now has simply has a number of sources which get mapped to load_param
intrinsics inside the functions. It's up to the client API to build an
ABI on top of that. In SPIR-V, out parameters are handled by passing
the result of a deref through as an SSA value and storing to it.
This virtue of this approach can be seen by how much it allows us to
delete from core NIR. In particular, nir_inline_functions gets halved
and goes from a fairly difficult pass to understand in detail to almost
trivial. It also simplifies spirv_to_nir somewhat because NIR functions
never were a good fit for SPIR-V.
Unfortunately, there is no good way to do this without a mega-commit.
Core NIR and SPIR-V have to be changed at the same time. This also
requires changes to anv and radv because nir_inline_functions couldn't
handle deref instructions before this change and can't work without them
after this change.
Acked-by: Rob Clark <[email protected]>
Acked-by: Bas Nieuwenhuizen <[email protected]>
Acked-by: Dave Airlie <[email protected]>
Reviewed-by: Kenneth Graunke <[email protected]>
Diffstat (limited to 'src/compiler/nir/nir.c')
-rw-r--r-- | src/compiler/nir/nir.c | 55 |
1 files changed, 21 insertions, 34 deletions
diff --git a/src/compiler/nir/nir.c b/src/compiler/nir/nir.c index d1404e82fb4..18bf7635e21 100644 --- a/src/compiler/nir/nir.c +++ b/src/compiler/nir/nir.c @@ -127,10 +127,6 @@ nir_shader_add_variable(nir_shader *shader, nir_variable *var) assert(!"nir_shader_add_variable cannot be used for local variables"); break; - case nir_var_param: - assert(!"nir_shader_add_variable cannot be used for function parameters"); - break; - case nir_var_global: exec_list_push_tail(&shader->globals, &var->node); break; @@ -207,7 +203,6 @@ nir_function_create(nir_shader *shader, const char *name) func->shader = shader; func->num_params = 0; func->params = NULL; - func->return_type = glsl_void_type(); func->impl = NULL; return func; @@ -291,9 +286,6 @@ nir_function_impl_create_bare(nir_shader *shader) exec_list_make_empty(&impl->body); exec_list_make_empty(&impl->registers); exec_list_make_empty(&impl->locals); - impl->num_params = 0; - impl->params = NULL; - impl->return_var = NULL; impl->reg_alloc = 0; impl->ssa_alloc = 0; impl->valid_metadata = nir_metadata_none; @@ -322,26 +314,6 @@ nir_function_impl_create(nir_function *function) function->impl = impl; impl->function = function; - impl->num_params = function->num_params; - impl->params = ralloc_array(function->shader, - nir_variable *, impl->num_params); - - for (unsigned i = 0; i < impl->num_params; i++) { - impl->params[i] = rzalloc(function->shader, nir_variable); - impl->params[i]->type = function->params[i].type; - impl->params[i]->data.mode = nir_var_param; - impl->params[i]->data.location = i; - } - - if (!glsl_type_is_void(function->return_type)) { - impl->return_var = rzalloc(function->shader, nir_variable); - impl->return_var->type = function->return_type; - impl->return_var->data.mode = nir_var_param; - impl->return_var->data.location = -1; - } else { - impl->return_var = NULL; - } - return impl; } @@ -539,13 +511,16 @@ nir_intrinsic_instr_create(nir_shader *shader, nir_intrinsic_op op) nir_call_instr * 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); + const unsigned num_params = callee->num_params; + nir_call_instr *instr = + rzalloc_size(shader, sizeof(*instr) + + num_params * sizeof(instr->params[0])); + instr_init(&instr->instr, nir_instr_type_call); instr->callee = callee; - instr->num_params = callee->num_params; - instr->params = ralloc_array(instr, nir_deref_var *, instr->num_params); - instr->return_deref = NULL; + instr->num_params = num_params; + for (unsigned i = 0; i < num_params; i++) + src_init(&instr->params[i]); return instr; } @@ -1441,6 +1416,17 @@ visit_intrinsic_src(nir_intrinsic_instr *instr, nir_foreach_src_cb cb, } static bool +visit_call_src(nir_call_instr *instr, nir_foreach_src_cb cb, void *state) +{ + for (unsigned i = 0; i < instr->num_params; i++) { + if (!visit_src(&instr->params[i], cb, state)) + return false; + } + + return true; +} + +static bool visit_phi_src(nir_phi_instr *instr, nir_foreach_src_cb cb, void *state) { nir_foreach_phi_src(src, instr) { @@ -1500,7 +1486,8 @@ nir_foreach_src(nir_instr *instr, nir_foreach_src_cb cb, void *state) return false; break; case nir_instr_type_call: - /* Call instructions have no regular sources */ + if (!visit_call_src(nir_instr_as_call(instr), cb, state)) + return false; break; case nir_instr_type_load_const: /* Constant load instructions have no regular sources */ |