isaspec: Add support for custom meta information
authorChristian Gmeiner <cgmeiner@igalia.com>
Tue, 29 Aug 2023 10:49:08 +0000 (12:49 +0200)
committerMarge Bot <emma+marge@anholt.net>
Tue, 3 Oct 2023 12:07:04 +0000 (12:07 +0000)
Allows every user of isaspec to add custom meta information
to any bitset. This can be quite handy if you want to know
how many sources your instruction have, if this instruction has
a dest or provide some names for sources that can be used
by some debug tools.

All you need is to sprinkle <meta> tags in the xml file and
provide custom attributes.
  <meta has_dest="1" num_sources="3" .. />

With get_meta() method of any bitset you can get access to
the dict with all the attributes. get_meta() walks the whole
tree to collect all <meta> tags on the way to the root node.

Signed-off-by: Christian Gmeiner <cgmeiner@igalia.com>
Reviewed-by: Rob Clark <robdclark@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/25451>

src/compiler/isaspec/isa.py

index 27e9794..32defb8 100644 (file)
@@ -258,6 +258,7 @@ class BitSet(object):
         self.xml = xml
         self.name = xml.attrib['name']
         self.display_name = xml.attrib['displayname'] if 'displayname' in xml.attrib else self.name
+        self.meta = {}
 
         # Used for generated encoder, to de-duplicate encoding for
         # similar instructions:
@@ -287,6 +288,9 @@ class BitSet(object):
             if 'max' in gen.attrib:
                 self.gen_max = int(gen.attrib['max'])
 
+        if xml.find('meta') is not None:
+            self.meta = xml.find('meta').attrib
+
         # Collect up the match/dontcare/mask bitmasks for
         # this bitset case:
         self.match = 0
@@ -381,6 +385,17 @@ class BitSet(object):
             return self.isa.bitsets[self.extends].get_root()
         return self
 
+    def get_meta(self):
+        meta = {}
+
+        if self.extends is not None:
+            meta = self.isa.bitsets[self.extends].get_meta()
+
+        if self.meta:
+            meta.update(self.meta)
+
+        return meta
+
 class BitSetTemplate(object):
     """Class that encapsulates a template declaration
     """