summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason Ekstrand <[email protected]>2014-12-08 17:34:23 -0800
committerJason Ekstrand <[email protected]>2015-01-15 07:19:03 -0800
commita3ad7fdf337023a1631bcc3ca44c733deb62b9fb (patch)
tree4ae5ee0adb43dc39e5bceb843dfbb823c53eca2d
parent940ccc45ad4110cf720d1de8652d484f47a7b439 (diff)
nir: Add a helper for getting a constant value from an SSA source
Reviewed-by: Connor Abbott <[email protected]>
-rw-r--r--src/glsl/nir/nir.c19
-rw-r--r--src/glsl/nir/nir.h1
2 files changed, 20 insertions, 0 deletions
diff --git a/src/glsl/nir/nir.c b/src/glsl/nir/nir.c
index b6bd78d05e6..c376de1cf19 100644
--- a/src/glsl/nir/nir.c
+++ b/src/glsl/nir/nir.c
@@ -1672,6 +1672,25 @@ nir_foreach_src(nir_instr *instr, nir_foreach_src_cb cb, void *state)
return nir_foreach_dest(instr, visit_dest_indirect, &dest_state);
}
+nir_const_value *
+nir_src_as_const_value(nir_src src)
+{
+ if (!src.is_ssa)
+ return NULL;
+
+ if (src.ssa->parent_instr->type != nir_instr_type_load_const)
+ return NULL;
+
+ nir_load_const_instr *load = nir_instr_as_load_const(src.ssa->parent_instr);
+
+ if (load->array_elems == 0)
+ return &load->value;
+ if (load->array_elems == 1)
+ return load->array;
+ else
+ return NULL;
+}
+
bool
nir_srcs_equal(nir_src src1, nir_src src2)
{
diff --git a/src/glsl/nir/nir.h b/src/glsl/nir/nir.h
index ff1f7964fce..660cc4b8bb6 100644
--- a/src/glsl/nir/nir.h
+++ b/src/glsl/nir/nir.h
@@ -1326,6 +1326,7 @@ typedef bool (*nir_foreach_src_cb)(nir_src *src, void *state);
bool nir_foreach_dest(nir_instr *instr, nir_foreach_dest_cb cb, void *state);
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);