diff --git a/mlir/include/mlir/Transforms/Passes.td b/mlir/include/mlir/Transforms/Passes.td --- a/mlir/include/mlir/Transforms/Passes.td +++ b/mlir/include/mlir/Transforms/Passes.td @@ -700,6 +700,14 @@ 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 --- a/mlir/lib/Transforms/ViewOpGraph.cpp +++ b/mlir/lib/Transforms/ViewOpGraph.cpp @@ -143,7 +143,10 @@ } // 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 @@ 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 @@ 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