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 @@ -13,11 +13,12 @@ #include "mlir/IR/Operation.h" #include "mlir/Pass/Pass.h" #include "mlir/Support/IndentedOstream.h" +#include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/StringMap.h" #include "llvm/Support/Format.h" #include "llvm/Support/GraphWriter.h" -#include #include +#include namespace mlir { #define GEN_PASS_DEF_VIEWOPGRAPH @@ -58,7 +59,7 @@ return "\"" + str + "\""; } -using AttributeMap = llvm::StringMap; +using Attributes = ArrayRef>; namespace { @@ -131,10 +132,11 @@ } /// Emit an attribute list. - void emitAttrList(raw_ostream &os, const AttributeMap &map) { + void emitAttrList(raw_ostream &os, const Attributes &attrs) { os << "["; - interleaveComma(map, os, [&](const auto &it) { - os << this->attrStmt(it.getKey(), it.getValue()); + interleaveComma(attrs, os, [&](const auto &kv) { + const auto &[Key, Value] = kv; + os << this->attrStmt(Key, Value); }); os << "]"; } @@ -175,18 +177,18 @@ /// Append an edge to the list of edges. /// Note: Edges are written to the output stream via `emitAllEdgeStmts`. void emitEdgeStmt(Node n1, Node n2, std::string label, StringRef style) { - AttributeMap attrs; - attrs["style"] = style.str(); + SmallVector, 3> attrs; + attrs.emplace_back("style", style.str()); // Do not label edges that start/end at a cluster boundary. Such edges are // clipped at the boundary, but labels are not. This can lead to labels // floating around without any edge next to them. if (!n1.clusterId && !n2.clusterId) - attrs["label"] = quoteString(escapeString(std::move(label))); + attrs.emplace_back("label", quoteString(escapeString(std::move(label)))); // Use `ltail` and `lhead` to draw edges between clusters. if (n1.clusterId) - attrs["ltail"] = "cluster_" + std::to_string(*n1.clusterId); + attrs.emplace_back("ltail", "cluster_" + std::to_string(*n1.clusterId)); if (n2.clusterId) - attrs["lhead"] = "cluster_" + std::to_string(*n2.clusterId); + attrs.emplace_back("lhead", "cluster_" + std::to_string(*n2.clusterId)); edges.push_back(strFromOs([&](raw_ostream &os) { os << llvm::format("v%i -> v%i ", n1.id, n2.id); @@ -208,9 +210,9 @@ /// Emit a node statement. Node emitNodeStmt(std::string label, StringRef shape = kShapeNode) { int nodeId = ++counter; - AttributeMap attrs; - attrs["label"] = quoteString(escapeString(std::move(label))); - attrs["shape"] = shape.str(); + std::array, 2> attrs = { + {{"label", quoteString(escapeString(std::move(label)))}, + {"shape", shape.str()}}}; os << llvm::format("v%i ", nodeId); emitAttrList(os, attrs); os << ";\n";