nir: add nir function clone

this just refactors the existing functionality so we can use it elsewhere.

Reviewed-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24687>
This commit is contained in:
Dave Airlie 2023-08-15 16:01:51 +10:00 committed by Marge Bot
parent 5dea1ac64c
commit 8f982a7fd9
2 changed files with 14 additions and 8 deletions

View file

@ -4602,6 +4602,7 @@ nir_instr *nir_instr_clone_deep(nir_shader *s, const nir_instr *orig,
nir_alu_instr *nir_alu_instr_clone(nir_shader *s, const nir_alu_instr *orig);
nir_shader *nir_shader_clone(void *mem_ctx, const nir_shader *s);
nir_function *nir_function_clone(nir_shader *ns, const nir_function *fxn);
nir_function_impl *nir_function_impl_clone(nir_shader *shader,
const nir_function_impl *fi);
nir_constant *nir_constant_clone(const nir_constant *c, nir_variable *var);

View file

@ -654,18 +654,13 @@ nir_function_impl_clone(nir_shader *shader, const nir_function_impl *fi)
return nfi;
}
static nir_function *
clone_function(clone_state *state, const nir_function *fxn, nir_shader *ns)
nir_function *
nir_function_clone(nir_shader *ns, const nir_function *fxn)
{
assert(ns == state->ns);
nir_function *nfxn = nir_function_create(ns, fxn->name);
/* Needed for call instructions */
add_remap(state, nfxn, fxn);
nfxn->num_params = fxn->num_params;
if (fxn->num_params) {
nfxn->params = ralloc_array(state->ns, nir_parameter, fxn->num_params);
nfxn->params = ralloc_array(ns, nir_parameter, fxn->num_params);
memcpy(nfxn->params, fxn->params, sizeof(nir_parameter) * fxn->num_params);
}
nfxn->is_entrypoint = fxn->is_entrypoint;
@ -676,7 +671,17 @@ clone_function(clone_state *state, const nir_function *fxn, nir_shader *ns)
* function and those will get processed as we clone the function_impls.
* We stop here and do function_impls as a second pass.
*/
return nfxn;
}
static nir_function *
clone_function(clone_state *state, const nir_function *fxn, nir_shader *ns)
{
assert(ns == state->ns);
nir_function *nfxn = nir_function_clone(ns, fxn);
/* Needed for call instructions */
add_remap(state, nfxn, fxn);
return nfxn;
}