[Mesa-dev] [PATCH 03/12] nir: Add a helper for creating a "bare" nir_function_impl

Jason Ekstrand jason at jlekstrand.net
Sat Dec 26 11:09:26 PST 2015


This is useful if you want to clone a single function_impl if, for
instance, you wanted to do function inlining.
---
 src/glsl/nir/nir.c | 37 ++++++++++++++++++++++++-------------
 src/glsl/nir/nir.h |  2 ++
 2 files changed, 26 insertions(+), 13 deletions(-)

diff --git a/src/glsl/nir/nir.c b/src/glsl/nir/nir.c
index 13de29d..12bd30f 100644
--- a/src/glsl/nir/nir.c
+++ b/src/glsl/nir/nir.c
@@ -254,16 +254,11 @@ cf_init(nir_cf_node *node, nir_cf_node_type type)
 }
 
 nir_function_impl *
-nir_function_impl_create(nir_function *function)
+nir_function_impl_create_bare(nir_shader *shader)
 {
-   assert(function->impl == NULL);
-
-   void *mem_ctx = ralloc_parent(function);
+   nir_function_impl *impl = ralloc(shader, nir_function_impl);
 
-   nir_function_impl *impl = ralloc(mem_ctx, nir_function_impl);
-
-   function->impl = impl;
-   impl->function = function;
+   impl->function = NULL;
 
    cf_init(&impl->cf_node, nir_cf_node_function);
 
@@ -271,17 +266,16 @@ nir_function_impl_create(nir_function *function)
    exec_list_make_empty(&impl->registers);
    exec_list_make_empty(&impl->locals);
 
-   impl->num_params = function->num_params;
-   impl->params = ralloc_array(mem_ctx, nir_variable *, impl->num_params);
-
+   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;
 
    /* 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;
@@ -293,6 +287,23 @@ nir_function_impl_create(nir_function *function)
    return impl;
 }
 
+nir_function_impl *
+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;
+
+   impl->num_params = function->num_params;
+   impl->params = ralloc_array(function->shader,
+                               nir_variable *, impl->num_params);
+
+   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 562c5c5..d862bcc 100644
--- a/src/glsl/nir/nir.h
+++ b/src/glsl/nir/nir.h
@@ -1639,6 +1639,8 @@ nir_variable *nir_local_variable_create(nir_function_impl *impl,
 nir_function *nir_function_create(nir_shader *shader, const char *name);
 
 nir_function_impl *nir_function_impl_create(nir_function *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);
-- 
2.5.0.400.gff86faf



More information about the mesa-dev mailing list