blob: 5a7b3fd75dc5d0d0609add79e4e90ba094608e2c [file] [log] [blame]
Chris Lattner66328482005-01-10 23:08:40 +00001//===-- SelectionDAGPrinter.cpp - Implement SelectionDAG::viewGraph() -----===//
Misha Brukmanedf128a2005-04-21 22:36:52 +00002//
Chris Lattner66328482005-01-10 23:08:40 +00003// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Misha Brukmanedf128a2005-04-21 22:36:52 +00007//
Chris Lattner66328482005-01-10 23:08:40 +00008//===----------------------------------------------------------------------===//
9//
10// This implements the SelectionDAG::viewGraph method.
11//
12//===----------------------------------------------------------------------===//
13
Dan Gohman84fbac52009-02-06 17:22:58 +000014#include "ScheduleDAGSDNodes.h"
Chris Lattner5839bf22005-08-26 17:15:30 +000015#include "llvm/Constants.h"
16#include "llvm/Function.h"
Chris Lattner52676512006-03-05 09:38:03 +000017#include "llvm/Assembly/Writer.h"
Chris Lattner66328482005-01-10 23:08:40 +000018#include "llvm/CodeGen/SelectionDAG.h"
Evan Chengd6594ae2006-09-12 21:00:35 +000019#include "llvm/CodeGen/MachineConstantPool.h"
Chris Lattner66328482005-01-10 23:08:40 +000020#include "llvm/CodeGen/MachineFunction.h"
Bill Wendling10fff602008-07-03 22:53:42 +000021#include "llvm/CodeGen/MachineModuleInfo.h"
Dan Gohmandc5f9362008-07-17 21:12:16 +000022#include "llvm/CodeGen/PseudoSourceValue.h"
Devang Patel83489bb2009-01-13 00:35:13 +000023#include "llvm/Analysis/DebugInfo.h"
Dan Gohman6f0d0242008-02-10 18:45:23 +000024#include "llvm/Target/TargetRegisterInfo.h"
Chris Lattner7228aa72005-08-19 21:21:16 +000025#include "llvm/Target/TargetMachine.h"
David Greenec5e7e8d2008-10-27 18:17:03 +000026#include "llvm/Support/Debug.h"
Chris Lattner66328482005-01-10 23:08:40 +000027#include "llvm/Support/GraphWriter.h"
Chris Lattner62ca3252008-08-23 22:53:13 +000028#include "llvm/Support/raw_ostream.h"
David Greenec5e7e8d2008-10-27 18:17:03 +000029#include "llvm/ADT/DenseSet.h"
Chris Lattnere9c44cd2005-01-11 00:34:33 +000030#include "llvm/ADT/StringExtras.h"
Chris Lattner6e741f82005-07-15 22:48:31 +000031#include "llvm/Config/config.h"
Chris Lattner66328482005-01-10 23:08:40 +000032#include <fstream>
33using namespace llvm;
34
Chris Lattnere0646b82005-01-10 23:26:00 +000035namespace llvm {
36 template<>
37 struct DOTGraphTraits<SelectionDAG*> : public DefaultDOTGraphTraits {
Dan Gohman35803312008-07-21 21:06:55 +000038 static bool hasEdgeDestLabels() {
39 return true;
40 }
41
42 static unsigned numEdgeDestLabels(const void *Node) {
43 return ((const SDNode *) Node)->getNumValues();
44 }
45
46 static std::string getEdgeDestLabel(const void *Node, unsigned i) {
47 return ((const SDNode *) Node)->getValueType(i).getMVTString();
48 }
49
50 /// edgeTargetsEdgeSource - This method returns true if this outgoing edge
51 /// should actually target another edge source, not a node. If this method is
52 /// implemented, getEdgeTarget should be implemented.
53 template<typename EdgeIter>
54 static bool edgeTargetsEdgeSource(const void *Node, EdgeIter I) {
55 return true;
56 }
57
58 /// getEdgeTarget - If edgeTargetsEdgeSource returns true, this method is
59 /// called to determine which outgoing edge of Node is the target of this
60 /// edge.
61 template<typename EdgeIter>
62 static EdgeIter getEdgeTarget(const void *Node, EdgeIter I) {
63 SDNode *TargetNode = *I;
64 SDNodeIterator NI = SDNodeIterator::begin(TargetNode);
Gabor Greif99a6cb92008-08-26 22:36:50 +000065 std::advance(NI, I.getNode()->getOperand(I.getOperand()).getResNo());
Dan Gohman35803312008-07-21 21:06:55 +000066 return NI;
67 }
68
Chris Lattnere0646b82005-01-10 23:26:00 +000069 static std::string getGraphName(const SelectionDAG *G) {
70 return G->getMachineFunction().getFunction()->getName();
71 }
Chris Lattnere9c44cd2005-01-11 00:34:33 +000072
73 static bool renderGraphFromBottomUp() {
74 return true;
Chris Lattnere0646b82005-01-10 23:26:00 +000075 }
Chris Lattner37345fe2005-10-01 00:17:07 +000076
77 static bool hasNodeAddressLabel(const SDNode *Node,
78 const SelectionDAG *Graph) {
79 return true;
80 }
Chris Lattner34ab4d42006-10-20 18:06:09 +000081
82 /// If you want to override the dot attributes printed for a particular
83 /// edge, override this method.
84 template<typename EdgeIter>
85 static std::string getEdgeAttributes(const void *Node, EdgeIter EI) {
Dan Gohman475871a2008-07-27 21:46:04 +000086 SDValue Op = EI.getNode()->getOperand(EI.getOperand());
Duncan Sands83ec4b62008-06-06 12:08:01 +000087 MVT VT = Op.getValueType();
Chris Lattner34ab4d42006-10-20 18:06:09 +000088 if (VT == MVT::Flag)
89 return "color=red,style=bold";
90 else if (VT == MVT::Other)
Dan Gohman7a0a4fc2007-06-18 15:30:16 +000091 return "color=blue,style=dashed";
Chris Lattner34ab4d42006-10-20 18:06:09 +000092 return "";
93 }
94
Chris Lattnere0646b82005-01-10 23:26:00 +000095
Chris Lattnere9c44cd2005-01-11 00:34:33 +000096 static std::string getNodeLabel(const SDNode *Node,
Owen Anderson8cbc94a2009-06-24 17:37:09 +000097 const SelectionDAG *Graph,
98 bool ShortNames);
Jim Laskeyec204022006-10-02 12:26:53 +000099 static std::string getNodeAttributes(const SDNode *N,
100 const SelectionDAG *Graph) {
101#ifndef NDEBUG
102 const std::string &Attrs = Graph->getGraphAttrs(N);
103 if (!Attrs.empty()) {
104 if (Attrs.find("shape=") == std::string::npos)
105 return std::string("shape=Mrecord,") + Attrs;
106 else
107 return Attrs;
108 }
109#endif
Chris Lattnere0646b82005-01-10 23:26:00 +0000110 return "shape=Mrecord";
111 }
Chris Lattnerfc08d9c2005-01-10 23:52:04 +0000112
113 static void addCustomGraphFeatures(SelectionDAG *G,
114 GraphWriter<SelectionDAG*> &GW) {
115 GW.emitSimpleNode(0, "plaintext=circle", "GraphRoot");
Gabor Greifba36cb52008-08-28 21:40:38 +0000116 if (G->getRoot().getNode())
117 GW.emitEdge(0, -1, G->getRoot().getNode(), G->getRoot().getResNo(),
Dan Gohman694caf52008-07-22 17:52:59 +0000118 "color=blue,style=dashed");
Chris Lattnerfc08d9c2005-01-10 23:52:04 +0000119 }
Chris Lattnere0646b82005-01-10 23:26:00 +0000120 };
121}
122
Chris Lattnere9c44cd2005-01-11 00:34:33 +0000123std::string DOTGraphTraits<SelectionDAG*>::getNodeLabel(const SDNode *Node,
Owen Anderson8cbc94a2009-06-24 17:37:09 +0000124 const SelectionDAG *G,
125 bool ShortNames) {
Chris Lattnerad95d6a2005-08-16 18:31:23 +0000126 std::string Op = Node->getOperationName(G);
Chris Lattnerc871e1d2005-01-11 22:21:04 +0000127
Chris Lattnere9c44cd2005-01-11 00:34:33 +0000128 if (const ConstantSDNode *CSDN = dyn_cast<ConstantSDNode>(Node)) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000129 Op += ": " + utostr(CSDN->getZExtValue());
Chris Lattnere9c44cd2005-01-11 00:34:33 +0000130 } else if (const ConstantFPSDNode *CSDN = dyn_cast<ConstantFPSDNode>(Node)) {
Dale Johanneseneaf08942007-08-31 04:03:46 +0000131 Op += ": " + ftostr(CSDN->getValueAPF());
Misha Brukmanedf128a2005-04-21 22:36:52 +0000132 } else if (const GlobalAddressSDNode *GADN =
Chris Lattnere9c44cd2005-01-11 00:34:33 +0000133 dyn_cast<GlobalAddressSDNode>(Node)) {
134 Op += ": " + GADN->getGlobal()->getName();
Dan Gohman668aff62008-10-18 18:22:42 +0000135 if (int64_t Offset = GADN->getOffset()) {
Chris Lattnerca19a3f2008-09-21 18:38:31 +0000136 if (Offset > 0)
137 Op += "+" + itostr(Offset);
138 else
139 Op += itostr(Offset);
140 }
Misha Brukmandedf2bd2005-04-22 04:01:18 +0000141 } else if (const FrameIndexSDNode *FIDN = dyn_cast<FrameIndexSDNode>(Node)) {
Chris Lattnere9c44cd2005-01-11 00:34:33 +0000142 Op += " " + itostr(FIDN->getIndex());
Evan Cheng6cc31ae2006-11-01 04:48:30 +0000143 } else if (const JumpTableSDNode *JTDN = dyn_cast<JumpTableSDNode>(Node)) {
144 Op += " " + itostr(JTDN->getIndex());
Chris Lattnere9c44cd2005-01-11 00:34:33 +0000145 } else if (const ConstantPoolSDNode *CP = dyn_cast<ConstantPoolSDNode>(Node)){
Evan Chengd6594ae2006-09-12 21:00:35 +0000146 if (CP->isMachineConstantPoolEntry()) {
Chris Lattner62ca3252008-08-23 22:53:13 +0000147 Op += '<';
148 {
149 raw_string_ostream OSS(Op);
150 OSS << *CP->getMachineCPVal();
151 }
152 Op += '>';
Evan Chengd6594ae2006-09-12 21:00:35 +0000153 } else {
154 if (ConstantFP *CFP = dyn_cast<ConstantFP>(CP->getConstVal()))
Dale Johanneseneaf08942007-08-31 04:03:46 +0000155 Op += "<" + ftostr(CFP->getValueAPF()) + ">";
Evan Chengd6594ae2006-09-12 21:00:35 +0000156 else if (ConstantInt *CI = dyn_cast<ConstantInt>(CP->getConstVal()))
157 Op += "<" + utostr(CI->getZExtValue()) + ">";
158 else {
Chris Lattner62ca3252008-08-23 22:53:13 +0000159 Op += '<';
160 {
161 raw_string_ostream OSS(Op);
162 WriteAsOperand(OSS, CP->getConstVal(), false);
163 }
164 Op += '>';
Evan Chengd6594ae2006-09-12 21:00:35 +0000165 }
Chris Lattner52676512006-03-05 09:38:03 +0000166 }
Evan Cheng1606e8e2009-03-13 07:51:59 +0000167 Op += " A=" + itostr(CP->getAlignment());
Misha Brukmandedf2bd2005-04-22 04:01:18 +0000168 } else if (const BasicBlockSDNode *BBDN = dyn_cast<BasicBlockSDNode>(Node)) {
Chris Lattnere9c44cd2005-01-11 00:34:33 +0000169 Op = "BB: ";
170 const Value *LBB = (const Value*)BBDN->getBasicBlock()->getBasicBlock();
171 if (LBB)
172 Op += LBB->getName();
173 //Op += " " + (const void*)BBDN->getBasicBlock();
Chris Lattnerd5d0f9b2005-08-16 21:55:35 +0000174 } else if (const RegisterSDNode *R = dyn_cast<RegisterSDNode>(Node)) {
Chris Lattner34ab4d42006-10-20 18:06:09 +0000175 if (G && R->getReg() != 0 &&
Dan Gohman6f0d0242008-02-10 18:45:23 +0000176 TargetRegisterInfo::isPhysicalRegister(R->getReg())) {
Bill Wendling74ab84c2008-02-26 21:11:01 +0000177 Op = Op + " " +
Bill Wendling6ef781f2008-02-27 06:33:05 +0000178 G->getTarget().getRegisterInfo()->getName(R->getReg());
Chris Lattner7228aa72005-08-19 21:21:16 +0000179 } else {
180 Op += " #" + utostr(R->getReg());
181 }
Dan Gohman7f460202008-06-30 20:59:49 +0000182 } else if (const DbgStopPointSDNode *D = dyn_cast<DbgStopPointSDNode>(Node)) {
Devang Patel83489bb2009-01-13 00:35:13 +0000183 DICompileUnit CU(cast<GlobalVariable>(D->getCompileUnit()));
Bill Wendling0582ae92009-03-13 04:39:26 +0000184 std::string FN;
185 Op += ": " + CU.getFilename(FN);
Dan Gohman7f460202008-06-30 20:59:49 +0000186 Op += ":" + utostr(D->getLine());
187 if (D->getColumn() != 0)
188 Op += ":" + utostr(D->getColumn());
Dan Gohman44066042008-07-01 00:05:16 +0000189 } else if (const LabelSDNode *L = dyn_cast<LabelSDNode>(Node)) {
190 Op += ": LabelID=" + utostr(L->getLabelID());
Dan Gohman095cc292008-09-13 01:54:27 +0000191 } else if (const CallSDNode *C = dyn_cast<CallSDNode>(Node)) {
192 Op += ": CallingConv=" + utostr(C->getCallingConv());
193 if (C->isVarArg())
194 Op += ", isVarArg";
195 if (C->isTailCall())
196 Op += ", isTailCall";
Bill Wendling056292f2008-09-16 21:48:12 +0000197 } else if (const ExternalSymbolSDNode *ES =
198 dyn_cast<ExternalSymbolSDNode>(Node)) {
199 Op += "'" + std::string(ES->getSymbol()) + "'";
Chris Lattner2bf3c262005-05-09 04:08:27 +0000200 } else if (const SrcValueSDNode *M = dyn_cast<SrcValueSDNode>(Node)) {
201 if (M->getValue())
Dan Gohman69de1932008-02-06 22:27:42 +0000202 Op += "<" + M->getValue()->getName() + ">";
Chris Lattner2bf3c262005-05-09 04:08:27 +0000203 else
Dan Gohman69de1932008-02-06 22:27:42 +0000204 Op += "<null>";
205 } else if (const MemOperandSDNode *M = dyn_cast<MemOperandSDNode>(Node)) {
Dan Gohmandc5f9362008-07-17 21:12:16 +0000206 const Value *V = M->MO.getValue();
207 Op += '<';
208 if (!V) {
209 Op += "(unknown)";
Dan Gohman464fc5a2008-12-15 17:28:10 +0000210 } else if (const PseudoSourceValue *PSV = dyn_cast<PseudoSourceValue>(V)) {
Dan Gohmandc5f9362008-07-17 21:12:16 +0000211 // PseudoSourceValues don't have names, so use their print method.
Dan Gohman464fc5a2008-12-15 17:28:10 +0000212 raw_string_ostream OSS(Op);
213 PSV->print(OSS);
Dan Gohman91d49f52008-07-14 17:51:24 +0000214 } else {
Dan Gohmandc5f9362008-07-17 21:12:16 +0000215 Op += V->getName();
Dan Gohman91d49f52008-07-14 17:51:24 +0000216 }
Dan Gohmandc5f9362008-07-17 21:12:16 +0000217 Op += '+' + itostr(M->MO.getOffset()) + '>';
Duncan Sands276dcbd2008-03-21 09:14:45 +0000218 } else if (const ARG_FLAGSSDNode *N = dyn_cast<ARG_FLAGSSDNode>(Node)) {
219 Op = Op + " AF=" + N->getArgFlags().getArgFlagsString();
Chris Lattnera23e8152005-08-18 03:31:02 +0000220 } else if (const VTSDNode *N = dyn_cast<VTSDNode>(Node)) {
Duncan Sands83ec4b62008-06-06 12:08:01 +0000221 Op = Op + " VT=" + N->getVT().getMVTString();
Evan Cheng45aeccc2006-10-10 20:11:26 +0000222 } else if (const LoadSDNode *LD = dyn_cast<LoadSDNode>(Node)) {
223 bool doExt = true;
224 switch (LD->getExtensionType()) {
225 default: doExt = false; break;
226 case ISD::EXTLOAD:
227 Op = Op + "<anyext ";
228 break;
229 case ISD::SEXTLOAD:
230 Op = Op + " <sext ";
231 break;
232 case ISD::ZEXTLOAD:
233 Op = Op + " <zext ";
234 break;
235 }
236 if (doExt)
Duncan Sands83ec4b62008-06-06 12:08:01 +0000237 Op += LD->getMemoryVT().getMVTString() + ">";
Chris Lattner94ffc7e2008-01-25 06:40:45 +0000238 if (LD->isVolatile())
239 Op += "<V>";
Evan Cheng00305822006-11-09 18:44:21 +0000240 Op += LD->getIndexedModeName(LD->getAddressingMode());
Chris Lattner94ffc7e2008-01-25 06:40:45 +0000241 if (LD->getAlignment() > 1)
242 Op += " A=" + utostr(LD->getAlignment());
Evan Cheng649b7ef2006-10-17 21:18:26 +0000243 } else if (const StoreSDNode *ST = dyn_cast<StoreSDNode>(Node)) {
244 if (ST->isTruncatingStore())
Duncan Sands83ec4b62008-06-06 12:08:01 +0000245 Op += "<trunc " + ST->getMemoryVT().getMVTString() + ">";
Chris Lattner94ffc7e2008-01-25 06:40:45 +0000246 if (ST->isVolatile())
247 Op += "<V>";
Evan Cheng00305822006-11-09 18:44:21 +0000248 Op += ST->getIndexedModeName(ST->getAddressingMode());
Chris Lattner94ffc7e2008-01-25 06:40:45 +0000249 if (ST->getAlignment() > 1)
250 Op += " A=" + utostr(ST->getAlignment());
Chris Lattnere9c44cd2005-01-11 00:34:33 +0000251 }
Chris Lattner59afba02007-10-15 05:32:43 +0000252
253#if 0
254 Op += " Id=" + itostr(Node->getNodeId());
255#endif
Chris Lattner36ce6912005-11-29 06:21:05 +0000256
Chris Lattnere9c44cd2005-01-11 00:34:33 +0000257 return Op;
258}
Misha Brukmanedf128a2005-04-21 22:36:52 +0000259
Chris Lattnere9c44cd2005-01-11 00:34:33 +0000260
Chris Lattner66328482005-01-10 23:08:40 +0000261/// viewGraph - Pop up a ghostview window with the reachable parts of the DAG
262/// rendered using 'dot'.
263///
Dan Gohman462dc7f2008-07-21 20:00:07 +0000264void SelectionDAG::viewGraph(const std::string &Title) {
Chris Lattnere388b5e2005-07-14 05:17:43 +0000265// This code is only for debugging!
Chris Lattnerc5f44ad2005-07-14 05:33:13 +0000266#ifndef NDEBUG
Owen Anderson8cbc94a2009-06-24 17:37:09 +0000267 ViewGraph(this, "dag." + getMachineFunction().getFunction()->getName(), false,
Dan Gohman462dc7f2008-07-21 20:00:07 +0000268 Title);
Reid Spencer9d5b5322006-06-27 16:49:46 +0000269#else
Bill Wendling832171c2006-12-07 20:04:42 +0000270 cerr << "SelectionDAG::viewGraph is only available in debug builds on "
271 << "systems with Graphviz or gv!\n";
Reid Spencer9d5b5322006-06-27 16:49:46 +0000272#endif // NDEBUG
Chris Lattner66328482005-01-10 23:08:40 +0000273}
Jim Laskeyec204022006-10-02 12:26:53 +0000274
Dan Gohman0b12aef2008-07-30 18:48:53 +0000275// This overload is defined out-of-line here instead of just using a
276// default parameter because this is easiest for gdb to call.
277void SelectionDAG::viewGraph() {
278 viewGraph("");
279}
Jim Laskeyec204022006-10-02 12:26:53 +0000280
281/// clearGraphAttrs - Clear all previously defined node graph attributes.
282/// Intended to be used from a debugging tool (eg. gdb).
283void SelectionDAG::clearGraphAttrs() {
284#ifndef NDEBUG
285 NodeGraphAttrs.clear();
286#else
Bill Wendling832171c2006-12-07 20:04:42 +0000287 cerr << "SelectionDAG::clearGraphAttrs is only available in debug builds"
288 << " on systems with Graphviz or gv!\n";
Jim Laskeyec204022006-10-02 12:26:53 +0000289#endif
290}
291
292
293/// setGraphAttrs - Set graph attributes for a node. (eg. "color=red".)
294///
295void SelectionDAG::setGraphAttrs(const SDNode *N, const char *Attrs) {
296#ifndef NDEBUG
297 NodeGraphAttrs[N] = Attrs;
298#else
Bill Wendling832171c2006-12-07 20:04:42 +0000299 cerr << "SelectionDAG::setGraphAttrs is only available in debug builds"
300 << " on systems with Graphviz or gv!\n";
Jim Laskeyec204022006-10-02 12:26:53 +0000301#endif
302}
303
304
305/// getGraphAttrs - Get graph attributes for a node. (eg. "color=red".)
306/// Used from getNodeAttributes.
307const std::string SelectionDAG::getGraphAttrs(const SDNode *N) const {
308#ifndef NDEBUG
309 std::map<const SDNode *, std::string>::const_iterator I =
310 NodeGraphAttrs.find(N);
311
312 if (I != NodeGraphAttrs.end())
313 return I->second;
314 else
315 return "";
316#else
Bill Wendling832171c2006-12-07 20:04:42 +0000317 cerr << "SelectionDAG::getGraphAttrs is only available in debug builds"
318 << " on systems with Graphviz or gv!\n";
Jim Laskeyec204022006-10-02 12:26:53 +0000319 return std::string("");
320#endif
321}
322
323/// setGraphColor - Convenience for setting node color attribute.
324///
325void SelectionDAG::setGraphColor(const SDNode *N, const char *Color) {
326#ifndef NDEBUG
327 NodeGraphAttrs[N] = std::string("color=") + Color;
328#else
Bill Wendling832171c2006-12-07 20:04:42 +0000329 cerr << "SelectionDAG::setGraphColor is only available in debug builds"
330 << " on systems with Graphviz or gv!\n";
Jim Laskeyec204022006-10-02 12:26:53 +0000331#endif
332}
333
David Greenec5e7e8d2008-10-27 18:17:03 +0000334/// setSubgraphColorHelper - Implement setSubgraphColor. Return
335/// whether we truncated the search.
336///
337bool SelectionDAG::setSubgraphColorHelper(SDNode *N, const char *Color, DenseSet<SDNode *> &visited,
338 int level, bool &printed) {
339 bool hit_limit = false;
340
341#ifndef NDEBUG
342 if (level >= 20) {
343 if (!printed) {
344 printed = true;
345 DOUT << "setSubgraphColor hit max level\n";
346 }
347 return true;
348 }
349
350 unsigned oldSize = visited.size();
351 visited.insert(N);
352 if (visited.size() != oldSize) {
353 setGraphColor(N, Color);
354 for(SDNodeIterator i = SDNodeIterator::begin(N), iend = SDNodeIterator::end(N);
355 i != iend;
356 ++i) {
357 hit_limit = setSubgraphColorHelper(*i, Color, visited, level+1, printed) || hit_limit;
358 }
359 }
360#else
361 cerr << "SelectionDAG::setSubgraphColor is only available in debug builds"
362 << " on systems with Graphviz or gv!\n";
363#endif
364 return hit_limit;
365}
366
367/// setSubgraphColor - Convenience for setting subgraph color attribute.
368///
369void SelectionDAG::setSubgraphColor(SDNode *N, const char *Color) {
370#ifndef NDEBUG
371 DenseSet<SDNode *> visited;
372 bool printed = false;
373 if (setSubgraphColorHelper(N, Color, visited, 0, printed)) {
374 // Visually mark that we hit the limit
Ted Kremenek8e7fa912008-10-27 22:43:07 +0000375 if (strcmp(Color, "red") == 0) {
David Greenec5e7e8d2008-10-27 18:17:03 +0000376 setSubgraphColorHelper(N, "blue", visited, 0, printed);
377 }
Ted Kremenek8e7fa912008-10-27 22:43:07 +0000378 else if (strcmp(Color, "yellow") == 0) {
David Greenec5e7e8d2008-10-27 18:17:03 +0000379 setSubgraphColorHelper(N, "green", visited, 0, printed);
380 }
381 }
382
383#else
384 cerr << "SelectionDAG::setSubgraphColor is only available in debug builds"
385 << " on systems with Graphviz or gv!\n";
386#endif
387}
388
Dan Gohman343f0c02008-11-19 23:18:57 +0000389std::string ScheduleDAGSDNodes::getGraphNodeLabel(const SUnit *SU) const {
Dan Gohman7d1cd3f2008-11-19 22:09:45 +0000390 std::string s;
391 raw_string_ostream O(s);
392 O << "SU(" << SU->NodeNum << "): ";
393 if (SU->getNode()) {
394 SmallVector<SDNode *, 4> FlaggedNodes;
395 for (SDNode *N = SU->getNode(); N; N = N->getFlaggedNode())
396 FlaggedNodes.push_back(N);
397 while (!FlaggedNodes.empty()) {
Owen Anderson8cbc94a2009-06-24 17:37:09 +0000398 O << DOTGraphTraits<SelectionDAG*>::getNodeLabel(FlaggedNodes.back(),
399 DAG, false);
Dan Gohman7d1cd3f2008-11-19 22:09:45 +0000400 FlaggedNodes.pop_back();
401 if (!FlaggedNodes.empty())
402 O << "\n ";
403 }
404 } else {
405 O << "CROSS RC COPY";
406 }
407 return O.str();
408}
Dan Gohman3e1a7ae2007-08-28 20:32:58 +0000409
Dan Gohman343f0c02008-11-19 23:18:57 +0000410void ScheduleDAGSDNodes::getCustomGraphFeatures(GraphWriter<ScheduleDAG*> &GW) const {
411 if (DAG) {
412 // Draw a special "GraphRoot" node to indicate the root of the graph.
413 GW.emitSimpleNode(0, "plaintext=circle", "GraphRoot");
414 const SDNode *N = DAG->getRoot().getNode();
415 if (N && N->getNodeId() != -1)
416 GW.emitEdge(0, -1, &SUnits[N->getNodeId()], -1,
417 "color=blue,style=dashed");
418 }
Dan Gohman3e1a7ae2007-08-28 20:32:58 +0000419}