forked from OSchip/llvm-project
Add an option to improve the readibility of the printed MLIR debuginfo
Use `-mlir-pretty-debuginfo` if the user wants line breaks between different callsite lines. The print results before and after this CL are shown in the tests. PiperOrigin-RevId: 231013812
This commit is contained in:
parent
fb679fc2b5
commit
ebac3528d0
|
@ -62,9 +62,14 @@ OpAsmPrinter::~OpAsmPrinter() {}
|
|||
// info or when we have a system for printer flags.
|
||||
static llvm::cl::opt<bool>
|
||||
shouldPrintDebugInfoOpt("mlir-print-debuginfo",
|
||||
llvm::cl::desc("Include debug info in MLIR output"),
|
||||
llvm::cl::desc("Print debug info in MLIR output"),
|
||||
llvm::cl::init(false));
|
||||
|
||||
static llvm::cl::opt<bool> printPrettyDebugInfo(
|
||||
"mlir-pretty-debuginfo",
|
||||
llvm::cl::desc("Print pretty debug info in MLIR output"),
|
||||
llvm::cl::init(false));
|
||||
|
||||
namespace {
|
||||
class ModuleState {
|
||||
public:
|
||||
|
@ -347,7 +352,7 @@ protected:
|
|||
void printIntegerSetReference(IntegerSet integerSet);
|
||||
void printIntegerSetAlias(StringRef alias) const;
|
||||
void printTrailingLocation(Location loc);
|
||||
void printLocationInternal(Location loc);
|
||||
void printLocationInternal(Location loc, bool pretty = false);
|
||||
void printDenseElementsAttr(DenseElementsAttr attr);
|
||||
|
||||
/// This enum is used to represent the binding stength of the enclosing
|
||||
|
@ -423,15 +428,19 @@ void ModulePrinter::printTrailingLocation(Location loc) {
|
|||
printLocation(loc);
|
||||
}
|
||||
|
||||
void ModulePrinter::printLocationInternal(Location loc) {
|
||||
void ModulePrinter::printLocationInternal(Location loc, bool pretty) {
|
||||
switch (loc.getKind()) {
|
||||
case Location::Kind::Unknown:
|
||||
os << "unknown";
|
||||
if (pretty)
|
||||
os << "[unknown]";
|
||||
else
|
||||
os << "unknown";
|
||||
break;
|
||||
case Location::Kind::FileLineCol: {
|
||||
auto fileLoc = loc.cast<FileLineColLoc>();
|
||||
os << '\"' << fileLoc.getFilename() << '\"' << ':' << fileLoc.getLine()
|
||||
<< ':' << fileLoc.getColumn();
|
||||
auto mayQuote = pretty ? "" : "\"";
|
||||
os << mayQuote << fileLoc.getFilename() << mayQuote << ':'
|
||||
<< fileLoc.getLine() << ':' << fileLoc.getColumn();
|
||||
break;
|
||||
}
|
||||
case Location::Kind::Name: {
|
||||
|
@ -441,22 +450,38 @@ void ModulePrinter::printLocationInternal(Location loc) {
|
|||
case Location::Kind::CallSite: {
|
||||
auto callLocation = loc.cast<CallSiteLoc>();
|
||||
auto caller = callLocation.getCaller();
|
||||
os << "callsite(";
|
||||
printLocationInternal(callLocation.getCallee());
|
||||
os << " at ";
|
||||
printLocationInternal(caller);
|
||||
os << ")";
|
||||
auto callee = callLocation.getCallee();
|
||||
if (!pretty)
|
||||
os << "callsite(";
|
||||
printLocationInternal(callee, pretty);
|
||||
if (pretty) {
|
||||
if (callee.isa<NameLoc>()) {
|
||||
if (caller.isa<FileLineColLoc>()) {
|
||||
os << " at ";
|
||||
} else {
|
||||
os << "\n at ";
|
||||
}
|
||||
} else {
|
||||
os << "\n at ";
|
||||
}
|
||||
} else {
|
||||
os << " at ";
|
||||
}
|
||||
printLocationInternal(caller, pretty);
|
||||
if (!pretty)
|
||||
os << ")";
|
||||
break;
|
||||
}
|
||||
case Location::Kind::FusedLocation: {
|
||||
auto fusedLoc = loc.cast<FusedLoc>();
|
||||
os << "fused";
|
||||
if (!pretty)
|
||||
os << "fused";
|
||||
if (auto metadata = fusedLoc.getMetadata())
|
||||
os << '<' << metadata << '>';
|
||||
os << '[';
|
||||
interleave(
|
||||
fusedLoc.getLocations(),
|
||||
[&](Location loc) { printLocationInternal(loc); },
|
||||
[&](Location loc) { printLocationInternal(loc, pretty); },
|
||||
[&]() { os << ", "; });
|
||||
os << ']';
|
||||
break;
|
||||
|
@ -531,9 +556,13 @@ void ModulePrinter::printFunctionReference(const Function *func) {
|
|||
}
|
||||
|
||||
void ModulePrinter::printLocation(Location loc) {
|
||||
os << "loc(";
|
||||
printLocationInternal(loc);
|
||||
os << ')';
|
||||
if (printPrettyDebugInfo) {
|
||||
printLocationInternal(loc, /*pretty=*/true);
|
||||
} else {
|
||||
os << "loc(";
|
||||
printLocationInternal(loc);
|
||||
os << ')';
|
||||
}
|
||||
}
|
||||
|
||||
void ModulePrinter::printAttribute(Attribute attr) {
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
// RUN: mlir-opt %s -mlir-print-debuginfo -mlir-pretty-debuginfo | FileCheck %s
|
||||
|
||||
#set0 = (d0) : (1 == 0)
|
||||
|
||||
// CHECK-LABEL: inline_notation
|
||||
// CHECK () -> i32 mysource.cc:10:8
|
||||
func @inline_notation() -> i32 loc("mysource.cc":10:8) {
|
||||
// CHECK: -> i32 "foo"
|
||||
%1 = "foo"() : () -> i32 loc("foo")
|
||||
|
||||
// CHECK: constant 4 : index "foo" at mysource.cc:10:8
|
||||
%2 = constant 4 : index loc(callsite("foo" at "mysource.cc":10:8))
|
||||
|
||||
// CHECK: constant 4 : index "foo"
|
||||
// CHECK-NEXT: at mysource1.cc:10:8
|
||||
// CHECK-NEXT: at mysource2.cc:13:8
|
||||
// CHECK-NEXT: at mysource3.cc:100:10
|
||||
%3 = constant 4 : index loc(callsite("foo" at callsite("mysource1.cc":10:8 at callsite("mysource2.cc":13:8 at "mysource3.cc":100:10))))
|
||||
|
||||
// CHECK: for %i0 = 0 to 8 ["foo", mysource.cc:10:8]
|
||||
for %i0 = 0 to 8 loc(fused["foo", "mysource.cc":10:8]) {
|
||||
}
|
||||
|
||||
// CHECK: ) <"myPass">["foo", "foo2"]
|
||||
if #set0(%2) loc(fused<"myPass">["foo", "foo2"]) {
|
||||
}
|
||||
|
||||
// CHECK: return %0 : i32 [unknown]
|
||||
return %1 : i32 loc(unknown)
|
||||
}
|
Loading…
Reference in New Issue