@@ -220,6 +220,19 @@ class PrintOpPass : public impl::ViewOpGraphBase<PrintOpPass> {
220220 os << escapeLabelString (truncateString (buf));
221221 }
222222
223+ // Print a truncated and escaped MLIR type to `os`.
224+ void emitMlirType (raw_ostream &os, Type type) {
225+ std::string buf;
226+ llvm::raw_string_ostream ss (buf);
227+ type.print (ss);
228+ os << escapeLabelString (truncateString (buf));
229+ }
230+
231+ // Print a truncated and escaped MLIR operand to `os`.
232+ void emitMlirOperand (raw_ostream &os, Value operand) {
233+ operand.printAsOperand (os, OpPrintingFlags ());
234+ }
235+
223236 // / Append an edge to the list of edges.
224237 // / Note: Edges are written to the output stream via `emitAllEdgeStmts`.
225238 void emitEdgeStmt (Node n1, Node n2, std::string port, StringRef style) {
@@ -318,7 +331,7 @@ class PrintOpPass : public impl::ViewOpGraphBase<PrintOpPass> {
318331 os << " {" ;
319332 auto operandToPort = [&](Value operand) {
320333 os << " <" << getValuePortName (operand) << " > " ;
321- operand. printAsOperand (os, OpPrintingFlags () );
334+ emitMlirOperand (os, operand );
322335 };
323336 interleave (op->getOperands (), os, operandToPort, " |" );
324337 os << " }|" ;
@@ -341,11 +354,11 @@ class PrintOpPass : public impl::ViewOpGraphBase<PrintOpPass> {
341354 os << " |{" ;
342355 auto resultToPort = [&](Value result) {
343356 os << " <" << getValuePortName (result) << " > " ;
344- result. printAsOperand (os, OpPrintingFlags () );
345- if (printResultTypes)
346- os << " "
347- << truncateString ( escapeLabelString ( strFromOs (
348- [&](raw_ostream &os) { os << result. getType (); })));
357+ emitMlirOperand (os, result );
358+ if (printResultTypes) {
359+ os << " " ;
360+ emitMlirType (os, result. getType ());
361+ }
349362 };
350363 interleave (op->getResults (), os, resultToPort, " |" );
351364 os << " }" ;
@@ -360,10 +373,10 @@ class PrintOpPass : public impl::ViewOpGraphBase<PrintOpPass> {
360373 return strFromOs ([&](raw_ostream &os) {
361374 os << " <" << getValuePortName (arg) << " > " ;
362375 arg.printAsOperand (os, OpPrintingFlags ());
363- if (printResultTypes)
364- os << " "
365- << truncateString ( escapeLabelString (
366- strFromOs ([&](raw_ostream &os) { os << arg. getType (); })));
376+ if (printResultTypes) {
377+ os << " " ;
378+ emitMlirType (os, arg. getType ());
379+ }
367380 });
368381 }
369382
0 commit comments