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/Support/DOTGraphTraits.h"
20
21namespace llvm {
22class LPMUpdater;
23class Loop;
24
25//===--------------------------------------------------------------------===//
26// Implementation of DDG DOT Printer for a loop.
27//===--------------------------------------------------------------------===//
28class DDGDotPrinterPass : public PassInfoMixin<DDGDotPrinterPass> {
29public:
30 PreservedAnalyses run(Loop &L, LoopAnalysisManager &AM,
31 LoopStandardAnalysisResults &AR, LPMUpdater &U);
32 static bool isRequired() { return true; }
33};
34
35//===--------------------------------------------------------------------===//
36// Specialization of DOTGraphTraits.
37//===--------------------------------------------------------------------===//
38template <>
39struct DOTGraphTraits<const DataDependenceGraph *>
40 : public DefaultDOTGraphTraits {
41
42 DOTGraphTraits(bool IsSimple = false) : DefaultDOTGraphTraits(IsSimple) {}
43
44 /// Generate a title for the graph in DOT format
45 std::string getGraphName(const DataDependenceGraph *G) {
46 assert(G && "expected a valid pointer to the graph.");
47 return "DDG for '" + std::string(G->getName()) + "'";
48 }
49
50 /// Print a DDG node either in concise form (-ddg-dot-only) or
51 /// verbose mode (-ddg-dot).
52 std::string getNodeLabel(const DDGNode *Node,
53 const DataDependenceGraph *Graph);
54
55 /// Print attributes of an edge in the DDG graph. If the edge
56 /// is a MemoryDependence edge, then detailed dependence info
57 /// available from DependenceAnalysis is displayed.
58 std::string
59 getEdgeAttributes(const DDGNode *Node,
60 GraphTraits<const DDGNode *>::ChildIteratorType I,
61 const DataDependenceGraph *G);
62
63 /// Do not print nodes that are part of a pi-block separately. They
64 /// will be printed when their containing pi-block is being printed.
65 bool isNodeHidden(const DDGNode *Node, const DataDependenceGraph *G);
66
67private:
68 /// Print a DDG node in concise form.
69 static std::string getSimpleNodeLabel(const DDGNode *Node,
70 const DataDependenceGraph *G);
71
72 /// Print a DDG node with more information including containing instructions
73 /// and detailed information about the dependence edges.
74 static std::string getVerboseNodeLabel(const DDGNode *Node,
75 const DataDependenceGraph *G);
76
77 /// Print a DDG edge in concise form.
78 static std::string getSimpleEdgeAttributes(const DDGNode *Src,
79 const DDGEdge *Edge,
80 const DataDependenceGraph *G);
81
82 /// Print a DDG edge with more information including detailed information
83 /// about the dependence edges.
84 static std::string getVerboseEdgeAttributes(const DDGNode *Src,
85 const DDGEdge *Edge,
86 const DataDependenceGraph *G);
87};
88
89using DDGDotGraphTraits = DOTGraphTraits<const DataDependenceGraph *>;
90
91} // namespace llvm
92
93#endif // LLVM_ANALYSIS_DDGPRINTER_H
94

source code of llvm/include/llvm/Analysis/DDGPrinter.h