1 //===-- ScheduleDAGPrinter.cpp - Implement ScheduleDAG::viewGraph() -------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This implements the ScheduleDAG::viewGraph method.
12 //===----------------------------------------------------------------------===//
14 #include "llvm/Constants.h"
15 #include "llvm/Function.h"
16 #include "llvm/Assembly/Writer.h"
17 #include "llvm/CodeGen/ScheduleDAG.h"
18 #include "llvm/CodeGen/MachineConstantPool.h"
19 #include "llvm/CodeGen/MachineFunction.h"
20 #include "llvm/CodeGen/MachineModuleInfo.h"
21 #include "llvm/CodeGen/PseudoSourceValue.h"
22 #include "llvm/Target/TargetRegisterInfo.h"
23 #include "llvm/Target/TargetMachine.h"
24 #include "llvm/Support/Debug.h"
25 #include "llvm/Support/GraphWriter.h"
26 #include "llvm/Support/raw_ostream.h"
27 #include "llvm/ADT/DenseSet.h"
28 #include "llvm/ADT/StringExtras.h"
29 #include "llvm/Config/config.h"
35 struct DOTGraphTraits
<ScheduleDAG
*> : public DefaultDOTGraphTraits
{
36 static std::string
getGraphName(const ScheduleDAG
*G
) {
37 return G
->MF
.getFunction()->getName();
40 static bool renderGraphFromBottomUp() {
44 static bool hasNodeAddressLabel(const SUnit
*Node
,
45 const ScheduleDAG
*Graph
) {
49 /// If you want to override the dot attributes printed for a particular
50 /// edge, override this method.
51 static std::string
getEdgeAttributes(const SUnit
*Node
,
53 if (EI
.isArtificialDep())
54 return "color=cyan,style=dashed";
56 return "color=blue,style=dashed";
61 static std::string
getNodeLabel(const SUnit
*Node
,
62 const ScheduleDAG
*Graph
,
64 static std::string
getNodeAttributes(const SUnit
*N
,
65 const ScheduleDAG
*Graph
) {
66 return "shape=Mrecord";
69 static void addCustomGraphFeatures(ScheduleDAG
*G
,
70 GraphWriter
<ScheduleDAG
*> &GW
) {
71 return G
->addCustomGraphFeatures(GW
);
76 std::string DOTGraphTraits
<ScheduleDAG
*>::getNodeLabel(const SUnit
*SU
,
79 return G
->getGraphNodeLabel(SU
);
82 /// viewGraph - Pop up a ghostview window with the reachable parts of the DAG
83 /// rendered using 'dot'.
85 void ScheduleDAG::viewGraph() {
86 // This code is only for debugging!
88 if (BB
->getBasicBlock())
89 ViewGraph(this, "dag." + MF
.getFunction()->getNameStr(), false,
90 "Scheduling-Units Graph for " + MF
.getFunction()->getNameStr() +
91 ":" + BB
->getBasicBlock()->getNameStr());
93 ViewGraph(this, "dag." + MF
.getFunction()->getNameStr(), false,
94 "Scheduling-Units Graph for " + MF
.getFunction()->getNameStr());
96 errs() << "ScheduleDAG::viewGraph is only available in debug builds on "
97 << "systems with Graphviz or gv!\n";