summaryrefslogtreecommitdiffstats
path: root/src/glsl
diff options
context:
space:
mode:
authorEric Anholt <[email protected]>2015-03-27 14:18:54 -0700
committerEric Anholt <[email protected]>2015-04-03 11:50:18 -0700
commitec029702054ddc4e098ebb96e76c7451190d649f (patch)
tree7b88c051db503085ca7948fbb7b03801b3d3b010 /src/glsl
parent328375d2742a3394dc481fc5fae6c4a5d797b4e7 (diff)
nir: Add an interface for the builder to insert instructions before.
So far we'd only used nir_builder to build brand new programs. But if we're doing modifications to instructions (like in a lowering pass), then we want to generate new stuff before the instruction we're modifying. Reviewed-by: Jason Ekstrand <[email protected]>
Diffstat (limited to 'src/glsl')
-rw-r--r--src/glsl/nir/nir_builder.h27
1 files changed, 23 insertions, 4 deletions
diff --git a/src/glsl/nir/nir_builder.h b/src/glsl/nir/nir_builder.h
index 6459e9a7e29..ecbdbe3d12d 100644
--- a/src/glsl/nir/nir_builder.h
+++ b/src/glsl/nir/nir_builder.h
@@ -28,6 +28,8 @@ struct exec_list;
typedef struct nir_builder {
struct exec_list *cf_node_list;
+ nir_instr *before_instr;
+
nir_shader *shader;
nir_function_impl *impl;
} nir_builder;
@@ -47,6 +49,23 @@ nir_builder_insert_after_cf_list(nir_builder *build,
build->cf_node_list = cf_node_list;
}
+static inline void
+nir_builder_insert_before_instr(nir_builder *build, nir_instr *before_instr)
+{
+ build->before_instr = before_instr;
+}
+
+static inline void
+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 {
+ assert(build->before_instr);
+ nir_instr_insert_before(build->before_instr, instr);
+ }
+}
+
static inline nir_ssa_def *
nir_build_imm(nir_builder *build, unsigned num_components, nir_const_value value)
{
@@ -57,7 +76,7 @@ nir_build_imm(nir_builder *build, unsigned num_components, nir_const_value value
load_const->value = value;
- nir_instr_insert_after_cf_list(build->cf_node_list, &load_const->instr);
+ nir_builder_instr_insert(build, &load_const->instr);
return &load_const->def;
}
@@ -125,7 +144,7 @@ nir_build_alu(nir_builder *build, nir_op op, nir_ssa_def *src0,
nir_ssa_dest_init(&instr->instr, &instr->dest.dest, num_components, NULL);
instr->dest.write_mask = (1 << num_components) - 1;
- nir_instr_insert_after_cf_list(build->cf_node_list, &instr->instr);
+ nir_builder_instr_insert(build, &instr->instr);
return &instr->dest.dest.ssa;
}
@@ -172,7 +191,7 @@ nir_fmov_alu(nir_builder *build, nir_alu_src src, unsigned num_components)
nir_ssa_dest_init(&mov->instr, &mov->dest.dest, num_components, NULL);
mov->dest.write_mask = (1 << num_components) - 1;
mov->src[0] = src;
- nir_instr_insert_after_cf_list(build->cf_node_list, &mov->instr);
+ nir_builder_instr_insert(build, &mov->instr);
return &mov->dest.dest.ssa;
}
@@ -184,7 +203,7 @@ nir_imov_alu(nir_builder *build, nir_alu_src src, unsigned num_components)
nir_ssa_dest_init(&mov->instr, &mov->dest.dest, num_components, NULL);
mov->dest.write_mask = (1 << num_components) - 1;
mov->src[0] = src;
- nir_instr_insert_after_cf_list(build->cf_node_list, &mov->instr);
+ nir_builder_instr_insert(build, &mov->instr);
return &mov->dest.dest.ssa;
}