[Mlir-commits] [mlir] 635f8f3 - Update mlir GDB printers

Christian Sigg llvmlistbot at llvm.org
Thu Jan 6 13:20:39 PST 2022


Author: Christian Sigg
Date: 2022-01-06T22:20:25+01:00
New Revision: 635f8f3c95dd7e4460555997503abbf7da3b1203

URL: https://github.com/llvm/llvm-project/commit/635f8f3c95dd7e4460555997503abbf7da3b1203
DIFF: https://github.com/llvm/llvm-project/commit/635f8f3c95dd7e4460555997503abbf7da3b1203.diff

LOG: Update mlir GDB printers

Update prettyprinters.py to match MLIR changes.

This has gone unnoticed because no build bot is running tests with debug info.

I will look into what we can do about this separately. There is
https://green.lab.llvm.org/green/view/LLDB/job/lldb-cmake/,
from Apple. The Debug Info tests are failing despite the green result.

See https://github.com/llvm/llvm-project/issues/48872.

Note: the llvm-support.gdb test only works with Debug,
but not RelWithDebInfo because some checked symbols are stripped.

Reviewed By: dblaikie

Differential Revision: https://reviews.llvm.org/D116646

Added: 
    

Modified: 
    cross-project-tests/debuginfo-tests/llvm-prettyprinters/gdb/mlir-support.gdb
    mlir/utils/gdb-scripts/prettyprinters.py

Removed: 
    


################################################################################
diff  --git a/cross-project-tests/debuginfo-tests/llvm-prettyprinters/gdb/mlir-support.gdb b/cross-project-tests/debuginfo-tests/llvm-prettyprinters/gdb/mlir-support.gdb
index 2a82412401231..de6b5f1e580e3 100644
--- a/cross-project-tests/debuginfo-tests/llvm-prettyprinters/gdb/mlir-support.gdb
+++ b/cross-project-tests/debuginfo-tests/llvm-prettyprinters/gdb/mlir-support.gdb
@@ -1,112 +1,144 @@
-# RUN: gdb -q -batch -n -iex 'source %mlir_src_root/utils/gdb-scripts/prettyprinters.py' -iex 'source %llvm_src_root/utils/gdb-scripts/prettyprinters.py' -x %s %llvm_tools_dir/check-gdb-mlir-support | FileCheck %s
+# RUN: gdb -q -batch -n \
+# RUN:   -iex 'source %mlir_src_root/utils/gdb-scripts/prettyprinters.py' \
+# RUN:   -iex 'source %llvm_src_root/utils/gdb-scripts/prettyprinters.py' \
+# RUN:   -ex 'source -v %s' %llvm_tools_dir/check-gdb-mlir-support \
+# RUN: | FileCheck %s
 # REQUIRES: debug-info
 # REQUIRES: mlir
 
 break main
 run
+set print pretty on
 
+# CHECK-LABEL: +print Identifier
+print Identifier
 # CHECK: "foo"
-p Identifier
 
+# CHECK-LABEL: +print OperationName
+print OperationName
 # CHECK: "FooOp"
-p OperationName
-
-# CHECK: 0x8
-# CHECK: TrailingOpResult
-p Value
 
+# CHECK-LABEL: +print Type
+print Type
 # CHECK: impl = 0x0
-p Type
 
-# CHECK: cast<mlir::IndexType>
-p IndexType
+# CHECK-LABEL: +print IndexType
+print IndexType
+# CHECK: mlir::IndexType
 
-# CHECK: cast<mlir::IntegerType>
+# CHECK-LABEL: +print IntegerType
+print IntegerType
+# CHECK: mlir::IntegerType
 # CHECK: width = 3
 # CHECK: Unsigned
-p IntegerType
-
-# CHECK: cast<mlir::Float32Type>
-p FloatType
-
-# CHECK: cast<mlir::MemRefType>
-# CHECK: shapeSize = 2
-# CHECK: shapeElements[0] = 4
-# CHECK: shapeElements[1] = 5
-p MemRefType
 
-# CHECK: cast<mlir::UnrankedMemRefType>
-# CHECK: memorySpace = 6
-p UnrankedMemRefType
+# CHECK-LABEL: +print FloatType
+print FloatType
+# CHECK: mlir::Float32Type
 
-# CHECK: cast<mlir::VectorType>
-# CHECK: shapeSize = 2
-# CHECK: shapeElements[0] = 1
-# CHECK: shapeElements[1] = 2
-p VectorType
+# CHECK-LABEL: +print MemRefType
+print MemRefType
+# CHECK: mlir::MemRefType
+# CHECK: shape = llvm::ArrayRef of length 2 = {4, 5}
+# CHECK: elementType
+# CHECK: mlir::Float32Type
 
-# CHECK: cast<mlir::TupleType>
+# CHECK-LABEL: +print UnrankedMemRefType
+print UnrankedMemRefType
+# CHECK: mlir::UnrankedMemRefType
+# CHECK: elementType
+# CHECK: mlir::IntegerType
+# CHECK: memorySpace
+# CHECK: 6
+
+# CHECK-LABEL: +print VectorType
+print VectorType
+# CHECK: mlir::VectorType
+# CHECK: shape = llvm::ArrayRef of length 2 = {1, 2}
+
+# CHECK-LABEL: +print TupleType
+print TupleType
+# CHECK: mlir::TupleType
 # CHECK: numElements = 2
 # CHECK: elements[0]
 # CHECK: mlir::IndexType
 # CHECK: elements[1]
 # CHECK: mlir::Float32Type
-p TupleType
 
-# CHECK: cast<mlir::UnknownLoc>
-p UnknownLoc
+# CHECK-LABEL: +print Result
+print Result
+# CHECK: mlir::Float32Type
+# CHECK: outOfLineIndex = 42
+
+# CHECK-LABEL: +print Value
+print Value
+# CHECK: OutOfLineOpResult
 
-# CHECK: cast<mlir::FileLineColLoc>
-# CHECK: filename = "file"
+# CHECK-LABEL: +print UnknownLoc
+print UnknownLoc
+# CHECK: mlir::UnknownLoc
+
+# CHECK-LABEL: +print FileLineColLoc
+print FileLineColLoc
+# CHECK: mlir::FileLineColLoc
+# CHECK: "file"
 # CHECK: line = 7
 # CHECK: column = 8
-p FileLineColLoc
 
-# CHECK: cast<mlir::OpaqueLoc>
+# CHECK-LABEL: +print OpaqueLoc
+print OpaqueLoc
+# CHECK: mlir::OpaqueLoc
 # CHECK: underlyingLocation = 9
-p OpaqueLoc
 
-# CHECK: cast<mlir::NameLoc>
-# CHECK: name = "foo"
+# CHECK-LABEL: +print NameLoc
+print NameLoc
+# CHECK: mlir::NameLoc
+# CHECK: "foo"
 # CHECK: mlir::UnknownLoc
-p NameLoc
 
-# CHECK: cast<mlir::CallSiteLoc>
+# CHECK-LABEL: +print CallSiteLoc
+print CallSiteLoc
+# CHECK: mlir::CallSiteLoc
 # CHECK: callee
 # CHECK: mlir::FileLineColLoc
 # CHECK: caller
 # CHECK: mlir::OpaqueLoc
-p CallSiteLoc
 
-# CHECK: cast<mlir::FusedLoc>
-# CHECK: numLocs = 2
-# CHECK: locs[0]
+# CHECK-LABEL: +print FusedLoc
+print FusedLoc
+# CHECK: mlir::FusedLoc
+# CHECK: locations = llvm::ArrayRef of length 2
 # CHECK: mlir::FileLineColLoc
-# CHECK: locs[1]
 # CHECK: mlir::NameLoc
-p FusedLoc
 
-# CHECK: cast<mlir::UnitAttr>
-p UnitAttr
+# CHECK-LABEL: +print UnitAttr
+print UnitAttr
+# CHECK: mlir::UnitAttr
 
-# CHECK: cast<mlir::FloatAttr>
-p FloatAttr
+# CHECK-LABEL: +print FloatAttr
+print FloatAttr
+# CHECK: mlir::FloatAttr
 
-# CHECK: cast<mlir::IntegerAttr>
-p IntegerAttr
+# CHECK-LABEL: +print IntegerAttr
+print IntegerAttr
+# CHECK: mlir::IntegerAttr
 
-# CHECK: cast<mlir::TypeAttr>
+# CHECK-LABEL: +print TypeAttr
+print TypeAttr
+# CHECK: mlir::TypeAttr
 # CHECK: mlir::IndexType
-p TypeAttr
 
-# CHECK: cast<mlir::ArrayAttr>
+# CHECK-LABEL: +print ArrayAttr
+print ArrayAttr
+# CHECK: mlir::ArrayAttr
 # CHECK: llvm::ArrayRef of length 1
 # CHECK: mlir::UnitAttr
-p ArrayAttr
 
-# CHECK: cast<mlir::StringAttr>
+# CHECK-LABEL: +print StringAttr
+print StringAttr
+# CHECK: mlir::StringAttr
 # CHECK: value = "foo"
-p StringAttr
 
-# CHECK: cast<mlir::DenseIntOrFPElementsAttr>
-p ElementsAttr
+# CHECK-LABEL: +print ElementsAttr
+print ElementsAttr
+# CHECK: mlir::DenseIntOrFPElementsAttr

diff  --git a/mlir/utils/gdb-scripts/prettyprinters.py b/mlir/utils/gdb-scripts/prettyprinters.py
index b495b7cee01ba..fcdb6641da109 100644
--- a/mlir/utils/gdb-scripts/prettyprinters.py
+++ b/mlir/utils/gdb-scripts/prettyprinters.py
@@ -12,9 +12,9 @@ def __init__(self, val):
   def children(self):
     for field in self.val.type.fields():
       if field.is_base_class:
-        yield ('<%s>' % field.name, self.val.cast(field.type))
+        yield '<%s>' % field.name, self.val.cast(field.type)
       else:
-        yield (field.name, self.val[field.name])
+        yield field.name, self.val[field.name]
 
 
 class TupleTypeStoragePrinter(StoragePrinter):
@@ -28,24 +28,6 @@ def children(self):
       yield 'elements[%u]' % i, elements[i]
 
 
-class RankedTypeStoragePrinter(StoragePrinter):
-
-  def children(self):
-    for child in StoragePrinter.children(self):
-      yield child
-    for i in range(self.val['shapeSize']):
-      yield 'shapeElements[%u]' % i, self.val['shapeElements'][i]
-
-
-class MemRefTypeStoragePrinter(RankedTypeStoragePrinter):
-
-  def children(self):
-    for child in RankedTypeStoragePrinter.children(self):
-      yield child
-    for i in range(self.val['numAffineMaps']):
-      yield 'affineMapsList[%u]' % i, self.val['affineMapsList'][i]
-
-
 class FusedLocationStoragePrinter(StoragePrinter):
 
   def children(self):
@@ -57,19 +39,8 @@ def children(self):
       yield 'locs[%u]' % i, elements[i]
 
 
-class StorageUserBasePrinter:
-  """Printer for an mlir::detail::StorageUserBase instance."""
-
-  def __init__(self, val):
-    self.val = val
-
-  def children(self):
-    storage_type = self.val.type.template_argument(2)
-    yield 'impl', self.val['impl'].dereference().cast(storage_type)
-
-
 class StorageTypeMap:
-  """Maps a TypeID to the corresponding type derived from StorageUserBase.
+  """Maps a TypeID to the corresponding concrete type.
 
   Types need to be registered by name before the first lookup.
   """
@@ -109,7 +80,7 @@ def __getitem__(self, type_id):
 def get_type_id_printer(val):
   """Returns a printer of the name of a mlir::TypeID."""
 
-  class StringPrinter:
+  class TypeIdPrinter:
 
     def __init__(self, string):
       self.string = string
@@ -120,48 +91,45 @@ def to_string(self):
   concrete_type = storage_type_map[val]
   if not concrete_type:
     return None
-  return StringPrinter('"%s"' % concrete_type.name)
+  return TypeIdPrinter('mlir::TypeID::get<%s>()' % concrete_type)
 
 
 def get_attr_or_type_printer(val, get_type_id):
   """Returns a printer for mlir::Attribute or mlir::Type."""
 
-  class UpcastPrinter:
+  class AttrOrTypePrinter:
 
-    def __init__(self, val, type):
-      self.val = val.cast(type)
+    def __init__(self, type_id, impl):
+      self.type_id = type_id
+      self.impl = impl
 
     def children(self):
-      yield 'cast<%s>' % self.val.type.name, self.val
+      yield 'typeID', self.type_id
+      yield 'cast<%s>(impl)' % self.impl.type, self.impl
 
   if not val['impl']:
     return None
-  type_id = get_type_id(val['impl'].dereference())
+  impl = val['impl'].dereference()
+  type_id = get_type_id(impl)
   concrete_type = storage_type_map[type_id]
   if not concrete_type:
     return None
-  return UpcastPrinter(val, concrete_type)
+  # 3rd template argument of StorageUserBase is the storage type.
+  storage_type = concrete_type.fields()[0].type.template_argument(2)
+  if not storage_type:
+    return None
+  return AttrOrTypePrinter(type_id, impl.cast(storage_type))
 
 
-pp = gdb.printing.RegexpCollectionPrettyPrinter('MLIRSupport')
+class ImplPrinter:
+  """Printer for an instance with a single 'impl' member pointer."""
 
-# Printers for types deriving from AttributeStorage or TypeStorage.
-pp.add_printer('mlir::detail::FusedLocationStorage',
-               '^mlir::detail::FusedLocationStorage',
-               FusedLocationStoragePrinter)
-pp.add_printer('mlir::detail::VectorTypeStorage',
-               '^mlir::detail::VectorTypeStorage', RankedTypeStoragePrinter)
-pp.add_printer('mlir::detail::RankedTensorTypeStorage',
-               '^mlir::detail::RankedTensorTypeStorage',
-               RankedTypeStoragePrinter)
-pp.add_printer('mlir::detail::MemRefTypeStorage',
-               '^mlir::detail::MemRefTypeStorage$', MemRefTypeStoragePrinter)
-pp.add_printer('mlir::detail::TupleTypeStorage',
-               '^mlir::detail::TupleTypeStorage$', TupleTypeStoragePrinter)
+  def __init__(self, val):
+    self.impl = val['impl']
+
+  def children(self):
+    yield 'impl', (self.impl.dereference() if self.impl else self.impl)
 
-# Printers for Attribute::AttrBase or Type::TypeBase typedefs.
-pp.add_printer('mlir::detail::StorageUserBase',
-               '^mlir::detail::StorageUserBase<.*>$', StorageUserBasePrinter)
 
 # Printers of types deriving from Attribute::AttrBase or Type::TypeBase.
 for name in [
@@ -205,6 +173,20 @@ def children(self):
     'UnknownLoc'
 ]:
   storage_type_map.register_type('mlir::%s' % name)  # Register for upcasting.
+storage_type_map.register_type('void')  # Register default.
+
+
+pp = gdb.printing.RegexpCollectionPrettyPrinter('MLIRSupport')
+
+pp.add_printer('mlir::OperationName', '^mlir::OperationName$', ImplPrinter)
+pp.add_printer('mlir::Value', '^mlir::Value$', ImplPrinter)
+
+# Printers for types deriving from AttributeStorage or TypeStorage.
+pp.add_printer('mlir::detail::FusedLocationStorage',
+               '^mlir::detail::FusedLocationStorage',
+               FusedLocationStoragePrinter)
+pp.add_printer('mlir::detail::TupleTypeStorage',
+               '^mlir::detail::TupleTypeStorage$', TupleTypeStoragePrinter)
 
 pp.add_printer('mlir::TypeID', '^mlir::TypeID$', get_type_id_printer)
 
@@ -214,8 +196,6 @@ def add_attr_or_type_printers(name):
   get_type_id = lambda val: val['abstract%s' % name]['typeID']
   pp.add_printer('mlir::%s' % name, '^mlir::%s$' % name,
                  lambda val: get_attr_or_type_printer(val, get_type_id))
-  pp.add_printer('mlir::%sStorage' % name, '^mlir::%sStorage$' % name,
-                 lambda val: get_type_id_printer(get_type_id(val)))
 
 
 # Upcasting printers of mlir::Attribute and mlir::Type.


        


More information about the Mlir-commits mailing list