nir: Add function nir_function_set_impl

This function is added for create strong relationship between
nir_function_impl and nir_function.

So that nir_function->impl->function == nir_function is always true when
(nir_function->impl != NULL && nir_function->impl != NIR_SERIALIZE_FUNC_HAS_IMPL)

And indeed this invariant is already done in functions validate_function and validate_function_impl
of nir_validate

Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
Reviewed-by: Alyssa Rosenzweig <alyssa@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/23820>
This commit is contained in:
Yonggang Luo
2023-06-23 11:57:47 +08:00
committed by Marge Bot
parent 9fa38cf142
commit 5b29463746
6 changed files with 16 additions and 13 deletions
+1 -2
View File
@@ -276,8 +276,7 @@ libclc_add_generic_variants(nir_shader *shader)
for (unsigned i = 0; i < gfunc->num_params; i++)
gfunc->params[i] = func->params[i];
gfunc->impl = nir_function_impl_clone(shader, func->impl);
gfunc->impl->function = gfunc;
nir_function_set_impl(gfunc, nir_function_impl_clone(shader, func->impl));
/* Rewrite any global pointers to generic */
nir_foreach_block(block, gfunc->impl) {
+1 -4
View File
@@ -667,10 +667,7 @@ nir_function_impl_create(nir_function *function)
assert(function->impl == NULL);
nir_function_impl *impl = nir_function_impl_create_bare(function->shader);
function->impl = impl;
impl->function = function;
nir_function_set_impl(function, impl);
return impl;
}
+10
View File
@@ -3402,6 +3402,9 @@ typedef struct nir_function {
/** The implementation of this function.
*
* If the function is only declared and not implemented, this is NULL.
*
* Unless setting to NULL or NIR_SERIALIZE_FUNC_HAS_IMPL, set with
* nir_function_set_impl to maintain IR invariants.
*/
nir_function_impl *impl;
@@ -4090,6 +4093,13 @@ void nir_sort_variables_with_modes(nir_shader *shader,
/** creates a function and adds it to the shader's list of functions */
nir_function *nir_function_create(nir_shader *shader, const char *name);
static inline void
nir_function_set_impl(nir_function *func, nir_function_impl *impl)
{
func->impl = impl;
impl->function = func;
}
nir_function_impl *nir_function_impl_create(nir_function *func);
/** creates a function_impl that isn't tied to any particular function */
nir_function_impl *nir_function_impl_create_bare(nir_shader *shader);
+1 -2
View File
@@ -771,8 +771,7 @@ nir_shader_clone(void *mem_ctx, const nir_shader *s)
*/
nir_foreach_function(fxn, s) {
nir_function *nfxn = remap_global(&state, fxn);
nfxn->impl = clone_function_impl(&state, fxn->impl);
nfxn->impl->function = nfxn;
nir_function_set_impl(nfxn, clone_function_impl(&state, fxn->impl));
}
ns->info = s->info;
+2 -3
View File
@@ -2001,10 +2001,9 @@ write_function_impl(write_ctx *ctx, const nir_function_impl *fi)
}
static nir_function_impl *
read_function_impl(read_ctx *ctx, nir_function *fxn)
read_function_impl(read_ctx *ctx)
{
nir_function_impl *fi = nir_function_impl_create_bare(ctx->nir);
fi->function = fxn;
fi->structured = blob_read_uint8(ctx->blob);
bool preamble = blob_read_uint8(ctx->blob);
@@ -2223,7 +2222,7 @@ nir_deserialize(void *mem_ctx,
nir_foreach_function(fxn, ctx.nir) {
if (fxn->impl == NIR_SERIALIZE_FUNC_HAS_IMPL)
fxn->impl = read_function_impl(&ctx, fxn);
nir_function_set_impl(fxn, read_function_impl(&ctx));
}
ctx.nir->constant_data_size = blob_read_uint32(blob);
+1 -2
View File
@@ -194,8 +194,7 @@ dxil_nir_split_tess_ctrl(nir_shader *nir, nir_function **patch_const_func)
*patch_const_func = nir_function_create(nir, "PatchConstantFunc");
nir_function_impl *patch_const_func_impl = nir_function_impl_clone(nir, entrypoint);
(*patch_const_func)->impl = patch_const_func_impl;
patch_const_func_impl->function = *patch_const_func;
nir_function_set_impl(*patch_const_func, patch_const_func_impl);
remove_hs_intrinsics(entrypoint);
prune_patch_function_to_intrinsic_and_srcs(patch_const_func_impl);