Skip to content

Commit e9b3884

Browse files
committed
Add GDB prettyprinters for a few more MLIR types.
Reviewed By: dblaikie, jpienaar Differential Revision: https://reviews.llvm.org/D87159
1 parent 1b60f63 commit e9b3884

File tree

8 files changed

+417
-8
lines changed

8 files changed

+417
-8
lines changed

debuginfo-tests/CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@ set(DEBUGINFO_TEST_DEPS
2222
not
2323
)
2424

25+
if ("mlir" IN_LIST LLVM_ENABLE_PROJECTS)
26+
add_llvm_executable(check-gdb-mlir-support
27+
llvm-prettyprinters/gdb/mlir-support.cpp
28+
)
29+
target_include_directories(check-gdb-mlir-support PRIVATE ${LLVM_EXTERNAL_MLIR_SOURCE_DIR}/include)
30+
target_link_libraries(check-gdb-mlir-support PRIVATE MLIRIR)
31+
list(APPEND DEBUGINFO_TEST_DEPS check-gdb-mlir-support)
32+
set(MLIR_SOURCE_DIR ${LLVM_EXTERNAL_MLIR_SOURCE_DIR})
33+
endif()
34+
2535
if("compiler-rt" IN_LIST LLVM_ENABLE_PROJECTS)
2636
# llgdb-tests/asan.c and other asan* files.
2737
if(TARGET asan)

debuginfo-tests/lit.cfg.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,6 @@ def get_required_attr(config, attr_name):
157157
if apple_lldb_vers < 1000:
158158
config.available_features.add('apple-lldb-pre-1000')
159159

160-
llvm_config.feature_config([('--build-mode', {
161-
'Debug|RelWithDebInfo': 'debug-info'
162-
})])
160+
llvm_config.feature_config(
161+
[('--build-mode', {'Debug|RelWithDebInfo': 'debug-info'})]
162+
)

debuginfo-tests/lit.site.cfg.py.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ config.target_triple = "@TARGET_TRIPLE@"
2020
config.host_arch = "@HOST_ARCH@"
2121
config.is_msvc = lit.util.pythonize_bool("@MSVC@")
2222

23+
config.mlir_src_root = "@MLIR_SOURCE_DIR@"
24+
2325
config.llvm_use_sanitizer = "@LLVM_USE_SANITIZER@"
2426

2527
config.python3_executable = "@Python3_EXECUTABLE@"

debuginfo-tests/llvm-prettyprinters/gdb/lit.local.cfg

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ import lit.util
44
if 'native' not in config.available_features or lit.util.which('gdb') is None:
55
config.unsupported = True
66

7+
if config.mlir_src_root:
8+
config.substitutions.append(("%mlir_src_root", config.mlir_src_root))
9+
config.available_features.add('mlir')
10+
711
config.suffixes = ['.gdb']
812

913

debuginfo-tests/llvm-prettyprinters/gdb/llvm-support.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,13 @@ auto SimpleIlist = []() {
5353
return Result;
5454
}();
5555

56-
// Check expected instances to avoid compile errors.
57-
auto CheckExpectedValue = static_cast<bool>(ExpectedValue);
58-
auto CheckExpectedError = static_cast<bool>(ExpectedError);
59-
60-
int main() { return 0; }
56+
int main() {
57+
// Reference symbols that might otherwise be stripped.
58+
ArrayRef[0];
59+
MutableArrayRef[0];
60+
!ExpectedValue;
61+
!ExpectedError;
62+
*OptionalValue;
63+
*OptionalNone;
64+
return 0;
65+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#include "mlir/IR/Identifier.h"
2+
#include "mlir/IR/Location.h"
3+
#include "mlir/IR/MLIRContext.h"
4+
#include "mlir/IR/OperationSupport.h"
5+
#include "mlir/IR/StandardTypes.h"
6+
7+
mlir::MLIRContext Context;
8+
9+
auto Identifier = mlir::Identifier::get("foo", &Context);
10+
mlir::OperationName OperationName("FooOp", &Context);
11+
mlir::Value Value({reinterpret_cast<void *>(0x8),
12+
mlir::Value::Kind::TrailingOpResult});
13+
14+
mlir::Type Type(nullptr);
15+
mlir::Type IndexType = mlir::IndexType::get(&Context);
16+
mlir::Type IntegerType =
17+
mlir::IntegerType::get(3, mlir::IntegerType::Unsigned, &Context);
18+
mlir::Type FloatType = mlir::Float32Type::get(&Context);
19+
mlir::Type MemRefType = mlir::MemRefType::get({4, 5}, FloatType);
20+
mlir::Type UnrankedMemRefType = mlir::UnrankedMemRefType::get(IntegerType, 6);
21+
mlir::Type VectorType = mlir::VectorType::get({1, 2}, FloatType);
22+
mlir::Type TupleType =
23+
mlir::TupleType::get(mlir::TypeRange({IndexType, FloatType}), &Context);
24+
25+
auto UnknownLoc = mlir::UnknownLoc::get(&Context);
26+
auto FileLineColLoc = mlir::FileLineColLoc::get("file", 7, 8, &Context);
27+
auto OpaqueLoc = mlir::OpaqueLoc::get<uintptr_t>(9, &Context);
28+
auto NameLoc = mlir::NameLoc::get(Identifier, &Context);
29+
auto CallSiteLoc = mlir::CallSiteLoc::get(FileLineColLoc, OpaqueLoc);
30+
auto FusedLoc = mlir::FusedLoc::get({FileLineColLoc, NameLoc}, &Context);
31+
32+
mlir::Attribute UnitAttr = mlir::UnitAttr::get(&Context);
33+
mlir::Attribute FloatAttr = mlir::FloatAttr::get(FloatType, 1.0);
34+
mlir::Attribute IntegerAttr = mlir::IntegerAttr::get(IntegerType, 10);
35+
mlir::Attribute TypeAttr = mlir::TypeAttr::get(IndexType);
36+
mlir::Attribute ArrayAttr = mlir::ArrayAttr::get({UnitAttr}, &Context);
37+
mlir::Attribute StringAttr = mlir::StringAttr::get("foo", &Context);
38+
mlir::Attribute ElementsAttr = mlir::DenseElementsAttr::get(
39+
VectorType.cast<mlir::ShapedType>(), llvm::ArrayRef<float>{2.0f, 3.0f});
40+
41+
int main() { return 0; }
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
# 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
2+
# REQUIRES: debug-info
3+
# REQUIRES: mlir
4+
5+
break main
6+
run
7+
8+
# CHECK: "foo"
9+
p Identifier
10+
11+
# CHECK: "FooOp"
12+
p OperationName
13+
14+
# CHECK: 0x8
15+
# CHECK: TrailingOpResult
16+
p Value
17+
18+
# CHECK: impl = 0x0
19+
p Type
20+
21+
# CHECK: cast<mlir::IndexType>
22+
p IndexType
23+
24+
# CHECK: cast<mlir::IntegerType>
25+
# CHECK: width = 3
26+
# CHECK: Unsigned
27+
p IntegerType
28+
29+
# CHECK: cast<mlir::Float32Type>
30+
p FloatType
31+
32+
# CHECK: cast<mlir::MemRefType>
33+
# CHECK: shapeSize = 2
34+
# CHECK: shapeElements[0] = 4
35+
# CHECK: shapeElements[1] = 5
36+
p MemRefType
37+
38+
# CHECK: cast<mlir::UnrankedMemRefType>
39+
# CHECK: memorySpace = 6
40+
p UnrankedMemRefType
41+
42+
# CHECK: cast<mlir::VectorType>
43+
# CHECK: shapeSize = 2
44+
# CHECK: shapeElements[0] = 1
45+
# CHECK: shapeElements[1] = 2
46+
p VectorType
47+
48+
# CHECK: cast<mlir::TupleType>
49+
# CHECK: numElements = 2
50+
# CHECK: elements[0]
51+
# CHECK: mlir::IndexType
52+
# CHECK: elements[1]
53+
# CHECK: mlir::Float32Type
54+
p TupleType
55+
56+
# CHECK: cast<mlir::UnknownLoc>
57+
p UnknownLoc
58+
59+
# CHECK: cast<mlir::FileLineColLoc>
60+
# CHECK: filename = "file"
61+
# CHECK: line = 7
62+
# CHECK: column = 8
63+
p FileLineColLoc
64+
65+
# CHECK: cast<mlir::OpaqueLoc>
66+
# CHECK: underlyingLocation = 9
67+
p OpaqueLoc
68+
69+
# CHECK: cast<mlir::NameLoc>
70+
# CHECK: name = "foo"
71+
# CHECK: mlir::UnknownLoc
72+
p NameLoc
73+
74+
# CHECK: cast<mlir::CallSiteLoc>
75+
# CHECK: callee
76+
# CHECK: mlir::FileLineColLoc
77+
# CHECK: caller
78+
# CHECK: mlir::OpaqueLoc
79+
p CallSiteLoc
80+
81+
# CHECK: cast<mlir::FusedLoc>
82+
# CHECK: numLocs = 2
83+
# CHECK: locs[0]
84+
# CHECK: mlir::FileLineColLoc
85+
# CHECK: locs[1]
86+
# CHECK: mlir::NameLoc
87+
p FusedLoc
88+
89+
# CHECK: cast<mlir::UnitAttr>
90+
p UnitAttr
91+
92+
# CHECK: cast<mlir::FloatAttr>
93+
p FloatAttr
94+
95+
# CHECK: cast<mlir::IntegerAttr>
96+
p IntegerAttr
97+
98+
# CHECK: cast<mlir::TypeAttr>
99+
# CHECK: mlir::IndexType
100+
p TypeAttr
101+
102+
# CHECK: cast<mlir::ArrayAttr>
103+
# CHECK: llvm::ArrayRef of length 1
104+
# CHECK: mlir::UnitAttr
105+
p ArrayAttr
106+
107+
# CHECK: cast<mlir::StringAttr>
108+
# CHECK: value = "foo"
109+
p StringAttr
110+
111+
# CHECK: cast<mlir::DenseIntOrFPElementsAttr>
112+
p ElementsAttr

0 commit comments

Comments
 (0)