Mesa (master): nir: Add a function for rewriting the condition of an if statement
Jason Ekstrand
jekstrand at kemper.freedesktop.org
Sat May 9 00:29:59 UTC 2015
Module: Mesa
Branch: master
Commit: f72a8d1cf06da55c215a61c085e1f29a5102182b
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=f72a8d1cf06da55c215a61c085e1f29a5102182b
Author: Jason Ekstrand <jason.ekstrand at intel.com>
Date: Fri Apr 24 10:34:30 2015 -0700
nir: Add a function for rewriting the condition of an if statement
Reviewed-by: Connor Abbott <cwabbott0 at gmail.com>
---
src/glsl/nir/nir.c | 22 ++++++++++++++++++++++
src/glsl/nir/nir.h | 1 +
2 files changed, 23 insertions(+)
diff --git a/src/glsl/nir/nir.c b/src/glsl/nir/nir.c
index 4cc074b..b8f5dd4 100644
--- a/src/glsl/nir/nir.c
+++ b/src/glsl/nir/nir.c
@@ -1895,6 +1895,28 @@ nir_instr_rewrite_src(nir_instr *instr, nir_src *src, nir_src new_src)
}
void
+nir_if_rewrite_condition(nir_if *if_stmt, nir_src new_src)
+{
+ for (nir_src *src = &if_stmt->condition; src;
+ src = src->is_ssa ? NULL : src->reg.indirect) {
+ struct set *uses = src->is_ssa ? src->ssa->if_uses
+ : src->reg.reg->if_uses;
+ struct set_entry *entry = _mesa_set_search(uses, if_stmt);
+ assert(entry);
+ _mesa_set_remove(uses, entry);
+ }
+
+ if_stmt->condition = new_src;
+
+ for (nir_src *src = &if_stmt->condition; src;
+ src = src->is_ssa ? NULL : src->reg.indirect) {
+ struct set *uses = src->is_ssa ? src->ssa->if_uses
+ : src->reg.reg->if_uses;
+ _mesa_set_add(uses, if_stmt);
+ }
+}
+
+void
nir_ssa_def_init(nir_instr *instr, nir_ssa_def *def,
unsigned num_components, const char *name)
{
diff --git a/src/glsl/nir/nir.h b/src/glsl/nir/nir.h
index a174666..aaf1c57 100644
--- a/src/glsl/nir/nir.h
+++ b/src/glsl/nir/nir.h
@@ -1549,6 +1549,7 @@ bool nir_foreach_src(nir_instr *instr, nir_foreach_src_cb cb, void *state);
nir_const_value *nir_src_as_const_value(nir_src src);
bool nir_srcs_equal(nir_src src1, nir_src src2);
void nir_instr_rewrite_src(nir_instr *instr, nir_src *src, nir_src new_src);
+void nir_if_rewrite_condition(nir_if *if_stmt, nir_src new_src);
void nir_ssa_dest_init(nir_instr *instr, nir_dest *dest,
unsigned num_components, const char *name);
More information about the mesa-commit
mailing list