isaspec: Do not emit duplicate field encodes
authorRob Clark <robdclark@chromium.org>
Wed, 13 Oct 2021 17:55:16 +0000 (10:55 -0700)
committerMarge Bot <eric+marge@anholt.net>
Fri, 15 Oct 2021 15:52:33 +0000 (15:52 +0000)
If an <override> overrides the definition of a field, don't emit
encoding for both the override's definition and the fallback.  (See
"SAMP" in #cat5-src3).  It is harmless currently, because (in this
case) it will just re-encode the low bits of "SAMP".  But when we
start asserting on that the field being encoded fits in the allowed
number of bits, the re-encoding of the fallback field definition
will start triggering asserts.

Signed-off-by: Rob Clark <robdclark@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13353>

src/compiler/isaspec/encode.py

index b581a56..9307ac0 100755 (executable)
@@ -554,6 +554,13 @@ isa = s.isa
 <%
     if case.expr is not None:
         visited_exprs.append(case.expr)
+
+    # per-expression-case track display-field-names that we have
+    # already emitted encoding for.  It is possible that an
+    # <override> case overrides a given field (for ex. #cat5-src3)
+    # and we don't want to emit encoding for both the override and
+    # the fallback
+    seen_fields = {}
 %>
     ${case_pre(root, case.expr)}
 %   for df in case.display_fields():
@@ -569,6 +576,13 @@ isa = s.isa
               # We are in an 'else'/'else-if' leg that we wouldn't
               # go down due to passing an earlier if()
               continue
+
+          if not expr in seen_fields.keys():
+              seen_fields[expr] = []
+
+          if f.field.name in seen_fields[expr]:
+              continue
+          seen_fields[expr].append(f.field.name)
 %>
            ${case_pre(root, expr)}
 %         if f.field.get_c_typename() == 'TYPE_BITSET':