nir/builder: add support for inserting before/after blocks
authorConnor Abbott <cwabbott0@gmail.com>
Tue, 23 Jun 2015 17:34:22 +0000 (10:34 -0700)
committerConnor Abbott <cwabbott0@gmail.com>
Tue, 23 Jun 2015 17:34:22 +0000 (10:34 -0700)
src/glsl/nir/nir_builder.h

index cffe38abf0e4de539144d5c66cdcb0fdb5ae4ed0..7d449262585db7d2bfab6ef9f766a506d0c06f05 100644 (file)
@@ -28,6 +28,10 @@ struct exec_list;
 
 typedef struct nir_builder {
    struct exec_list *cf_node_list;
+
+   nir_block *before_block;
+   nir_block *after_block;
+
    nir_instr *before_instr;
    nir_instr *after_instr;
 
@@ -48,6 +52,30 @@ nir_builder_insert_after_cf_list(nir_builder *build,
                                  struct exec_list *cf_node_list)
 {
    build->cf_node_list = cf_node_list;
+   build->before_block = NULL;
+   build->after_block = NULL;
+   build->before_instr = NULL;
+   build->after_instr = NULL;
+}
+
+static inline void
+nir_builder_insert_before_block(nir_builder *build,
+                                nir_block *block)
+{
+   build->cf_node_list = NULL;
+   build->before_block = block;
+   build->after_block = NULL;
+   build->before_instr = NULL;
+   build->after_instr = NULL;
+}
+
+static inline void
+nir_builder_insert_after_block(nir_builder *build,
+                                nir_block *block)
+{
+   build->cf_node_list = NULL;
+   build->before_block = NULL;
+   build->after_block = block;
    build->before_instr = NULL;
    build->after_instr = NULL;
 }
@@ -56,6 +84,8 @@ static inline void
 nir_builder_insert_before_instr(nir_builder *build, nir_instr *before_instr)
 {
    build->cf_node_list = NULL;
+   build->before_block = NULL;
+   build->after_block = NULL;
    build->before_instr = before_instr;
    build->after_instr = NULL;
 }
@@ -64,6 +94,8 @@ static inline void
 nir_builder_insert_after_instr(nir_builder *build, nir_instr *after_instr)
 {
    build->cf_node_list = NULL;
+   build->before_block = NULL;
+   build->after_block = NULL;
    build->before_instr = NULL;
    build->after_instr = after_instr;
 }
@@ -73,6 +105,10 @@ nir_builder_instr_insert(nir_builder *build, nir_instr *instr)
 {
    if (build->cf_node_list) {
       nir_instr_insert_after_cf_list(build->cf_node_list, instr);
+   } else if (build->before_block) {
+      nir_instr_insert_before_block(build->before_block, instr);
+   } else if (build->after_block) {
+      nir_instr_insert_after_block(build->after_block, instr);
    } else if (build->before_instr) {
       nir_instr_insert_before(build->before_instr, instr);
    } else {