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 --- 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 -p IndexType +# CHECK-LABEL: +print IndexType +print IndexType +# CHECK: mlir::IndexType -# CHECK: cast +# CHECK-LABEL: +print IntegerType +print IntegerType +# CHECK: mlir::IntegerType # CHECK: width = 3 # CHECK: Unsigned -p IntegerType - -# CHECK: cast -p FloatType - -# CHECK: cast -# CHECK: shapeSize = 2 -# CHECK: shapeElements[0] = 4 -# CHECK: shapeElements[1] = 5 -p MemRefType -# CHECK: cast -# CHECK: memorySpace = 6 -p UnrankedMemRefType +# CHECK-LABEL: +print FloatType +print FloatType +# CHECK: mlir::Float32Type -# CHECK: cast -# 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 +# 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 -p UnknownLoc +# CHECK-LABEL: +print Result +print Result +# CHECK: mlir::Float32Type +# CHECK: outOfLineIndex = 42 + +# CHECK-LABEL: +print Value +print Value +# CHECK: OutOfLineOpResult -# CHECK: cast -# 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 +# CHECK-LABEL: +print OpaqueLoc +print OpaqueLoc +# CHECK: mlir::OpaqueLoc # CHECK: underlyingLocation = 9 -p OpaqueLoc -# CHECK: cast -# CHECK: name = "foo" +# CHECK-LABEL: +print NameLoc +print NameLoc +# CHECK: mlir::NameLoc +# CHECK: "foo" # CHECK: mlir::UnknownLoc -p NameLoc -# CHECK: cast +# CHECK-LABEL: +print CallSiteLoc +print CallSiteLoc +# CHECK: mlir::CallSiteLoc # CHECK: callee # CHECK: mlir::FileLineColLoc # CHECK: caller # CHECK: mlir::OpaqueLoc -p CallSiteLoc -# CHECK: cast -# 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 -p UnitAttr +# CHECK-LABEL: +print UnitAttr +print UnitAttr +# CHECK: mlir::UnitAttr -# CHECK: cast -p FloatAttr +# CHECK-LABEL: +print FloatAttr +print FloatAttr +# CHECK: mlir::FloatAttr -# CHECK: cast -p IntegerAttr +# CHECK-LABEL: +print IntegerAttr +print IntegerAttr +# CHECK: mlir::IntegerAttr -# CHECK: cast +# CHECK-LABEL: +print TypeAttr +print TypeAttr +# CHECK: mlir::TypeAttr # CHECK: mlir::IndexType -p TypeAttr -# CHECK: cast +# CHECK-LABEL: +print ArrayAttr +print ArrayAttr +# CHECK: mlir::ArrayAttr # CHECK: llvm::ArrayRef of length 1 # CHECK: mlir::UnitAttr -p ArrayAttr -# CHECK: cast +# CHECK-LABEL: +print StringAttr +print StringAttr +# CHECK: mlir::StringAttr # CHECK: value = "foo" -p StringAttr -# CHECK: cast -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 --- a/mlir/utils/gdb-scripts/prettyprinters.py +++ b/mlir/utils/gdb-scripts/prettyprinters.py @@ -12,9 +12,9 @@ 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 @@ 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 @@ 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 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 @@ 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 @@ '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 @@ 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.