Mesa (master): nir/search: Fold src_is_bool()/alu_instr_is_bool() into src_is_type().

Kenneth Graunke kwg at kemper.freedesktop.org
Thu Aug 18 08:31:45 UTC 2016


Module: Mesa
Branch: master
Commit: e8543feba790b68edfcacc9554967118029b88f8
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=e8543feba790b68edfcacc9554967118029b88f8

Author: Kenneth Graunke <kenneth at whitecape.org>
Date:   Wed Aug 17 15:02:59 2016 -0700

nir/search: Fold src_is_bool()/alu_instr_is_bool() into src_is_type().

I don't want src_is_bool() and src_is_type(x, nir_type_bool) to behave
differently.  Having the logic spread out over three functions makes it
harder to decide where to put new logic, as well.

So, combine them all.  It's a bit simpler because there's now only one
recursive function rather than a pair of mutually recursive functions.

Signed-off-by: Kenneth Graunke <kenneth at whitecape.org>
Reviewed-by: Jason Ekstrand <jason at jlekstrand.net>

---

 src/compiler/nir/nir_search.c | 50 ++++++++++++++++---------------------------
 1 file changed, 19 insertions(+), 31 deletions(-)

diff --git a/src/compiler/nir/nir_search.c b/src/compiler/nir/nir_search.c
index bd12312..bfa00c2 100644
--- a/src/compiler/nir/nir_search.c
+++ b/src/compiler/nir/nir_search.c
@@ -42,34 +42,6 @@ match_expression(const nir_search_expression *expr, nir_alu_instr *instr,
 
 static const uint8_t identity_swizzle[] = { 0, 1, 2, 3 };
 
-static bool alu_instr_is_bool(nir_alu_instr *instr);
-
-static bool
-src_is_bool(nir_src src)
-{
-   if (!src.is_ssa)
-      return false;
-   if (src.ssa->parent_instr->type != nir_instr_type_alu)
-      return false;
-   return alu_instr_is_bool(nir_instr_as_alu(src.ssa->parent_instr));
-}
-
-static bool
-alu_instr_is_bool(nir_alu_instr *instr)
-{
-   switch (instr->op) {
-   case nir_op_iand:
-   case nir_op_ior:
-   case nir_op_ixor:
-      return src_is_bool(instr->src[0].src) && src_is_bool(instr->src[1].src);
-   case nir_op_inot:
-      return src_is_bool(instr->src[0].src);
-   default:
-      return (nir_alu_type_get_base_type(nir_op_infos[instr->op].output_type)
-             == nir_type_bool);
-   }
-}
-
 /**
  * Check if a source produces a value of the given type.
  *
@@ -83,13 +55,29 @@ src_is_type(nir_src src, nir_alu_type type)
    if (!src.is_ssa)
       return false;
 
+   /* Turn nir_type_bool32 into nir_type_bool...they're the same thing. */
+   if (nir_alu_type_get_base_type(type) == nir_type_bool)
+      type = nir_type_bool;
+
    if (src.ssa->parent_instr->type == nir_instr_type_alu) {
       nir_alu_instr *src_alu = nir_instr_as_alu(src.ssa->parent_instr);
       nir_alu_type output_type = nir_op_infos[src_alu->op].output_type;
 
-      return nir_alu_type_get_base_type(output_type) == type ||
-             (nir_alu_type_get_base_type(type) == nir_type_bool &&
-              alu_instr_is_bool(src_alu));
+      if (type == nir_type_bool) {
+         switch (src_alu->op) {
+         case nir_op_iand:
+         case nir_op_ior:
+         case nir_op_ixor:
+            return src_is_type(src_alu->src[0].src, nir_type_bool) &&
+                   src_is_type(src_alu->src[1].src, nir_type_bool);
+         case nir_op_inot:
+            return src_is_type(src_alu->src[0].src, nir_type_bool);
+         default:
+            break;
+         }
+      }
+
+      return nir_alu_type_get_base_type(output_type) == type;
    }
 
    /* don't know */




More information about the mesa-commit mailing list