[Mesa-dev] [PATCH 03/15] nir/algebraic: Improve a couple error messages

Jason Ekstrand jason at jlekstrand.net
Fri Nov 9 03:45:04 UTC 2018


There is a possible functional change here because we're now using
canonical bit classes in the check in validate().  If anything, it
should be more precise than the old check.  The other changes just make
us print out the canonical classes in the error messages.  We do this
because, if we have an actual bit size, the canonical class will be the
bit size whereas any other class may just be -2 or some other nonsense
used as part of generating the equivalence relationships.
---
 src/compiler/nir/nir_algebraic.py | 30 +++++++++++++++++++++---------
 1 file changed, 21 insertions(+), 9 deletions(-)

diff --git a/src/compiler/nir/nir_algebraic.py b/src/compiler/nir/nir_algebraic.py
index 728196136ab..5b2ec82448b 100644
--- a/src/compiler/nir/nir_algebraic.py
+++ b/src/compiler/nir/nir_algebraic.py
@@ -339,16 +339,21 @@ class BitSizeValidator(object):
       self._propagate_bit_class_down(search, search_dst_class)
 
       replace_dst_class = self._validate_bit_class_up(replace)
-      if replace_dst_class != 0:
-         assert search_dst_class != 0, \
+
+      # Get canonical classes before we compare anything
+      search_dst_class = self._class_relation.get_canonical(search_dst_class)
+      replace_dst_class = self._class_relation.get_canonical(replace_dst_class)
+      if replace_dst_class != 0 and search_dst_class != replace_dst_class:
+         assert search_dst_class > 0, \
                 'Search expression matches any bit size but replace ' \
-                'expression can only generate {0}-bit values' \
-                .format(replace_dst_class)
+                'expression can only generate {} values' \
+                .format(self._bit_class_to_str(replace_dst_class))
 
-         assert search_dst_class == replace_dst_class, \
-                'Search expression matches any {0}-bit values but replace ' \
-                'expression can only generates {1}-bit values' \
-                .format(search_dst_class, replace_dst_class)
+         assert False, \
+                'Search expression matches any {} values but replace ' \
+                'expression can only generate {} values' \
+                .format(self._bit_class_to_str(search_dst_class),
+                        self._bit_class_to_str(replace_dst_class))
 
       self._validate_bit_class_down(replace, search_dst_class)
 
@@ -367,13 +372,20 @@ class BitSizeValidator(object):
          assert canon_var_class < 0 or canon_bit_class < 0 or \
                 canon_var_class == canon_bit_class, \
                 'Variable {0} cannot be both {1}-bit and {2}-bit' \
-                .format(str(var), bit_class, var_class)
+                .format(str(var), canon_bit_class, canon_var_class)
          var_class = self._class_relation.add_equiv(var_class, bit_class)
          self._var_classes[var.index] = var_class
 
    def _get_var_bit_class(self, var):
       return self._class_relation.get_canonical(self._var_classes[var.index])
 
+   def _bit_class_to_str(self, bit_class):
+      bit_class = self._class_relation.get_canonical(bit_class)
+      if bit_class < 0:
+         return 'bit-class {0}'.format(bit_class)
+      else:
+         return '{0}-bit'.format(bit_class)
+
    def _propagate_bit_size_up(self, val):
       if isinstance(val, (Constant, Variable)):
          return val.bit_size
-- 
2.19.1



More information about the mesa-dev mailing list