[Mlir-commits] [mlir] a87be1c - [mlir] Truncate/skip long strings in ViewOpGraph.cpp
Matthias Springer
llvmlistbot at llvm.org
Tue Aug 3 20:15:11 PDT 2021
Author: Matthias Springer
Date: 2021-08-04T12:14:46+09:00
New Revision: a87be1c1bd950bfe46c1904474c67dd3a0a7586d
URL: https://github.com/llvm/llvm-project/commit/a87be1c1bd950bfe46c1904474c67dd3a0a7586d
DIFF: https://github.com/llvm/llvm-project/commit/a87be1c1bd950bfe46c1904474c67dd3a0a7586d.diff
LOG: [mlir] Truncate/skip long strings in ViewOpGraph.cpp
* New pass option `max-label-len`: Truncate attributes/result types that have more #chars.
* New pass option `print-attrs`: Activate/deactivate rendering of attributes.
* New pass option `printResultTypes`: Activate/deactivate rendering of result types.
Differential Revision: https://reviews.llvm.org/D106337
Added:
Modified:
mlir/include/mlir/Transforms/Passes.td
mlir/lib/Transforms/ViewOpGraph.cpp
Removed:
################################################################################
diff --git a/mlir/include/mlir/Transforms/Passes.td b/mlir/include/mlir/Transforms/Passes.td
index 324f06454a49..857b21ccddc4 100644
--- a/mlir/include/mlir/Transforms/Passes.td
+++ b/mlir/include/mlir/Transforms/Passes.td
@@ -700,6 +700,14 @@ def ViewOpGraphPass : Pass<"view-op-graph"> {
Note: See https://www.graphviz.org/doc/info/lang.html for more information
about the Graphviz DOT language.
}];
+ let options = [
+ Option<"maxLabelLen", "max-label-len", "unsigned",
+ /*default=*/"20", "Limit attribute/type length to number of chars">,
+ Option<"printAttrs", "print-attrs", "bool",
+ /*default=*/"true", "Print attributes of operations">,
+ Option<"printResultTypes", "print-result-types", "bool",
+ /*default=*/"true", "Print result types of operations">
+ ];
let constructor = "mlir::createPrintOpGraphPass()";
}
diff --git a/mlir/lib/Transforms/ViewOpGraph.cpp b/mlir/lib/Transforms/ViewOpGraph.cpp
index 86c5725b8910..d18de7c53c8e 100644
--- a/mlir/lib/Transforms/ViewOpGraph.cpp
+++ b/mlir/lib/Transforms/ViewOpGraph.cpp
@@ -143,7 +143,10 @@ class PrintOpPass : public ViewOpGraphPassBase<PrintOpPass> {
}
// Print all other attributes.
- attr.print(os);
+ std::string buf;
+ llvm::raw_string_ostream ss(buf);
+ attr.print(ss);
+ os << truncateString(ss.str());
}
/// Append an edge to the list of edges.
@@ -196,14 +199,23 @@ class PrintOpPass : public ViewOpGraphPassBase<PrintOpPass> {
std::string getLabel(Operation *op) {
return strFromOs([&](raw_ostream &os) {
// Print operation name and type.
- os << op->getName() << " : (";
- interleaveComma(op->getResultTypes(), os);
- os << ")\n";
+ os << op->getName();
+ if (printResultTypes) {
+ os << " : (";
+ std::string buf;
+ llvm::raw_string_ostream ss(buf);
+ interleaveComma(op->getResultTypes(), ss);
+ os << truncateString(ss.str()) << ")";
+ os << ")";
+ }
// Print attributes.
- for (const NamedAttribute &attr : op->getAttrs()) {
- os << '\n' << attr.first << ": ";
- emitMlirAttr(os, attr.second);
+ if (printAttrs) {
+ os << "\n";
+ for (const NamedAttribute &attr : op->getAttrs()) {
+ os << '\n' << attr.first << ": ";
+ emitMlirAttr(os, attr.second);
+ }
}
});
}
@@ -258,6 +270,13 @@ class PrintOpPass : public ViewOpGraphPassBase<PrintOpPass> {
processBlock(block);
}
+ /// Truncate long strings.
+ std::string truncateString(std::string str) {
+ if (str.length() <= maxLabelLen)
+ return str;
+ return str.substr(0, maxLabelLen) + "...";
+ }
+
/// Output stream to write DOT file to.
raw_indented_ostream os;
/// A list of edges. For simplicity, should be emitted after all nodes were
More information about the Mlir-commits
mailing list