LLVM: lib/CodeGen/SelectionDAG/SelectionDAGPrinter.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
21using namespace llvm;
22
23#define DEBUG_TYPE "dag-printer"
24
25namespace llvm {
26 template<>
28
31
35
37 return ((const SDNode *) Node)->getNumValues();
38 }
39
41 return ((const SDNode *) Node)->getValueType(i).getEVTString();
42 }
43
44 template
48
49
50
51
52 template
56
57
58
59
60 template
64 std::advance(NI, I.getNode()->getOperand(I.getOperand()).getResNo());
65 return NI;
66 }
67
69 return std::string(G->getMachineFunction().getName());
70 }
71
75
78 std::string R;
80#ifndef NDEBUG
81 OS << 't' << Node->PersistentId;
82#else
83 OS << static_cast<const void *>(Node);
84#endif
85 return R;
86 }
87
88
89
90 template
93 SDValue Op = EI.getNode()->getOperand(EI.getOperand());
94 EVT VT = Op.getValueType();
95 if (VT == MVT::Glue)
96 return "color=red,style=bold";
97 else if (VT == MVT::Other)
98 return "color=blue,style=dashed";
99 return "";
100 }
101
102
105 std::string Result = Node->getOperationName(G);
106 {
108 Node->print_details(OS, G);
109 }
110 return Result;
111 }
115#ifndef NDEBUG
117 if (!Attrs.empty()) {
118 if (Attrs.find("shape=") == std:🧵:npos)
119 return std::string("shape=Mrecord,") + Attrs;
120 else
121 return Attrs;
122 }
123#endif
124 return "shape=Mrecord";
125 }
126
129 GW.emitSimpleNode(nullptr, "plaintext=circle", "GraphRoot");
130 if (G->getRoot().getNode())
131 GW.emitEdge(nullptr, -1, G->getRoot().getNode(), G->getRoot().getResNo(),
132 "color=blue,style=dashed");
133 }
134 };
135}
136
140}
141
142
143
144
145
147
148#ifndef NDEBUG
150 false, Title);
151#else
152 errs() << "SelectionDAG::viewGraph is only available in debug builds on "
153 << "systems with Graphviz or gv!\n";
154#endif
155}
156
157
158
162
163
164
165
166
167
168
169
170#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
172 const Twine &Title) {
174}
175#endif
176
177
178
180#if LLVM_ENABLE_ABI_BREAKING_CHECKS
181 NodeGraphAttrs.clear();
182#else
183 errs() << "SelectionDAG::clearGraphAttrs is only available in builds with "
184 << "ABI breaking checks enabled on systems with Graphviz or gv!\n";
185#endif
186}
187
188
189
190
192#if LLVM_ENABLE_ABI_BREAKING_CHECKS
193 NodeGraphAttrs[N] = Attrs;
194#else
195 errs() << "SelectionDAG::setGraphAttrs is only available in builds with "
196 << "ABI breaking checks enabled on systems with Graphviz or gv!\n";
197#endif
198}
199
200
201
202
204#if LLVM_ENABLE_ABI_BREAKING_CHECKS
205 std::map<const SDNode *, std::string>::const_iterator I =
206 NodeGraphAttrs.find(N);
207
208 if (I != NodeGraphAttrs.end())
209 return I->second;
210 else
211 return "";
212#else
213 errs() << "SelectionDAG::getGraphAttrs is only available in builds with "
214 << "ABI breaking checks enabled on systems with Graphviz or gv!\n";
215 return std::string();
216#endif
217}
218
219
220
222#if LLVM_ENABLE_ABI_BREAKING_CHECKS
223 NodeGraphAttrs[N] = std::string("color=") + Color;
224#else
225 errs() << "SelectionDAG::setGraphColor is only available in builds with "
226 << "ABI breaking checks enabled on systems with Graphviz or gv!\n";
227#endif
228}
229
230
231
232
233bool SelectionDAG::setSubgraphColorHelper(SDNode *N, const char *Color, DenseSet<SDNode *> &visited,
234 int level, bool &printed) {
235 bool hit_limit = false;
236
237#ifndef NDEBUG
238 if (level >= 20) {
239 if (!printed) {
240 printed = true;
241 LLVM_DEBUG(dbgs() << "setSubgraphColor hit max level\n");
242 }
243 return true;
244 }
245
246 unsigned oldSize = visited.size();
248 if (visited.size() != oldSize) {
251 i != iend;
252 ++i) {
253 hit_limit = setSubgraphColorHelper(*i, Color, visited, level+1, printed) || hit_limit;
254 }
255 }
256#else
257 errs() << "SelectionDAG::setSubgraphColor is only available in debug builds"
258 << " on systems with Graphviz or gv!\n";
259#endif
260 return hit_limit;
261}
262
263
264
266#ifndef NDEBUG
268 bool printed = false;
269 if (setSubgraphColorHelper(N, Color, visited, 0, printed)) {
270
271 if (strcmp(Color, "red") == 0) {
272 setSubgraphColorHelper(N, "blue", visited, 0, printed);
273 } else if (strcmp(Color, "yellow") == 0) {
274 setSubgraphColorHelper(N, "green", visited, 0, printed);
275 }
276 }
277
278#else
279 errs() << "SelectionDAG::setSubgraphColor is only available in debug builds"
280 << " on systems with Graphviz or gv!\n";
281#endif
282}
283
285 std::string s;
287 O << "SU(" << SU->NodeNum << "): ";
292 while (!GluedNodes.empty()) {
293 O << DOTGraphTraits<SelectionDAG*>
294 ::getSimpleNodeLabel(GluedNodes.back(), DAG);
296 if (!GluedNodes.empty())
297 O << "\n ";
298 }
299 } else {
300 O << "CROSS RC COPY";
301 }
302 return s;
303}
304
306 if (DAG) {
307
308 GW.emitSimpleNode(nullptr, "plaintext=circle", "GraphRoot");
309 const SDNode *N = DAG->getRoot().getNode();
310 if (N && N->getNodeId() != -1)
312 "color=blue,style=dashed");
313 }
314}
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
This file defines the DenseSet and SmallDenseSet classes.
static StringRef getName(Value *V)
Implements a dense probed hash-table based set.
void emitSimpleNode(const void *ID, const std::string &Attr, const std::string &Label, unsigned NumEdgeSources=0, const std::vector< std::string > *EdgeSourceLabels=nullptr)
emitSimpleNode - Outputs a simple (non-record) node
void emitEdge(const void *SrcNodeID, int SrcNodePort, const void *DestNodeID, int DestNodePort, const std::string &Attrs)
emitEdge - Output an edge from a simple node into the graph...
static SDNodeIterator end(const SDNode *N)
static SDNodeIterator begin(const SDNode *N)
Represents one node in the SelectionDAG.
Unlike LLVM values, Selection DAG nodes may return multiple values as the result of a computation.
Scheduling unit. This is a node in the scheduling DAG.
unsigned NodeNum
Entry # of node in the node vector.
SDNode * getNode() const
Returns the representative SDNode for this SUnit.
virtual void getCustomGraphFeatures(GraphWriter< ScheduleDAG * > &GW) const
Definition SelectionDAGPrinter.cpp:305
std::string getGraphNodeLabel(const SUnit *SU) const override
Returns a label for an SUnit node in a visualization of the ScheduleDAG.
Definition SelectionDAGPrinter.cpp:284
std::vector< SUnit > SUnits
The scheduling units.
This is used to represent a portion of an LLVM function in a low-level Data Dependence DAG representa...
LLVM_ABI void setGraphAttrs(const SDNode *N, const char *Attrs)
Set graph attributes for a node. (eg. "color=red".)
Definition SelectionDAGPrinter.cpp:191
LLVM_ABI void setGraphColor(const SDNode *N, const char *Color)
Convenience for setting node color attribute.
Definition SelectionDAGPrinter.cpp:221
LLVM_ABI void viewGraph()
Definition SelectionDAGPrinter.cpp:159
LLVM_ABI std::string getGraphAttrs(const SDNode *N) const
Get graph attributes for a node.
Definition SelectionDAGPrinter.cpp:203
MachineFunction & getMachineFunction() const
LLVM_ABI void clearGraphAttrs()
Clear all previously defined node graph attributes.
Definition SelectionDAGPrinter.cpp:179
LLVM_ABI void setSubgraphColor(SDNode *N, const char *Color)
Convenience for setting subgraph color attribute.
Definition SelectionDAGPrinter.cpp:265
LLVM_DUMP_METHOD void dumpDotGraph(const Twine &FileName, const Twine &Title)
Just dump dot graph to a user-provided path and title.
Definition SelectionDAGPrinter.cpp:171
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
std::pair< iterator, bool > insert(const ValueT &V)
A raw_ostream that writes to an std::string.
This is an optimization pass for GlobalISel generic memory operations.
LLVM_DUMP_METHOD void dumpDotGraphToFile(const GraphType &G, const Twine &FileName, const Twine &Title, bool ShortNames=false, const Twine &Name="")
DumpDotGraph - Just dump a dot graph to the user-provided file name.
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
LLVM_ABI raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
DWARFExpression::Operation Op
void ViewGraph(const GraphType &G, const Twine &Name, bool ShortNames=false, const Twine &Title="", GraphProgram::Name Program=GraphProgram::DOT)
ViewGraph - Emit a dot graph, run 'dot', run gv on the postscript file, then cleanup.
std::string itostr(int64_t X)
std::string getNodeLabel(const SDNode *Node, const SelectionDAG *Graph)
static std::string getGraphName(const SelectionDAG *G)
Definition SelectionDAGPrinter.cpp:68
static unsigned numEdgeDestLabels(const void *Node)
Definition SelectionDAGPrinter.cpp:36
DOTGraphTraits(bool isSimple=false)
Definition SelectionDAGPrinter.cpp:29
static std::string getEdgeSourceLabel(const void *Node, EdgeIter I)
Definition SelectionDAGPrinter.cpp:45
static bool edgeTargetsEdgeSource(const void *Node, EdgeIter I)
edgeTargetsEdgeSource - This method returns true if this outgoing edge should actually target another...
Definition SelectionDAGPrinter.cpp:53
static bool hasEdgeDestLabels()
Definition SelectionDAGPrinter.cpp:32
static void addCustomGraphFeatures(SelectionDAG *G, GraphWriter< SelectionDAG * > &GW)
Definition SelectionDAGPrinter.cpp:127
static std::string getNodeAttributes(const SDNode *N, const SelectionDAG *Graph)
Definition SelectionDAGPrinter.cpp:113
static std::string getEdgeAttributes(const void *Node, EdgeIter EI, const SelectionDAG *Graph)
If you want to override the dot attributes printed for a particular edge, override this method.
Definition SelectionDAGPrinter.cpp:91
static std::string getSimpleNodeLabel(const SDNode *Node, const SelectionDAG *G)
Definition SelectionDAGPrinter.cpp:103
static EdgeIter getEdgeTarget(const void *Node, EdgeIter I)
getEdgeTarget - If edgeTargetsEdgeSource returns true, this method is called to determine which outgo...
Definition SelectionDAGPrinter.cpp:61
static bool renderGraphFromBottomUp()
Definition SelectionDAGPrinter.cpp:72
static std::string getNodeIdentifierLabel(const SDNode *Node, const SelectionDAG *Graph)
Definition SelectionDAGPrinter.cpp:76
static std::string getEdgeDestLabel(const void *Node, unsigned i)
Definition SelectionDAGPrinter.cpp:40
DOTGraphTraits - Template class that can be specialized to customize how graphs are converted to 'dot...
DefaultDOTGraphTraits(bool simple=false)
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...