forked from OSchip/llvm-project
[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
This commit is contained in:
parent
3df1e7e6f0
commit
a87be1c1bd
|
@ -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()";
|
||||
}
|
||||
|
||||
|
|
|
@ -143,7 +143,10 @@ private:
|
|||
}
|
||||
|
||||
// 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 @@ private:
|
|||
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 @@ private:
|
|||
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
|
||||
|
|
Loading…
Reference in New Issue