xref: /aosp_15_r20/external/llvm/lib/CodeGen/SelectionDAG/SelectionDAGPrinter.cpp (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker //===-- SelectionDAGPrinter.cpp - Implement SelectionDAG::viewGraph() -----===//
2*9880d681SAndroid Build Coastguard Worker //
3*9880d681SAndroid Build Coastguard Worker //                     The LLVM Compiler Infrastructure
4*9880d681SAndroid Build Coastguard Worker //
5*9880d681SAndroid Build Coastguard Worker // This file is distributed under the University of Illinois Open Source
6*9880d681SAndroid Build Coastguard Worker // License. See LICENSE.TXT for details.
7*9880d681SAndroid Build Coastguard Worker //
8*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===//
9*9880d681SAndroid Build Coastguard Worker //
10*9880d681SAndroid Build Coastguard Worker // This implements the SelectionDAG::viewGraph method.
11*9880d681SAndroid Build Coastguard Worker //
12*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===//
13*9880d681SAndroid Build Coastguard Worker 
14*9880d681SAndroid Build Coastguard Worker #include "llvm/CodeGen/SelectionDAG.h"
15*9880d681SAndroid Build Coastguard Worker #include "ScheduleDAGSDNodes.h"
16*9880d681SAndroid Build Coastguard Worker #include "llvm/ADT/DenseSet.h"
17*9880d681SAndroid Build Coastguard Worker #include "llvm/ADT/StringExtras.h"
18*9880d681SAndroid Build Coastguard Worker #include "llvm/CodeGen/MachineConstantPool.h"
19*9880d681SAndroid Build Coastguard Worker #include "llvm/CodeGen/MachineFunction.h"
20*9880d681SAndroid Build Coastguard Worker #include "llvm/CodeGen/MachineModuleInfo.h"
21*9880d681SAndroid Build Coastguard Worker #include "llvm/IR/Constants.h"
22*9880d681SAndroid Build Coastguard Worker #include "llvm/IR/DebugInfo.h"
23*9880d681SAndroid Build Coastguard Worker #include "llvm/Support/Debug.h"
24*9880d681SAndroid Build Coastguard Worker #include "llvm/Support/GraphWriter.h"
25*9880d681SAndroid Build Coastguard Worker #include "llvm/Support/raw_ostream.h"
26*9880d681SAndroid Build Coastguard Worker #include "llvm/Target/TargetMachine.h"
27*9880d681SAndroid Build Coastguard Worker #include "llvm/Target/TargetRegisterInfo.h"
28*9880d681SAndroid Build Coastguard Worker using namespace llvm;
29*9880d681SAndroid Build Coastguard Worker 
30*9880d681SAndroid Build Coastguard Worker #define DEBUG_TYPE "dag-printer"
31*9880d681SAndroid Build Coastguard Worker 
32*9880d681SAndroid Build Coastguard Worker namespace llvm {
33*9880d681SAndroid Build Coastguard Worker   template<>
34*9880d681SAndroid Build Coastguard Worker   struct DOTGraphTraits<SelectionDAG*> : public DefaultDOTGraphTraits {
35*9880d681SAndroid Build Coastguard Worker 
DOTGraphTraitsllvm::DOTGraphTraits36*9880d681SAndroid Build Coastguard Worker     explicit DOTGraphTraits(bool isSimple=false) :
37*9880d681SAndroid Build Coastguard Worker       DefaultDOTGraphTraits(isSimple) {}
38*9880d681SAndroid Build Coastguard Worker 
hasEdgeDestLabelsllvm::DOTGraphTraits39*9880d681SAndroid Build Coastguard Worker     static bool hasEdgeDestLabels() {
40*9880d681SAndroid Build Coastguard Worker       return true;
41*9880d681SAndroid Build Coastguard Worker     }
42*9880d681SAndroid Build Coastguard Worker 
numEdgeDestLabelsllvm::DOTGraphTraits43*9880d681SAndroid Build Coastguard Worker     static unsigned numEdgeDestLabels(const void *Node) {
44*9880d681SAndroid Build Coastguard Worker       return ((const SDNode *) Node)->getNumValues();
45*9880d681SAndroid Build Coastguard Worker     }
46*9880d681SAndroid Build Coastguard Worker 
getEdgeDestLabelllvm::DOTGraphTraits47*9880d681SAndroid Build Coastguard Worker     static std::string getEdgeDestLabel(const void *Node, unsigned i) {
48*9880d681SAndroid Build Coastguard Worker       return ((const SDNode *) Node)->getValueType(i).getEVTString();
49*9880d681SAndroid Build Coastguard Worker     }
50*9880d681SAndroid Build Coastguard Worker 
51*9880d681SAndroid Build Coastguard Worker     template<typename EdgeIter>
getEdgeSourceLabelllvm::DOTGraphTraits52*9880d681SAndroid Build Coastguard Worker     static std::string getEdgeSourceLabel(const void *Node, EdgeIter I) {
53*9880d681SAndroid Build Coastguard Worker       return itostr(I - SDNodeIterator::begin((const SDNode *) Node));
54*9880d681SAndroid Build Coastguard Worker     }
55*9880d681SAndroid Build Coastguard Worker 
56*9880d681SAndroid Build Coastguard Worker     /// edgeTargetsEdgeSource - This method returns true if this outgoing edge
57*9880d681SAndroid Build Coastguard Worker     /// should actually target another edge source, not a node.  If this method
58*9880d681SAndroid Build Coastguard Worker     /// is implemented, getEdgeTarget should be implemented.
59*9880d681SAndroid Build Coastguard Worker     template<typename EdgeIter>
edgeTargetsEdgeSourcellvm::DOTGraphTraits60*9880d681SAndroid Build Coastguard Worker     static bool edgeTargetsEdgeSource(const void *Node, EdgeIter I) {
61*9880d681SAndroid Build Coastguard Worker       return true;
62*9880d681SAndroid Build Coastguard Worker     }
63*9880d681SAndroid Build Coastguard Worker 
64*9880d681SAndroid Build Coastguard Worker     /// getEdgeTarget - If edgeTargetsEdgeSource returns true, this method is
65*9880d681SAndroid Build Coastguard Worker     /// called to determine which outgoing edge of Node is the target of this
66*9880d681SAndroid Build Coastguard Worker     /// edge.
67*9880d681SAndroid Build Coastguard Worker     template<typename EdgeIter>
getEdgeTargetllvm::DOTGraphTraits68*9880d681SAndroid Build Coastguard Worker     static EdgeIter getEdgeTarget(const void *Node, EdgeIter I) {
69*9880d681SAndroid Build Coastguard Worker       SDNode *TargetNode = *I;
70*9880d681SAndroid Build Coastguard Worker       SDNodeIterator NI = SDNodeIterator::begin(TargetNode);
71*9880d681SAndroid Build Coastguard Worker       std::advance(NI, I.getNode()->getOperand(I.getOperand()).getResNo());
72*9880d681SAndroid Build Coastguard Worker       return NI;
73*9880d681SAndroid Build Coastguard Worker     }
74*9880d681SAndroid Build Coastguard Worker 
getGraphNamellvm::DOTGraphTraits75*9880d681SAndroid Build Coastguard Worker     static std::string getGraphName(const SelectionDAG *G) {
76*9880d681SAndroid Build Coastguard Worker       return G->getMachineFunction().getName();
77*9880d681SAndroid Build Coastguard Worker     }
78*9880d681SAndroid Build Coastguard Worker 
renderGraphFromBottomUpllvm::DOTGraphTraits79*9880d681SAndroid Build Coastguard Worker     static bool renderGraphFromBottomUp() {
80*9880d681SAndroid Build Coastguard Worker       return true;
81*9880d681SAndroid Build Coastguard Worker     }
82*9880d681SAndroid Build Coastguard Worker 
getNodeIdentifierLabelllvm::DOTGraphTraits83*9880d681SAndroid Build Coastguard Worker     static std::string getNodeIdentifierLabel(const SDNode *Node,
84*9880d681SAndroid Build Coastguard Worker                                               const SelectionDAG *Graph) {
85*9880d681SAndroid Build Coastguard Worker       std::string R;
86*9880d681SAndroid Build Coastguard Worker       raw_string_ostream OS(R);
87*9880d681SAndroid Build Coastguard Worker #ifndef NDEBUG
88*9880d681SAndroid Build Coastguard Worker       OS << 't' << Node->PersistentId;
89*9880d681SAndroid Build Coastguard Worker #else
90*9880d681SAndroid Build Coastguard Worker       OS << static_cast<const void *>(Node);
91*9880d681SAndroid Build Coastguard Worker #endif
92*9880d681SAndroid Build Coastguard Worker       return R;
93*9880d681SAndroid Build Coastguard Worker     }
94*9880d681SAndroid Build Coastguard Worker 
95*9880d681SAndroid Build Coastguard Worker     /// If you want to override the dot attributes printed for a particular
96*9880d681SAndroid Build Coastguard Worker     /// edge, override this method.
97*9880d681SAndroid Build Coastguard Worker     template<typename EdgeIter>
getEdgeAttributesllvm::DOTGraphTraits98*9880d681SAndroid Build Coastguard Worker     static std::string getEdgeAttributes(const void *Node, EdgeIter EI,
99*9880d681SAndroid Build Coastguard Worker                                          const SelectionDAG *Graph) {
100*9880d681SAndroid Build Coastguard Worker       SDValue Op = EI.getNode()->getOperand(EI.getOperand());
101*9880d681SAndroid Build Coastguard Worker       EVT VT = Op.getValueType();
102*9880d681SAndroid Build Coastguard Worker       if (VT == MVT::Glue)
103*9880d681SAndroid Build Coastguard Worker         return "color=red,style=bold";
104*9880d681SAndroid Build Coastguard Worker       else if (VT == MVT::Other)
105*9880d681SAndroid Build Coastguard Worker         return "color=blue,style=dashed";
106*9880d681SAndroid Build Coastguard Worker       return "";
107*9880d681SAndroid Build Coastguard Worker     }
108*9880d681SAndroid Build Coastguard Worker 
109*9880d681SAndroid Build Coastguard Worker 
getSimpleNodeLabelllvm::DOTGraphTraits110*9880d681SAndroid Build Coastguard Worker     static std::string getSimpleNodeLabel(const SDNode *Node,
111*9880d681SAndroid Build Coastguard Worker                                           const SelectionDAG *G) {
112*9880d681SAndroid Build Coastguard Worker       std::string Result = Node->getOperationName(G);
113*9880d681SAndroid Build Coastguard Worker       {
114*9880d681SAndroid Build Coastguard Worker         raw_string_ostream OS(Result);
115*9880d681SAndroid Build Coastguard Worker         Node->print_details(OS, G);
116*9880d681SAndroid Build Coastguard Worker       }
117*9880d681SAndroid Build Coastguard Worker       return Result;
118*9880d681SAndroid Build Coastguard Worker     }
119*9880d681SAndroid Build Coastguard Worker     std::string getNodeLabel(const SDNode *Node, const SelectionDAG *Graph);
getNodeAttributesllvm::DOTGraphTraits120*9880d681SAndroid Build Coastguard Worker     static std::string getNodeAttributes(const SDNode *N,
121*9880d681SAndroid Build Coastguard Worker                                          const SelectionDAG *Graph) {
122*9880d681SAndroid Build Coastguard Worker #ifndef NDEBUG
123*9880d681SAndroid Build Coastguard Worker       const std::string &Attrs = Graph->getGraphAttrs(N);
124*9880d681SAndroid Build Coastguard Worker       if (!Attrs.empty()) {
125*9880d681SAndroid Build Coastguard Worker         if (Attrs.find("shape=") == std::string::npos)
126*9880d681SAndroid Build Coastguard Worker           return std::string("shape=Mrecord,") + Attrs;
127*9880d681SAndroid Build Coastguard Worker         else
128*9880d681SAndroid Build Coastguard Worker           return Attrs;
129*9880d681SAndroid Build Coastguard Worker       }
130*9880d681SAndroid Build Coastguard Worker #endif
131*9880d681SAndroid Build Coastguard Worker       return "shape=Mrecord";
132*9880d681SAndroid Build Coastguard Worker     }
133*9880d681SAndroid Build Coastguard Worker 
addCustomGraphFeaturesllvm::DOTGraphTraits134*9880d681SAndroid Build Coastguard Worker     static void addCustomGraphFeatures(SelectionDAG *G,
135*9880d681SAndroid Build Coastguard Worker                                        GraphWriter<SelectionDAG*> &GW) {
136*9880d681SAndroid Build Coastguard Worker       GW.emitSimpleNode(nullptr, "plaintext=circle", "GraphRoot");
137*9880d681SAndroid Build Coastguard Worker       if (G->getRoot().getNode())
138*9880d681SAndroid Build Coastguard Worker         GW.emitEdge(nullptr, -1, G->getRoot().getNode(), G->getRoot().getResNo(),
139*9880d681SAndroid Build Coastguard Worker                     "color=blue,style=dashed");
140*9880d681SAndroid Build Coastguard Worker     }
141*9880d681SAndroid Build Coastguard Worker   };
142*9880d681SAndroid Build Coastguard Worker }
143*9880d681SAndroid Build Coastguard Worker 
getNodeLabel(const SDNode * Node,const SelectionDAG * G)144*9880d681SAndroid Build Coastguard Worker std::string DOTGraphTraits<SelectionDAG*>::getNodeLabel(const SDNode *Node,
145*9880d681SAndroid Build Coastguard Worker                                                         const SelectionDAG *G) {
146*9880d681SAndroid Build Coastguard Worker   return DOTGraphTraits<SelectionDAG*>::getSimpleNodeLabel(Node, G);
147*9880d681SAndroid Build Coastguard Worker }
148*9880d681SAndroid Build Coastguard Worker 
149*9880d681SAndroid Build Coastguard Worker 
150*9880d681SAndroid Build Coastguard Worker /// viewGraph - Pop up a ghostview window with the reachable parts of the DAG
151*9880d681SAndroid Build Coastguard Worker /// rendered using 'dot'.
152*9880d681SAndroid Build Coastguard Worker ///
viewGraph(const std::string & Title)153*9880d681SAndroid Build Coastguard Worker void SelectionDAG::viewGraph(const std::string &Title) {
154*9880d681SAndroid Build Coastguard Worker // This code is only for debugging!
155*9880d681SAndroid Build Coastguard Worker #ifndef NDEBUG
156*9880d681SAndroid Build Coastguard Worker   ViewGraph(this, "dag." + getMachineFunction().getName(),
157*9880d681SAndroid Build Coastguard Worker             false, Title);
158*9880d681SAndroid Build Coastguard Worker #else
159*9880d681SAndroid Build Coastguard Worker   errs() << "SelectionDAG::viewGraph is only available in debug builds on "
160*9880d681SAndroid Build Coastguard Worker          << "systems with Graphviz or gv!\n";
161*9880d681SAndroid Build Coastguard Worker #endif  // NDEBUG
162*9880d681SAndroid Build Coastguard Worker }
163*9880d681SAndroid Build Coastguard Worker 
164*9880d681SAndroid Build Coastguard Worker // This overload is defined out-of-line here instead of just using a
165*9880d681SAndroid Build Coastguard Worker // default parameter because this is easiest for gdb to call.
viewGraph()166*9880d681SAndroid Build Coastguard Worker void SelectionDAG::viewGraph() {
167*9880d681SAndroid Build Coastguard Worker   viewGraph("");
168*9880d681SAndroid Build Coastguard Worker }
169*9880d681SAndroid Build Coastguard Worker 
170*9880d681SAndroid Build Coastguard Worker /// clearGraphAttrs - Clear all previously defined node graph attributes.
171*9880d681SAndroid Build Coastguard Worker /// Intended to be used from a debugging tool (eg. gdb).
clearGraphAttrs()172*9880d681SAndroid Build Coastguard Worker void SelectionDAG::clearGraphAttrs() {
173*9880d681SAndroid Build Coastguard Worker #ifndef NDEBUG
174*9880d681SAndroid Build Coastguard Worker   NodeGraphAttrs.clear();
175*9880d681SAndroid Build Coastguard Worker #else
176*9880d681SAndroid Build Coastguard Worker   errs() << "SelectionDAG::clearGraphAttrs is only available in debug builds"
177*9880d681SAndroid Build Coastguard Worker          << " on systems with Graphviz or gv!\n";
178*9880d681SAndroid Build Coastguard Worker #endif
179*9880d681SAndroid Build Coastguard Worker }
180*9880d681SAndroid Build Coastguard Worker 
181*9880d681SAndroid Build Coastguard Worker 
182*9880d681SAndroid Build Coastguard Worker /// setGraphAttrs - Set graph attributes for a node. (eg. "color=red".)
183*9880d681SAndroid Build Coastguard Worker ///
setGraphAttrs(const SDNode * N,const char * Attrs)184*9880d681SAndroid Build Coastguard Worker void SelectionDAG::setGraphAttrs(const SDNode *N, const char *Attrs) {
185*9880d681SAndroid Build Coastguard Worker #ifndef NDEBUG
186*9880d681SAndroid Build Coastguard Worker   NodeGraphAttrs[N] = Attrs;
187*9880d681SAndroid Build Coastguard Worker #else
188*9880d681SAndroid Build Coastguard Worker   errs() << "SelectionDAG::setGraphAttrs is only available in debug builds"
189*9880d681SAndroid Build Coastguard Worker          << " on systems with Graphviz or gv!\n";
190*9880d681SAndroid Build Coastguard Worker #endif
191*9880d681SAndroid Build Coastguard Worker }
192*9880d681SAndroid Build Coastguard Worker 
193*9880d681SAndroid Build Coastguard Worker 
194*9880d681SAndroid Build Coastguard Worker /// getGraphAttrs - Get graph attributes for a node. (eg. "color=red".)
195*9880d681SAndroid Build Coastguard Worker /// Used from getNodeAttributes.
getGraphAttrs(const SDNode * N) const196*9880d681SAndroid Build Coastguard Worker const std::string SelectionDAG::getGraphAttrs(const SDNode *N) const {
197*9880d681SAndroid Build Coastguard Worker #ifndef NDEBUG
198*9880d681SAndroid Build Coastguard Worker   std::map<const SDNode *, std::string>::const_iterator I =
199*9880d681SAndroid Build Coastguard Worker     NodeGraphAttrs.find(N);
200*9880d681SAndroid Build Coastguard Worker 
201*9880d681SAndroid Build Coastguard Worker   if (I != NodeGraphAttrs.end())
202*9880d681SAndroid Build Coastguard Worker     return I->second;
203*9880d681SAndroid Build Coastguard Worker   else
204*9880d681SAndroid Build Coastguard Worker     return "";
205*9880d681SAndroid Build Coastguard Worker #else
206*9880d681SAndroid Build Coastguard Worker   errs() << "SelectionDAG::getGraphAttrs is only available in debug builds"
207*9880d681SAndroid Build Coastguard Worker          << " on systems with Graphviz or gv!\n";
208*9880d681SAndroid Build Coastguard Worker   return std::string();
209*9880d681SAndroid Build Coastguard Worker #endif
210*9880d681SAndroid Build Coastguard Worker }
211*9880d681SAndroid Build Coastguard Worker 
212*9880d681SAndroid Build Coastguard Worker /// setGraphColor - Convenience for setting node color attribute.
213*9880d681SAndroid Build Coastguard Worker ///
setGraphColor(const SDNode * N,const char * Color)214*9880d681SAndroid Build Coastguard Worker void SelectionDAG::setGraphColor(const SDNode *N, const char *Color) {
215*9880d681SAndroid Build Coastguard Worker #ifndef NDEBUG
216*9880d681SAndroid Build Coastguard Worker   NodeGraphAttrs[N] = std::string("color=") + Color;
217*9880d681SAndroid Build Coastguard Worker #else
218*9880d681SAndroid Build Coastguard Worker   errs() << "SelectionDAG::setGraphColor is only available in debug builds"
219*9880d681SAndroid Build Coastguard Worker          << " on systems with Graphviz or gv!\n";
220*9880d681SAndroid Build Coastguard Worker #endif
221*9880d681SAndroid Build Coastguard Worker }
222*9880d681SAndroid Build Coastguard Worker 
223*9880d681SAndroid Build Coastguard Worker /// setSubgraphColorHelper - Implement setSubgraphColor.  Return
224*9880d681SAndroid Build Coastguard Worker /// whether we truncated the search.
225*9880d681SAndroid Build Coastguard Worker ///
setSubgraphColorHelper(SDNode * N,const char * Color,DenseSet<SDNode * > & visited,int level,bool & printed)226*9880d681SAndroid Build Coastguard Worker bool SelectionDAG::setSubgraphColorHelper(SDNode *N, const char *Color, DenseSet<SDNode *> &visited,
227*9880d681SAndroid Build Coastguard Worker                                           int level, bool &printed) {
228*9880d681SAndroid Build Coastguard Worker   bool hit_limit = false;
229*9880d681SAndroid Build Coastguard Worker 
230*9880d681SAndroid Build Coastguard Worker #ifndef NDEBUG
231*9880d681SAndroid Build Coastguard Worker   if (level >= 20) {
232*9880d681SAndroid Build Coastguard Worker     if (!printed) {
233*9880d681SAndroid Build Coastguard Worker       printed = true;
234*9880d681SAndroid Build Coastguard Worker       DEBUG(dbgs() << "setSubgraphColor hit max level\n");
235*9880d681SAndroid Build Coastguard Worker     }
236*9880d681SAndroid Build Coastguard Worker     return true;
237*9880d681SAndroid Build Coastguard Worker   }
238*9880d681SAndroid Build Coastguard Worker 
239*9880d681SAndroid Build Coastguard Worker   unsigned oldSize = visited.size();
240*9880d681SAndroid Build Coastguard Worker   visited.insert(N);
241*9880d681SAndroid Build Coastguard Worker   if (visited.size() != oldSize) {
242*9880d681SAndroid Build Coastguard Worker     setGraphColor(N, Color);
243*9880d681SAndroid Build Coastguard Worker     for(SDNodeIterator i = SDNodeIterator::begin(N), iend = SDNodeIterator::end(N);
244*9880d681SAndroid Build Coastguard Worker         i != iend;
245*9880d681SAndroid Build Coastguard Worker         ++i) {
246*9880d681SAndroid Build Coastguard Worker       hit_limit = setSubgraphColorHelper(*i, Color, visited, level+1, printed) || hit_limit;
247*9880d681SAndroid Build Coastguard Worker     }
248*9880d681SAndroid Build Coastguard Worker   }
249*9880d681SAndroid Build Coastguard Worker #else
250*9880d681SAndroid Build Coastguard Worker   errs() << "SelectionDAG::setSubgraphColor is only available in debug builds"
251*9880d681SAndroid Build Coastguard Worker          << " on systems with Graphviz or gv!\n";
252*9880d681SAndroid Build Coastguard Worker #endif
253*9880d681SAndroid Build Coastguard Worker   return hit_limit;
254*9880d681SAndroid Build Coastguard Worker }
255*9880d681SAndroid Build Coastguard Worker 
256*9880d681SAndroid Build Coastguard Worker /// setSubgraphColor - Convenience for setting subgraph color attribute.
257*9880d681SAndroid Build Coastguard Worker ///
setSubgraphColor(SDNode * N,const char * Color)258*9880d681SAndroid Build Coastguard Worker void SelectionDAG::setSubgraphColor(SDNode *N, const char *Color) {
259*9880d681SAndroid Build Coastguard Worker #ifndef NDEBUG
260*9880d681SAndroid Build Coastguard Worker   DenseSet<SDNode *> visited;
261*9880d681SAndroid Build Coastguard Worker   bool printed = false;
262*9880d681SAndroid Build Coastguard Worker   if (setSubgraphColorHelper(N, Color, visited, 0, printed)) {
263*9880d681SAndroid Build Coastguard Worker     // Visually mark that we hit the limit
264*9880d681SAndroid Build Coastguard Worker     if (strcmp(Color, "red") == 0) {
265*9880d681SAndroid Build Coastguard Worker       setSubgraphColorHelper(N, "blue", visited, 0, printed);
266*9880d681SAndroid Build Coastguard Worker     } else if (strcmp(Color, "yellow") == 0) {
267*9880d681SAndroid Build Coastguard Worker       setSubgraphColorHelper(N, "green", visited, 0, printed);
268*9880d681SAndroid Build Coastguard Worker     }
269*9880d681SAndroid Build Coastguard Worker   }
270*9880d681SAndroid Build Coastguard Worker 
271*9880d681SAndroid Build Coastguard Worker #else
272*9880d681SAndroid Build Coastguard Worker   errs() << "SelectionDAG::setSubgraphColor is only available in debug builds"
273*9880d681SAndroid Build Coastguard Worker          << " on systems with Graphviz or gv!\n";
274*9880d681SAndroid Build Coastguard Worker #endif
275*9880d681SAndroid Build Coastguard Worker }
276*9880d681SAndroid Build Coastguard Worker 
getGraphNodeLabel(const SUnit * SU) const277*9880d681SAndroid Build Coastguard Worker std::string ScheduleDAGSDNodes::getGraphNodeLabel(const SUnit *SU) const {
278*9880d681SAndroid Build Coastguard Worker   std::string s;
279*9880d681SAndroid Build Coastguard Worker   raw_string_ostream O(s);
280*9880d681SAndroid Build Coastguard Worker   O << "SU(" << SU->NodeNum << "): ";
281*9880d681SAndroid Build Coastguard Worker   if (SU->getNode()) {
282*9880d681SAndroid Build Coastguard Worker     SmallVector<SDNode *, 4> GluedNodes;
283*9880d681SAndroid Build Coastguard Worker     for (SDNode *N = SU->getNode(); N; N = N->getGluedNode())
284*9880d681SAndroid Build Coastguard Worker       GluedNodes.push_back(N);
285*9880d681SAndroid Build Coastguard Worker     while (!GluedNodes.empty()) {
286*9880d681SAndroid Build Coastguard Worker       O << DOTGraphTraits<SelectionDAG*>
287*9880d681SAndroid Build Coastguard Worker         ::getSimpleNodeLabel(GluedNodes.back(), DAG);
288*9880d681SAndroid Build Coastguard Worker       GluedNodes.pop_back();
289*9880d681SAndroid Build Coastguard Worker       if (!GluedNodes.empty())
290*9880d681SAndroid Build Coastguard Worker         O << "\n    ";
291*9880d681SAndroid Build Coastguard Worker     }
292*9880d681SAndroid Build Coastguard Worker   } else {
293*9880d681SAndroid Build Coastguard Worker     O << "CROSS RC COPY";
294*9880d681SAndroid Build Coastguard Worker   }
295*9880d681SAndroid Build Coastguard Worker   return O.str();
296*9880d681SAndroid Build Coastguard Worker }
297*9880d681SAndroid Build Coastguard Worker 
getCustomGraphFeatures(GraphWriter<ScheduleDAG * > & GW) const298*9880d681SAndroid Build Coastguard Worker void ScheduleDAGSDNodes::getCustomGraphFeatures(GraphWriter<ScheduleDAG*> &GW) const {
299*9880d681SAndroid Build Coastguard Worker   if (DAG) {
300*9880d681SAndroid Build Coastguard Worker     // Draw a special "GraphRoot" node to indicate the root of the graph.
301*9880d681SAndroid Build Coastguard Worker     GW.emitSimpleNode(nullptr, "plaintext=circle", "GraphRoot");
302*9880d681SAndroid Build Coastguard Worker     const SDNode *N = DAG->getRoot().getNode();
303*9880d681SAndroid Build Coastguard Worker     if (N && N->getNodeId() != -1)
304*9880d681SAndroid Build Coastguard Worker       GW.emitEdge(nullptr, -1, &SUnits[N->getNodeId()], -1,
305*9880d681SAndroid Build Coastguard Worker                   "color=blue,style=dashed");
306*9880d681SAndroid Build Coastguard Worker   }
307*9880d681SAndroid Build Coastguard Worker }
308