[Mesa-dev] [RFC] nir/builder: Add support for easily building control-flow

Jason Ekstrand jason at jlekstrand.net
Wed Feb 15 16:43:33 UTC 2017


---
 src/compiler/nir/nir_builder.h | 41 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)

diff --git a/src/compiler/nir/nir_builder.h b/src/compiler/nir/nir_builder.h
index 194d327..cdfc15b 100644
--- a/src/compiler/nir/nir_builder.h
+++ b/src/compiler/nir/nir_builder.h
@@ -81,6 +81,47 @@ nir_builder_cf_insert(nir_builder *build, nir_cf_node *cf)
    nir_cf_node_insert(build->cursor, cf);
 }
 
+static inline void
+nir_push_if(nir_builder *build, nir_ssa_def *condition)
+{
+   nir_if *nif = nir_if_create(build->shader);
+   nif->condition = nir_src_for_ssa(condition);
+   nir_builder_cf_insert(build, &nif->cf_node);
+   build->cursor = nir_before_cf_list(&nif->then_list);
+}
+
+static inline void
+nir_push_else(nir_builder *build)
+{
+   nir_block *block = nir_cursor_current_block(build->cursor);
+   nir_if *nif = nir_cf_node_as_if(block->cf_node.parent);
+   build->cursor = nir_before_cf_list(&nif->else_list);
+}
+
+static inline void
+nir_pop_if(nir_builder *build)
+{
+   nir_block *block = nir_cursor_current_block(build->cursor);
+   nir_if *nif = nir_cf_node_as_if(block->cf_node.parent);
+   build->cursor = nir_after_cf_node(&nif->cf_node);
+}
+
+static inline void
+nir_push_loop(nir_builder *build)
+{
+   nir_loop *loop = nir_loop_create(build->shader);
+   nir_builder_cf_insert(build, &loop->cf_node);
+   build->cursor = nir_before_cf_list(&loop->body);
+}
+
+static inline void
+nir_pop_loop(nir_builder *build)
+{
+   nir_block *block = nir_cursor_current_block(build->cursor);
+   nir_loop *loop = nir_cf_node_as_loop(block->cf_node.parent);
+   build->cursor = nir_after_cf_node(&loop->cf_node);
+}
+
 static inline nir_ssa_def *
 nir_ssa_undef(nir_builder *build, unsigned num_components, unsigned bit_size)
 {
-- 
2.5.0.400.gff86faf



More information about the mesa-dev mailing list