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/Target/TargetRegisterInfo.h"
22 #include "llvm/Target/TargetMachine.h"
23 #include "llvm/Support/Debug.h"
24 #include "llvm/Support/GraphWriter.h"
25 #include "llvm/Support/raw_ostream.h"
26 #include "llvm/ADT/DenseSet.h"
27 #include "llvm/ADT/StringExtras.h"
33 struct DOTGraphTraits<ScheduleDAG*> : public DefaultDOTGraphTraits {
35 DOTGraphTraits (bool isSimple=false) : DefaultDOTGraphTraits(isSimple) {}
37 static std::string getGraphName(const ScheduleDAG *G) {
38 return G->MF.getFunction()->getName();
41 static bool renderGraphFromBottomUp() {
45 static bool hasNodeAddressLabel(const SUnit *Node,
46 const ScheduleDAG *Graph) {
50 /// If you want to override the dot attributes printed for a particular
51 /// edge, override this method.
52 static std::string getEdgeAttributes(const SUnit *Node,
54 const ScheduleDAG *Graph) {
55 if (EI.isArtificialDep())
56 return "color=cyan,style=dashed";
58 return "color=blue,style=dashed";
63 std::string getNodeLabel(const SUnit *Node, 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,
77 const ScheduleDAG *G) {
78 return G->getGraphNodeLabel(SU);
81 /// viewGraph - Pop up a ghostview window with the reachable parts of the DAG
82 /// rendered using 'dot'.
84 void ScheduleDAG::viewGraph() {
85 // This code is only for debugging!
87 if (BB->getBasicBlock())
88 ViewGraph(this, "dag." + MF.getFunction()->getName(), false,
89 "Scheduling-Units Graph for " + MF.getFunction()->getName() +
90 ":" + BB->getBasicBlock()->getName());
92 ViewGraph(this, "dag." + MF.getFunction()->getName(), false,
93 "Scheduling-Units Graph for " + MF.getFunction()->getName());
95 errs() << "ScheduleDAG::viewGraph is only available in debug builds on "
96 << "systems with Graphviz or gv!\n";