[Mesa-dev] [PATCH 3/5] nir: Move nir_instr_get_dest_ssa_def to nir.c / nir.h

Thomas Helland thomashelland90 at gmail.com
Tue Jul 14 15:08:07 PDT 2015


This was originally located in nir_opt_cse.
Move it out for reuse.

Signed-off-by: Thomas Helland <thomashelland90 at gmail.com>
---
This probably is not that smart. We can ofcourse roll our
own in value range pass. It was just so conventient at the time.
 src/glsl/nir/nir.c         | 21 +++++++++++++++++++++
 src/glsl/nir/nir.h         |  3 +++
 src/glsl/nir/nir_opt_cse.c | 20 --------------------
 3 files changed, 24 insertions(+), 20 deletions(-)

diff --git a/src/glsl/nir/nir.c b/src/glsl/nir/nir.c
index 78ff886..4234593 100644
--- a/src/glsl/nir/nir.c
+++ b/src/glsl/nir/nir.c
@@ -1594,6 +1594,27 @@ nir_foreach_ssa_def(nir_instr *instr, nir_foreach_ssa_def_cb cb, void *state)
    }
 }
 
+nir_ssa_def *
+nir_instr_get_dest_ssa_def(nir_instr *instr)
+{
+   switch (instr->type) {
+   case nir_instr_type_alu:
+      assert(nir_instr_as_alu(instr)->dest.dest.is_ssa);
+      return &nir_instr_as_alu(instr)->dest.dest.ssa;
+   case nir_instr_type_load_const:
+      return &nir_instr_as_load_const(instr)->def;
+   case nir_instr_type_phi:
+      assert(nir_instr_as_phi(instr)->dest.is_ssa);
+      return &nir_instr_as_phi(instr)->dest.ssa;
+   case nir_instr_type_intrinsic:
+      assert(nir_instr_as_intrinsic(instr)->dest.is_ssa);
+      return &nir_instr_as_intrinsic(instr)->dest.ssa;
+   default:
+      unreachable("We never ask for any of these");
+      return NULL;
+   }
+}
+
 static bool
 visit_src(nir_src *src, nir_foreach_src_cb cb, void *state)
 {
diff --git a/src/glsl/nir/nir.h b/src/glsl/nir/nir.h
index e9a506c..0837a9b 100644
--- a/src/glsl/nir/nir.h
+++ b/src/glsl/nir/nir.h
@@ -1560,6 +1560,9 @@ bool nir_foreach_ssa_def(nir_instr *instr, nir_foreach_ssa_def_cb cb,
 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_ssa_def *
+nir_instr_get_dest_ssa_def(nir_instr *instr);
+
 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);
diff --git a/src/glsl/nir/nir_opt_cse.c b/src/glsl/nir/nir_opt_cse.c
index 553906e..348c416 100644
--- a/src/glsl/nir/nir_opt_cse.c
+++ b/src/glsl/nir/nir_opt_cse.c
@@ -205,26 +205,6 @@ nir_instr_can_cse(nir_instr *instr)
    return false;
 }
 
-static nir_ssa_def *
-nir_instr_get_dest_ssa_def(nir_instr *instr)
-{
-   switch (instr->type) {
-   case nir_instr_type_alu:
-      assert(nir_instr_as_alu(instr)->dest.dest.is_ssa);
-      return &nir_instr_as_alu(instr)->dest.dest.ssa;
-   case nir_instr_type_load_const:
-      return &nir_instr_as_load_const(instr)->def;
-   case nir_instr_type_phi:
-      assert(nir_instr_as_phi(instr)->dest.is_ssa);
-      return &nir_instr_as_phi(instr)->dest.ssa;
-   case nir_instr_type_intrinsic:
-      assert(nir_instr_as_intrinsic(instr)->dest.is_ssa);
-      return &nir_instr_as_intrinsic(instr)->dest.ssa;
-   default:
-      unreachable("We never ask for any of these");
-   }
-}
-
 static void
 nir_opt_cse_instr(nir_instr *instr, struct cse_state *state)
 {
-- 
2.4.5



More information about the mesa-dev mailing list