nir: Add a helper for creating a "bare" nir_function_impl
authorJason Ekstrand <jason.ekstrand@intel.com>
Wed, 28 Oct 2015 04:34:56 +0000 (21:34 -0700)
committerJason Ekstrand <jason.ekstrand@intel.com>
Sat, 12 Mar 2016 23:48:36 +0000 (15:48 -0800)
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
src/compiler/nir/nir.c
src/compiler/nir/nir.h

index acb2692e2a0375b4191d4064e1596b6ea8b38698..2242317bc8d7b0eac7192c27ec74f51b7865caf3 100644 (file)
@@ -258,16 +258,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);
 
@@ -282,8 +277,8 @@ nir_function_impl_create(nir_function *function)
    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;
@@ -295,6 +290,19 @@ 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;
+
+   return impl;
+}
+
 nir_block *
 nir_block_create(nir_shader *shader)
 {
index ede56953d0a3a66bbecfe211ae3e0c138aa5490b..40169adbcf2fc8de4332a9647ee920a37dba8d74 100644 (file)
@@ -1732,6 +1732,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 function */
+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);