nir: Add a function for comparing two sources
authorJason Ekstrand <jason.ekstrand@intel.com>
Fri, 12 Dec 2014 20:52:11 +0000 (12:52 -0800)
committerJason Ekstrand <jason.ekstrand@intel.com>
Thu, 15 Jan 2015 15:19:00 +0000 (07:19 -0800)
Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
src/glsl/nir/nir.c
src/glsl/nir/nir.h

index b64ec4073a406fc5ce75b418edbd43cc4b939a15..56891dc340148bd461c6e9441dd302569ee50008 100644 (file)
@@ -1634,6 +1634,33 @@ nir_foreach_src(nir_instr *instr, nir_foreach_src_cb cb, void *state)
    return nir_foreach_dest(instr, visit_dest_indirect, &dest_state);
 }
 
+bool
+nir_srcs_equal(nir_src src1, nir_src src2)
+{
+   if (src1.is_ssa) {
+      if (src2.is_ssa) {
+         return src1.ssa == src2.ssa;
+      } else {
+         return false;
+      }
+   } else {
+      if (src2.is_ssa) {
+         return false;
+      } else {
+         if ((src1.reg.indirect == NULL) != (src2.reg.indirect == NULL))
+            return false;
+
+         if (src1.reg.indirect) {
+            if (!nir_srcs_equal(*src1.reg.indirect, *src2.reg.indirect))
+               return false;
+         }
+
+         return src1.reg.reg == src2.reg.reg &&
+                src1.reg.base_offset == src2.reg.base_offset;
+      }
+   }
+}
+
 void
 nir_ssa_def_init(nir_function_impl *impl, nir_instr *instr, nir_ssa_def *def,
                  unsigned num_components, const char *name)
index 6c1f66828433f97ef62ca36cf831a2c9e6e315b3..126e9c841c79f7b1b7a04ea3c247544e98788aac 100644 (file)
@@ -1301,6 +1301,8 @@ 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);
 
+bool nir_srcs_equal(nir_src src1, nir_src src2);
+
 void nir_ssa_def_init(nir_function_impl *impl, nir_instr *instr,
                       nir_ssa_def *def, unsigned num_components,
                       const char *name);