//===- ViewOpGraph.cpp - View/write op graphviz graphs --------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// #include "mlir/Transforms/ViewOpGraph.h" #include "mlir/Analysis/TopologicalSortUtils.h" #include "mlir/IR/Block.h" #include "mlir/IR/BuiltinTypes.h" #include "mlir/IR/Operation.h" #include "mlir/Pass/Pass.h" #include "mlir/Support/IndentedOstream.h" #include "llvm/Support/Format.h" #include "llvm/Support/GraphWriter.h" #include <map> #include <optional> #include <utility> namespace mlir { #define GEN_PASS_DEF_VIEWOPGRAPH #include "mlir/Transforms/Passes.h.inc" } // namespace mlir usingnamespacemlir; static const StringRef kLineStyleControlFlow = …; static const StringRef kLineStyleDataFlow = …; static const StringRef kShapeNode = …; static const StringRef kShapeNone = …; /// Return the size limits for eliding large attributes. static int64_t getLargeAttributeSizeLimit() { … } /// Return all values printed onto a stream as a string. static std::string strFromOs(function_ref<void(raw_ostream &)> func) { … } /// Escape special characters such as '\n' and quotation marks. static std::string escapeString(std::string str) { … } /// Put quotation marks around a given string. static std::string quoteString(const std::string &str) { … } AttributeMap; namespace { /// This struct represents a node in the DOT language. Each node has an /// identifier and an optional identifier for the cluster (subgraph) that /// contains the node. /// Note: In the DOT language, edges can be drawn only from nodes to nodes, but /// not between clusters. However, edges can be clipped to the boundary of a /// cluster with `lhead` and `ltail` attributes. Therefore, when creating a new /// cluster, an invisible "anchor" node is created. struct Node { … }; /// This pass generates a Graphviz dataflow visualization of an MLIR operation. /// Note: See https://www.graphviz.org/doc/info/lang.html for more information /// about the Graphviz DOT language. class PrintOpPass : public impl::ViewOpGraphBase<PrintOpPass> { … }; } // namespace std::unique_ptr<Pass> mlir::createPrintOpGraphPass(raw_ostream &os) { … } /// Generate a CFG for a region and show it in a window. static void llvmViewGraph(Region ®ion, const Twine &name) { … } void mlir::Region::viewGraph(const Twine ®ionName) { … } void mlir::Region::viewGraph() { … }