LLVM  15.0.0git
DOTGraphTraits.h
Go to the documentation of this file.
1 //===-- llvm/Support/DOTGraphTraits.h - Customize .dot output ---*- 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 // This file defines a template class that can be used to customize dot output
10 // graphs generated by the GraphWriter.h file. The default implementation of
11 // this file will produce a simple, but not very polished graph. By
12 // specializing this template, lots of customization opportunities are possible.
13 //
14 //===----------------------------------------------------------------------===//
15 
16 #ifndef LLVM_SUPPORT_DOTGRAPHTRAITS_H
17 #define LLVM_SUPPORT_DOTGRAPHTRAITS_H
18 
19 #include <string>
20 
21 namespace llvm {
22 
23 /// DefaultDOTGraphTraits - This class provides the default implementations of
24 /// all of the DOTGraphTraits methods. If a specialization does not need to
25 /// override all methods here it should inherit so that it can get the default
26 /// implementations.
27 ///
29 private:
30  bool IsSimple;
31 
32 protected:
33  bool isSimple() {
34  return IsSimple;
35  }
36 
37 public:
38  explicit DefaultDOTGraphTraits(bool simple=false) : IsSimple (simple) {}
39 
40  /// getGraphName - Return the label for the graph as a whole. Printed at the
41  /// top of the graph.
42  ///
43  template<typename GraphType>
44  static std::string getGraphName(const GraphType &) { return ""; }
45 
46  /// getGraphProperties - Return any custom properties that should be included
47  /// in the top level graph structure for dot.
48  ///
49  template<typename GraphType>
50  static std::string getGraphProperties(const GraphType &) {
51  return "";
52  }
53 
54  /// renderGraphFromBottomUp - If this function returns true, the graph is
55  /// emitted bottom-up instead of top-down. This requires graphviz 2.0 to work
56  /// though.
57  static bool renderGraphFromBottomUp() {
58  return false;
59  }
60 
61  /// isNodeHidden - If the function returns true, the given node is not
62  /// displayed in the graph.
63  template <typename GraphType>
64  static bool isNodeHidden(const void *, const GraphType &) {
65  return false;
66  }
67 
68  // renderNodesUsingHTML - If the function returns true, nodes will be
69  // rendered using HTML-like labels which allows colors, etc in the nodes
70  // and the edge source labels.
71  static bool renderNodesUsingHTML() { return false; }
72 
73  /// getNodeLabel - Given a node and a pointer to the top level graph, return
74  /// the label to print in the node.
75  template<typename GraphType>
76  std::string getNodeLabel(const void *, const GraphType &) {
77  return "";
78  }
79 
80  // getNodeIdentifierLabel - Returns a string representing the
81  // address or other unique identifier of the node. (Only used if
82  // non-empty.)
83  template <typename GraphType>
84  static std::string getNodeIdentifierLabel(const void *, const GraphType &) {
85  return "";
86  }
87 
88  template<typename GraphType>
89  static std::string getNodeDescription(const void *, const GraphType &) {
90  return "";
91  }
92 
93  /// If you want to specify custom node attributes, this is the place to do so
94  ///
95  template<typename GraphType>
96  static std::string getNodeAttributes(const void *,
97  const GraphType &) {
98  return "";
99  }
100 
101  /// If you want to override the dot attributes printed for a particular edge,
102  /// override this method.
103  template<typename EdgeIter, typename GraphType>
104  static std::string getEdgeAttributes(const void *, EdgeIter,
105  const GraphType &) {
106  return "";
107  }
108 
109  /// getEdgeSourceLabel - If you want to label the edge source itself,
110  /// implement this method.
111  template<typename EdgeIter>
112  static std::string getEdgeSourceLabel(const void *, EdgeIter) {
113  return "";
114  }
115 
116  /// edgeTargetsEdgeSource - This method returns true if this outgoing edge
117  /// should actually target another edge source, not a node. If this method is
118  /// implemented, getEdgeTarget should be implemented.
119  template<typename EdgeIter>
120  static bool edgeTargetsEdgeSource(const void *, EdgeIter) {
121  return false;
122  }
123 
124  /// getEdgeTarget - If edgeTargetsEdgeSource returns true, this method is
125  /// called to determine which outgoing edge of Node is the target of this
126  /// edge.
127  template<typename EdgeIter>
128  static EdgeIter getEdgeTarget(const void *, EdgeIter I) {
129  return I;
130  }
131 
132  /// hasEdgeDestLabels - If this function returns true, the graph is able
133  /// to provide labels for edge destinations.
134  static bool hasEdgeDestLabels() {
135  return false;
136  }
137 
138  /// numEdgeDestLabels - If hasEdgeDestLabels, this function returns the
139  /// number of incoming edge labels the given node has.
140  static unsigned numEdgeDestLabels(const void *) {
141  return 0;
142  }
143 
144  /// getEdgeDestLabel - If hasEdgeDestLabels, this function returns the
145  /// incoming edge label with the given index in the given node.
146  static std::string getEdgeDestLabel(const void *, unsigned) {
147  return "";
148  }
149 
150  /// addCustomGraphFeatures - If a graph is made up of more than just
151  /// straight-forward nodes and edges, this is the place to put all of the
152  /// custom stuff necessary. The GraphWriter object, instantiated with your
153  /// GraphType is passed in as an argument. You may call arbitrary methods on
154  /// it to add things to the output graph.
155  ///
156  template<typename GraphType, typename GraphWriter>
157  static void addCustomGraphFeatures(const GraphType &, GraphWriter &) {}
158 };
159 
160 
161 /// DOTGraphTraits - Template class that can be specialized to customize how
162 /// graphs are converted to 'dot' graphs. When specializing, you may inherit
163 /// from DefaultDOTGraphTraits if you don't need to override everything.
164 ///
165 template <typename Ty>
167  DOTGraphTraits (bool simple=false) : DefaultDOTGraphTraits (simple) {}
168 };
169 
170 } // End llvm namespace
171 
172 #endif
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
llvm::GraphWriter
Definition: ScheduleDAG.h:34
llvm::DefaultDOTGraphTraits::isNodeHidden
static bool isNodeHidden(const void *, const GraphType &)
isNodeHidden - If the function returns true, the given node is not displayed in the graph.
Definition: DOTGraphTraits.h:64
llvm::DefaultDOTGraphTraits::getEdgeTarget
static EdgeIter getEdgeTarget(const void *, EdgeIter I)
getEdgeTarget - If edgeTargetsEdgeSource returns true, this method is called to determine which outgo...
Definition: DOTGraphTraits.h:128
llvm::DefaultDOTGraphTraits::getEdgeAttributes
static std::string getEdgeAttributes(const void *, EdgeIter, const GraphType &)
If you want to override the dot attributes printed for a particular edge, override this method.
Definition: DOTGraphTraits.h:104
llvm::DOTGraphTraits::DOTGraphTraits
DOTGraphTraits(bool simple=false)
Definition: DOTGraphTraits.h:167
llvm::DefaultDOTGraphTraits::getGraphProperties
static std::string getGraphProperties(const GraphType &)
getGraphProperties - Return any custom properties that should be included in the top level graph stru...
Definition: DOTGraphTraits.h:50
llvm::DefaultDOTGraphTraits::getNodeAttributes
static std::string getNodeAttributes(const void *, const GraphType &)
If you want to specify custom node attributes, this is the place to do so.
Definition: DOTGraphTraits.h:96
llvm::DefaultDOTGraphTraits::DefaultDOTGraphTraits
DefaultDOTGraphTraits(bool simple=false)
Definition: DOTGraphTraits.h:38
llvm::DOTGraphTraits
DOTGraphTraits - Template class that can be specialized to customize how graphs are converted to 'dot...
Definition: DOTGraphTraits.h:166
llvm::DefaultDOTGraphTraits::getGraphName
static std::string getGraphName(const GraphType &)
getGraphName - Return the label for the graph as a whole.
Definition: DOTGraphTraits.h:44
I
#define I(x, y, z)
Definition: MD5.cpp:58
llvm::DefaultDOTGraphTraits::addCustomGraphFeatures
static void addCustomGraphFeatures(const GraphType &, GraphWriter &)
addCustomGraphFeatures - If a graph is made up of more than just straight-forward nodes and edges,...
Definition: DOTGraphTraits.h:157
llvm::DefaultDOTGraphTraits::getEdgeDestLabel
static std::string getEdgeDestLabel(const void *, unsigned)
getEdgeDestLabel - If hasEdgeDestLabels, this function returns the incoming edge label with the given...
Definition: DOTGraphTraits.h:146
llvm::DefaultDOTGraphTraits::isSimple
bool isSimple()
Definition: DOTGraphTraits.h:33
llvm::DefaultDOTGraphTraits::getEdgeSourceLabel
static std::string getEdgeSourceLabel(const void *, EdgeIter)
getEdgeSourceLabel - If you want to label the edge source itself, implement this method.
Definition: DOTGraphTraits.h:112
llvm::DefaultDOTGraphTraits::edgeTargetsEdgeSource
static bool edgeTargetsEdgeSource(const void *, EdgeIter)
edgeTargetsEdgeSource - This method returns true if this outgoing edge should actually target another...
Definition: DOTGraphTraits.h:120
llvm::DefaultDOTGraphTraits::renderGraphFromBottomUp
static bool renderGraphFromBottomUp()
renderGraphFromBottomUp - If this function returns true, the graph is emitted bottom-up instead of to...
Definition: DOTGraphTraits.h:57
llvm::DefaultDOTGraphTraits::numEdgeDestLabels
static unsigned numEdgeDestLabels(const void *)
numEdgeDestLabels - If hasEdgeDestLabels, this function returns the number of incoming edge labels th...
Definition: DOTGraphTraits.h:140
llvm::DefaultDOTGraphTraits::getNodeDescription
static std::string getNodeDescription(const void *, const GraphType &)
Definition: DOTGraphTraits.h:89
llvm::DefaultDOTGraphTraits::getNodeIdentifierLabel
static std::string getNodeIdentifierLabel(const void *, const GraphType &)
Definition: DOTGraphTraits.h:84
llvm::DefaultDOTGraphTraits::getNodeLabel
std::string getNodeLabel(const void *, const GraphType &)
getNodeLabel - Given a node and a pointer to the top level graph, return the label to print in the no...
Definition: DOTGraphTraits.h:76
llvm::DefaultDOTGraphTraits
DefaultDOTGraphTraits - This class provides the default implementations of all of the DOTGraphTraits ...
Definition: DOTGraphTraits.h:28
llvm::DefaultDOTGraphTraits::hasEdgeDestLabels
static bool hasEdgeDestLabels()
hasEdgeDestLabels - If this function returns true, the graph is able to provide labels for edge desti...
Definition: DOTGraphTraits.h:134
llvm::DefaultDOTGraphTraits::renderNodesUsingHTML
static bool renderNodesUsingHTML()
Definition: DOTGraphTraits.h:71