@@ -220,6 +220,19 @@ class PrintOpPass : public impl::ViewOpGraphBase<PrintOpPass> {
220
220
os << escapeLabelString (truncateString (buf));
221
221
}
222
222
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
+
223
236
// / Append an edge to the list of edges.
224
237
// / Note: Edges are written to the output stream via `emitAllEdgeStmts`.
225
238
void emitEdgeStmt (Node n1, Node n2, std::string port, StringRef style) {
@@ -318,7 +331,7 @@ class PrintOpPass : public impl::ViewOpGraphBase<PrintOpPass> {
318
331
os << " {" ;
319
332
auto operandToPort = [&](Value operand) {
320
333
os << " <" << getValuePortName (operand) << " > " ;
321
- operand. printAsOperand (os, OpPrintingFlags () );
334
+ emitMlirOperand (os, operand );
322
335
};
323
336
interleave (op->getOperands (), os, operandToPort, " |" );
324
337
os << " }|" ;
@@ -341,11 +354,11 @@ class PrintOpPass : public impl::ViewOpGraphBase<PrintOpPass> {
341
354
os << " |{" ;
342
355
auto resultToPort = [&](Value result) {
343
356
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
+ }
349
362
};
350
363
interleave (op->getResults (), os, resultToPort, " |" );
351
364
os << " }" ;
@@ -360,10 +373,10 @@ class PrintOpPass : public impl::ViewOpGraphBase<PrintOpPass> {
360
373
return strFromOs ([&](raw_ostream &os) {
361
374
os << " <" << getValuePortName (arg) << " > " ;
362
375
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
+ }
367
380
});
368
381
}
369
382
0 commit comments