From: Jason Ekstrand Date: Wed, 28 Oct 2015 04:34:56 +0000 (-0700) Subject: nir: Add a helper for creating a "bare" nir_function_impl X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=98291b8f2cad24d6467cf35e00135e4b015cb1f2;p=mesa.git nir: Add a helper for creating a "bare" nir_function_impl This is useful if you want to clone a single function_impl if, for instance, you wanted to do function inlining. --- diff --git a/src/glsl/nir/nir.c b/src/glsl/nir/nir.c index 94bb76034a2..b1a53308381 100644 --- a/src/glsl/nir/nir.c +++ b/src/glsl/nir/nir.c @@ -268,16 +268,11 @@ cf_init(nir_cf_node *node, nir_cf_node_type type) } nir_function_impl * -nir_function_impl_create(nir_function_overload *overload) +nir_function_impl_create_bare(nir_shader *shader) { - assert(overload->impl == NULL); - - void *mem_ctx = ralloc_parent(overload); + nir_function_impl *impl = ralloc(shader, nir_function_impl); - nir_function_impl *impl = ralloc(mem_ctx, nir_function_impl); - - overload->impl = impl; - impl->overload = overload; + impl->overload = NULL; cf_init(&impl->cf_node, nir_cf_node_function); @@ -292,8 +287,8 @@ nir_function_impl_create(nir_function_overload *overload) impl->valid_metadata = nir_metadata_none; /* create start & end blocks */ - nir_block *start_block = nir_block_create(mem_ctx); - nir_block *end_block = nir_block_create(mem_ctx); + nir_block *start_block = nir_block_create(shader); + nir_block *end_block = nir_block_create(shader); start_block->cf_node.parent = &impl->cf_node; end_block->cf_node.parent = &impl->cf_node; impl->end_block = end_block; @@ -305,6 +300,20 @@ nir_function_impl_create(nir_function_overload *overload) return impl; } +nir_function_impl * +nir_function_impl_create(nir_function_overload *overload) +{ + assert(overload->impl == NULL); + + nir_function_impl *impl = + nir_function_impl_create_bare(overload->function->shader); + + overload->impl = impl; + impl->overload = overload; + + return impl; +} + nir_block * nir_block_create(nir_shader *shader) { diff --git a/src/glsl/nir/nir.h b/src/glsl/nir/nir.h index 0cf5f80c591..2ae83b49aef 100644 --- a/src/glsl/nir/nir.h +++ b/src/glsl/nir/nir.h @@ -1696,6 +1696,8 @@ nir_function *nir_function_create(nir_shader *shader, const char *name); nir_function_overload *nir_function_overload_create(nir_function *func); nir_function_impl *nir_function_impl_create(nir_function_overload *func); +/** creates a function_impl that isn't tied to any particular overload */ +nir_function_impl *nir_function_impl_create_bare(nir_shader *shader); nir_block *nir_block_create(nir_shader *shader); nir_if *nir_if_create(nir_shader *shader);