1 //===-- ScheduleDAGPrinter.cpp - Implement ScheduleDAG::viewGraph() -------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This implements the ScheduleDAG::viewGraph method.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "llvm/CodeGen/ScheduleDAG.h"
15 #include "llvm/ADT/DenseSet.h"
16 #include "llvm/ADT/StringExtras.h"
17 #include "llvm/CodeGen/MachineConstantPool.h"
18 #include "llvm/CodeGen/MachineFunction.h"
19 #include "llvm/CodeGen/MachineModuleInfo.h"
20 #include "llvm/IR/Constants.h"
21 #include "llvm/Support/Debug.h"
22 #include "llvm/Support/GraphWriter.h"
23 #include "llvm/Support/raw_ostream.h"
24 #include "llvm/Target/TargetRegisterInfo.h"
25 #include <fstream>
26 using namespace llvm;
27
28 namespace llvm {
29 template<>
30 struct DOTGraphTraits<ScheduleDAG*> : public DefaultDOTGraphTraits {
31
DOTGraphTraitsllvm::DOTGraphTraits32 DOTGraphTraits (bool isSimple=false) : DefaultDOTGraphTraits(isSimple) {}
33
getGraphNamellvm::DOTGraphTraits34 static std::string getGraphName(const ScheduleDAG *G) {
35 return G->MF.getName();
36 }
37
renderGraphFromBottomUpllvm::DOTGraphTraits38 static bool renderGraphFromBottomUp() {
39 return true;
40 }
41
isNodeHiddenllvm::DOTGraphTraits42 static bool isNodeHidden(const SUnit *Node) {
43 return (Node->NumPreds > 10 || Node->NumSuccs > 10);
44 }
45
getNodeIdentifierLabelllvm::DOTGraphTraits46 static std::string getNodeIdentifierLabel(const SUnit *Node,
47 const ScheduleDAG *Graph) {
48 std::string R;
49 raw_string_ostream OS(R);
50 OS << static_cast<const void *>(Node);
51 return R;
52 }
53
54 /// If you want to override the dot attributes printed for a particular
55 /// edge, override this method.
getEdgeAttributesllvm::DOTGraphTraits56 static std::string getEdgeAttributes(const SUnit *Node,
57 SUnitIterator EI,
58 const ScheduleDAG *Graph) {
59 if (EI.isArtificialDep())
60 return "color=cyan,style=dashed";
61 if (EI.isCtrlDep())
62 return "color=blue,style=dashed";
63 return "";
64 }
65
66
67 std::string getNodeLabel(const SUnit *Node, const ScheduleDAG *Graph);
getNodeAttributesllvm::DOTGraphTraits68 static std::string getNodeAttributes(const SUnit *N,
69 const ScheduleDAG *Graph) {
70 return "shape=Mrecord";
71 }
72
addCustomGraphFeaturesllvm::DOTGraphTraits73 static void addCustomGraphFeatures(ScheduleDAG *G,
74 GraphWriter<ScheduleDAG*> &GW) {
75 return G->addCustomGraphFeatures(GW);
76 }
77 };
78 }
79
getNodeLabel(const SUnit * SU,const ScheduleDAG * G)80 std::string DOTGraphTraits<ScheduleDAG*>::getNodeLabel(const SUnit *SU,
81 const ScheduleDAG *G) {
82 return G->getGraphNodeLabel(SU);
83 }
84
85 /// viewGraph - Pop up a ghostview window with the reachable parts of the DAG
86 /// rendered using 'dot'.
87 ///
viewGraph(const Twine & Name,const Twine & Title)88 void ScheduleDAG::viewGraph(const Twine &Name, const Twine &Title) {
89 // This code is only for debugging!
90 #ifndef NDEBUG
91 ViewGraph(this, Name, false, Title);
92 #else
93 errs() << "ScheduleDAG::viewGraph is only available in debug builds on "
94 << "systems with Graphviz or gv!\n";
95 #endif // NDEBUG
96 }
97
98 /// Out-of-line implementation with no arguments is handy for gdb.
viewGraph()99 void ScheduleDAG::viewGraph() {
100 viewGraph(getDAGName(), "Scheduling-Units Graph for " + getDAGName());
101 }
102