Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame] | 1 | //===- llvm/Analysis/DDGPrinter.h -------------------------------*- C++ -*-===// |
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | //===----------------------------------------------------------------------===// |
| 10 | // |
| 11 | // This file defines the DOT printer for the Data-Dependence Graph (DDG). |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #ifndef LLVM_ANALYSIS_DDGPRINTER_H |
| 16 | #define LLVM_ANALYSIS_DDGPRINTER_H |
| 17 | |
| 18 | #include "llvm/Analysis/DDG.h" |
| 19 | #include "llvm/Pass.h" |
| 20 | #include "llvm/Support/DOTGraphTraits.h" |
| 21 | |
| 22 | namespace llvm { |
| 23 | |
| 24 | //===--------------------------------------------------------------------===// |
| 25 | // Implementation of DDG DOT Printer for a loop. |
| 26 | //===--------------------------------------------------------------------===// |
| 27 | class DDGDotPrinterPass : public PassInfoMixin<DDGDotPrinterPass> { |
| 28 | public: |
| 29 | PreservedAnalyses run(Loop &L, LoopAnalysisManager &AM, |
| 30 | LoopStandardAnalysisResults &AR, LPMUpdater &U); |
| 31 | }; |
| 32 | |
| 33 | //===--------------------------------------------------------------------===// |
| 34 | // Specialization of DOTGraphTraits. |
| 35 | //===--------------------------------------------------------------------===// |
| 36 | template <> |
| 37 | struct DOTGraphTraits<const DataDependenceGraph *> |
| 38 | : public DefaultDOTGraphTraits { |
| 39 | |
| 40 | DOTGraphTraits(bool IsSimple = false) : DefaultDOTGraphTraits(IsSimple) {} |
| 41 | |
| 42 | /// Generate a title for the graph in DOT format |
| 43 | std::string getGraphName(const DataDependenceGraph *G) { |
| 44 | assert(G && "expected a valid pointer to the graph."); |
| 45 | return "DDG for '" + std::string(G->getName()) + "'"; |
| 46 | } |
| 47 | |
| 48 | /// Print a DDG node either in concise form (-ddg-dot-only) or |
| 49 | /// verbose mode (-ddg-dot). |
| 50 | std::string getNodeLabel(const DDGNode *Node, |
| 51 | const DataDependenceGraph *Graph); |
| 52 | |
| 53 | /// Print attributes of an edge in the DDG graph. If the edge |
| 54 | /// is a MemoryDependence edge, then detailed dependence info |
| 55 | /// available from DependenceAnalysis is displayed. |
| 56 | std::string |
| 57 | getEdgeAttributes(const DDGNode *Node, |
| 58 | GraphTraits<const DDGNode *>::ChildIteratorType I, |
| 59 | const DataDependenceGraph *G); |
| 60 | |
| 61 | /// Do not print nodes that are part of a pi-block separately. They |
| 62 | /// will be printed when their containing pi-block is being printed. |
| 63 | bool isNodeHidden(const DDGNode *Node, const DataDependenceGraph *G); |
| 64 | |
| 65 | private: |
| 66 | /// Print a DDG node in concise form. |
| 67 | static std::string getSimpleNodeLabel(const DDGNode *Node, |
| 68 | const DataDependenceGraph *G); |
| 69 | |
| 70 | /// Print a DDG node with more information including containing instructions |
| 71 | /// and detailed information about the dependence edges. |
| 72 | static std::string getVerboseNodeLabel(const DDGNode *Node, |
| 73 | const DataDependenceGraph *G); |
| 74 | |
| 75 | /// Print a DDG edge in concise form. |
| 76 | static std::string getSimpleEdgeAttributes(const DDGNode *Src, |
| 77 | const DDGEdge *Edge, |
| 78 | const DataDependenceGraph *G); |
| 79 | |
| 80 | /// Print a DDG edge with more information including detailed information |
| 81 | /// about the dependence edges. |
| 82 | static std::string getVerboseEdgeAttributes(const DDGNode *Src, |
| 83 | const DDGEdge *Edge, |
| 84 | const DataDependenceGraph *G); |
| 85 | }; |
| 86 | |
| 87 | using DDGDotGraphTraits = DOTGraphTraits<const DataDependenceGraph *>; |
| 88 | |
| 89 | } // namespace llvm |
| 90 | |
| 91 | #endif // LLVM_ANALYSIS_DDGPRINTER_H |