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/StringExtras.h"
16 #include "llvm/CodeGen/MachineConstantPool.h"
17 #include "llvm/CodeGen/MachineFunction.h"
18 #include "llvm/CodeGen/MachineModuleInfo.h"
19 #include "llvm/IR/Constants.h"
20 #include "llvm/Support/Debug.h"
21 #include "llvm/Support/GraphWriter.h"
22 #include "llvm/Support/raw_ostream.h"
23 #include "llvm/Target/TargetRegisterInfo.h"
24 #include <fstream>
25 using namespace llvm;
26
27 namespace llvm {
28 template<>
29 struct DOTGraphTraits<ScheduleDAG*> : public DefaultDOTGraphTraits {
30
DOTGraphTraitsllvm::DOTGraphTraits31 DOTGraphTraits (bool isSimple=false) : DefaultDOTGraphTraits(isSimple) {}
32
getGraphNamellvm::DOTGraphTraits33 static std::string getGraphName(const ScheduleDAG *G) {
34 return G->MF.getName();
35 }
36
renderGraphFromBottomUpllvm::DOTGraphTraits37 static bool renderGraphFromBottomUp() {
38 return true;
39 }
40
isNodeHiddenllvm::DOTGraphTraits41 static bool isNodeHidden(const SUnit *Node) {
42 return (Node->NumPreds > 10 || Node->NumSuccs > 10);
43 }
44
getNodeIdentifierLabelllvm::DOTGraphTraits45 static std::string getNodeIdentifierLabel(const SUnit *Node,
46 const ScheduleDAG *Graph) {
47 std::string R;
48 raw_string_ostream OS(R);
49 OS << static_cast<const void *>(Node);
50 return R;
51 }
52
53 /// If you want to override the dot attributes printed for a particular
54 /// edge, override this method.
getEdgeAttributesllvm::DOTGraphTraits55 static std::string getEdgeAttributes(const SUnit *Node,
56 SUnitIterator EI,
57 const ScheduleDAG *Graph) {
58 if (EI.isArtificialDep())
59 return "color=cyan,style=dashed";
60 if (EI.isCtrlDep())
61 return "color=blue,style=dashed";
62 return "";
63 }
64
65
66 std::string getNodeLabel(const SUnit *Node, const ScheduleDAG *Graph);
getNodeAttributesllvm::DOTGraphTraits67 static std::string getNodeAttributes(const SUnit *N,
68 const ScheduleDAG *Graph) {
69 return "shape=Mrecord";
70 }
71
addCustomGraphFeaturesllvm::DOTGraphTraits72 static void addCustomGraphFeatures(ScheduleDAG *G,
73 GraphWriter<ScheduleDAG*> &GW) {
74 return G->addCustomGraphFeatures(GW);
75 }
76 };
77 }
78
getNodeLabel(const SUnit * SU,const ScheduleDAG * G)79 std::string DOTGraphTraits<ScheduleDAG*>::getNodeLabel(const SUnit *SU,
80 const ScheduleDAG *G) {
81 return G->getGraphNodeLabel(SU);
82 }
83
84 /// viewGraph - Pop up a ghostview window with the reachable parts of the DAG
85 /// rendered using 'dot'.
86 ///
viewGraph(const Twine & Name,const Twine & Title)87 void ScheduleDAG::viewGraph(const Twine &Name, const Twine &Title) {
88 // This code is only for debugging!
89 #ifndef NDEBUG
90 ViewGraph(this, Name, false, Title);
91 #else
92 errs() << "ScheduleDAG::viewGraph is only available in debug builds on "
93 << "systems with Graphviz or gv!\n";
94 #endif // NDEBUG
95 }
96
97 /// Out-of-line implementation with no arguments is handy for gdb.
viewGraph()98 void ScheduleDAG::viewGraph() {
99 viewGraph(getDAGName(), "Scheduling-Units Graph for " + getDAGName());
100 }
101