[Mesa-dev] [PATCH 3/9] nir/algebraic: add support for conditional helper functions to expressions

Timothy Arceri timothy.arceri at collabora.com
Tue Jan 10 09:41:52 UTC 2017


---
 src/compiler/nir/nir_algebraic.py | 5 ++++-
 src/compiler/nir/nir_search.c     | 3 +++
 src/compiler/nir/nir_search.h     | 8 ++++++++
 3 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/src/compiler/nir/nir_algebraic.py b/src/compiler/nir/nir_algebraic.py
index 19ac6ee..b0fa9e7 100644
--- a/src/compiler/nir/nir_algebraic.py
+++ b/src/compiler/nir/nir_algebraic.py
@@ -90,6 +90,7 @@ static const ${val.c_type} ${val.name} = {
    ${'true' if val.inexact else 'false'},
    nir_op_${val.opcode},
    { ${', '.join(src.c_ptr for src in val.sources)} },
+   ${val.cond if val.cond else 'NULL'},
 % endif
 };""")
 
@@ -185,7 +186,8 @@ class Variable(Value):
       elif self.required_type == 'float':
          return "nir_type_float"
 
-_opcode_re = re.compile(r"(?P<inexact>~)?(?P<opcode>\w+)(?:@(?P<bits>\d+))?")
+_opcode_re = re.compile(r"(?P<inexact>~)?(?P<opcode>\w+)(?:@(?P<bits>\d+))?"
+                        r"(?P<cond>\([^\)]+\))?")
 
 class Expression(Value):
    def __init__(self, expr, name_base, varset):
@@ -198,6 +200,7 @@ class Expression(Value):
       self.opcode = m.group('opcode')
       self.bit_size = int(m.group('bits')) if m.group('bits') else 0
       self.inexact = m.group('inexact') is not None
+      self.cond = m.group('cond')
       self.sources = [ Value.create(src, "{0}_{1}".format(name_base, i), varset)
                        for (i, src) in enumerate(expr[1:]) ]
 
diff --git a/src/compiler/nir/nir_search.c b/src/compiler/nir/nir_search.c
index cc17642..0d08614 100644
--- a/src/compiler/nir/nir_search.c
+++ b/src/compiler/nir/nir_search.c
@@ -264,6 +264,9 @@ static bool
 match_expression(const nir_search_expression *expr, nir_alu_instr *instr,
                  unsigned num_components, struct match_state *state)
 {
+   if (expr->cond && !expr->cond(instr))
+      return false;
+
    if (instr->op != expr->opcode)
       return false;
 
diff --git a/src/compiler/nir/nir_search.h b/src/compiler/nir/nir_search.h
index 357509a..004b61d 100644
--- a/src/compiler/nir/nir_search.h
+++ b/src/compiler/nir/nir_search.h
@@ -102,6 +102,14 @@ typedef struct {
 
    nir_op opcode;
    const nir_search_value *srcs[4];
+
+   /** Optional condition fxn ptr
+    *
+    * This allows additional constraints on expression matching, it is
+    * typically used to match an expressions uses such as the number of times
+    * the expression is used, and whether its used by an if.
+    */
+   bool (*cond)(nir_alu_instr *instr);
 } nir_search_expression;
 
 NIR_DEFINE_CAST(nir_search_value_as_variable, nir_search_value,
-- 
2.9.3



More information about the mesa-dev mailing list