Skip to content

Commit

Permalink
Add GDB prettyprinters for a few more MLIR types.
Browse files Browse the repository at this point in the history
Reviewed By: dblaikie, jpienaar

Differential Revision: https://reviews.llvm.org/D87159
  • Loading branch information
chsigg committed Sep 30, 2020
1 parent 1b60f63 commit e9b3884
Show file tree
Hide file tree
Showing 8 changed files with 417 additions and 8 deletions.
10 changes: 10 additions & 0 deletions debuginfo-tests/CMakeLists.txt
Expand Up @@ -22,6 +22,16 @@ set(DEBUGINFO_TEST_DEPS
not
)

if ("mlir" IN_LIST LLVM_ENABLE_PROJECTS)
add_llvm_executable(check-gdb-mlir-support
llvm-prettyprinters/gdb/mlir-support.cpp
)
target_include_directories(check-gdb-mlir-support PRIVATE ${LLVM_EXTERNAL_MLIR_SOURCE_DIR}/include)
target_link_libraries(check-gdb-mlir-support PRIVATE MLIRIR)
list(APPEND DEBUGINFO_TEST_DEPS check-gdb-mlir-support)
set(MLIR_SOURCE_DIR ${LLVM_EXTERNAL_MLIR_SOURCE_DIR})
endif()

if("compiler-rt" IN_LIST LLVM_ENABLE_PROJECTS)
# llgdb-tests/asan.c and other asan* files.
if(TARGET asan)
Expand Down
6 changes: 3 additions & 3 deletions debuginfo-tests/lit.cfg.py
Expand Up @@ -157,6 +157,6 @@ def get_required_attr(config, attr_name):
if apple_lldb_vers < 1000:
config.available_features.add('apple-lldb-pre-1000')

llvm_config.feature_config([('--build-mode', {
'Debug|RelWithDebInfo': 'debug-info'
})])
llvm_config.feature_config(
[('--build-mode', {'Debug|RelWithDebInfo': 'debug-info'})]
)
2 changes: 2 additions & 0 deletions debuginfo-tests/lit.site.cfg.py.in
Expand Up @@ -20,6 +20,8 @@ config.target_triple = "@TARGET_TRIPLE@"
config.host_arch = "@HOST_ARCH@"
config.is_msvc = lit.util.pythonize_bool("@MSVC@")

config.mlir_src_root = "@MLIR_SOURCE_DIR@"

config.llvm_use_sanitizer = "@LLVM_USE_SANITIZER@"

config.python3_executable = "@Python3_EXECUTABLE@"
Expand Down
4 changes: 4 additions & 0 deletions debuginfo-tests/llvm-prettyprinters/gdb/lit.local.cfg
Expand Up @@ -4,6 +4,10 @@ import lit.util
if 'native' not in config.available_features or lit.util.which('gdb') is None:
config.unsupported = True

if config.mlir_src_root:
config.substitutions.append(("%mlir_src_root", config.mlir_src_root))
config.available_features.add('mlir')

config.suffixes = ['.gdb']


15 changes: 10 additions & 5 deletions debuginfo-tests/llvm-prettyprinters/gdb/llvm-support.cpp
Expand Up @@ -53,8 +53,13 @@ auto SimpleIlist = []() {
return Result;
}();

// Check expected instances to avoid compile errors.
auto CheckExpectedValue = static_cast<bool>(ExpectedValue);
auto CheckExpectedError = static_cast<bool>(ExpectedError);

int main() { return 0; }
int main() {
// Reference symbols that might otherwise be stripped.
ArrayRef[0];
MutableArrayRef[0];
!ExpectedValue;
!ExpectedError;
*OptionalValue;
*OptionalNone;
return 0;
}
41 changes: 41 additions & 0 deletions debuginfo-tests/llvm-prettyprinters/gdb/mlir-support.cpp
@@ -0,0 +1,41 @@
#include "mlir/IR/Identifier.h"
#include "mlir/IR/Location.h"
#include "mlir/IR/MLIRContext.h"
#include "mlir/IR/OperationSupport.h"
#include "mlir/IR/StandardTypes.h"

mlir::MLIRContext Context;

auto Identifier = mlir::Identifier::get("foo", &Context);
mlir::OperationName OperationName("FooOp", &Context);
mlir::Value Value({reinterpret_cast<void *>(0x8),
mlir::Value::Kind::TrailingOpResult});

mlir::Type Type(nullptr);
mlir::Type IndexType = mlir::IndexType::get(&Context);
mlir::Type IntegerType =
mlir::IntegerType::get(3, mlir::IntegerType::Unsigned, &Context);
mlir::Type FloatType = mlir::Float32Type::get(&Context);
mlir::Type MemRefType = mlir::MemRefType::get({4, 5}, FloatType);
mlir::Type UnrankedMemRefType = mlir::UnrankedMemRefType::get(IntegerType, 6);
mlir::Type VectorType = mlir::VectorType::get({1, 2}, FloatType);
mlir::Type TupleType =
mlir::TupleType::get(mlir::TypeRange({IndexType, FloatType}), &Context);

auto UnknownLoc = mlir::UnknownLoc::get(&Context);
auto FileLineColLoc = mlir::FileLineColLoc::get("file", 7, 8, &Context);
auto OpaqueLoc = mlir::OpaqueLoc::get<uintptr_t>(9, &Context);
auto NameLoc = mlir::NameLoc::get(Identifier, &Context);
auto CallSiteLoc = mlir::CallSiteLoc::get(FileLineColLoc, OpaqueLoc);
auto FusedLoc = mlir::FusedLoc::get({FileLineColLoc, NameLoc}, &Context);

mlir::Attribute UnitAttr = mlir::UnitAttr::get(&Context);
mlir::Attribute FloatAttr = mlir::FloatAttr::get(FloatType, 1.0);
mlir::Attribute IntegerAttr = mlir::IntegerAttr::get(IntegerType, 10);
mlir::Attribute TypeAttr = mlir::TypeAttr::get(IndexType);
mlir::Attribute ArrayAttr = mlir::ArrayAttr::get({UnitAttr}, &Context);
mlir::Attribute StringAttr = mlir::StringAttr::get("foo", &Context);
mlir::Attribute ElementsAttr = mlir::DenseElementsAttr::get(
VectorType.cast<mlir::ShapedType>(), llvm::ArrayRef<float>{2.0f, 3.0f});

int main() { return 0; }
112 changes: 112 additions & 0 deletions debuginfo-tests/llvm-prettyprinters/gdb/mlir-support.gdb
@@ -0,0 +1,112 @@
# 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
# REQUIRES: debug-info
# REQUIRES: mlir

break main
run

# CHECK: "foo"
p Identifier

# CHECK: "FooOp"
p OperationName

# CHECK: 0x8
# CHECK: TrailingOpResult
p Value

# CHECK: impl = 0x0
p Type

# CHECK: cast<mlir::IndexType>
p IndexType

# CHECK: cast<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: cast<mlir::VectorType>
# CHECK: shapeSize = 2
# CHECK: shapeElements[0] = 1
# CHECK: shapeElements[1] = 2
p VectorType

# CHECK: cast<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: cast<mlir::FileLineColLoc>
# CHECK: filename = "file"
# CHECK: line = 7
# CHECK: column = 8
p FileLineColLoc

# CHECK: cast<mlir::OpaqueLoc>
# CHECK: underlyingLocation = 9
p OpaqueLoc

# CHECK: cast<mlir::NameLoc>
# CHECK: name = "foo"
# CHECK: mlir::UnknownLoc
p NameLoc

# CHECK: cast<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: mlir::FileLineColLoc
# CHECK: locs[1]
# CHECK: mlir::NameLoc
p FusedLoc

# CHECK: cast<mlir::UnitAttr>
p UnitAttr

# CHECK: cast<mlir::FloatAttr>
p FloatAttr

# CHECK: cast<mlir::IntegerAttr>
p IntegerAttr

# CHECK: cast<mlir::TypeAttr>
# CHECK: mlir::IndexType
p TypeAttr

# CHECK: cast<mlir::ArrayAttr>
# CHECK: llvm::ArrayRef of length 1
# CHECK: mlir::UnitAttr
p ArrayAttr

# CHECK: cast<mlir::StringAttr>
# CHECK: value = "foo"
p StringAttr

# CHECK: cast<mlir::DenseIntOrFPElementsAttr>
p ElementsAttr

0 comments on commit e9b3884

Please sign in to comment.