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/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/TargetMachine.h"
25 #include "llvm/Target/TargetRegisterInfo.h"
31 struct DOTGraphTraits<ScheduleDAG*> : public DefaultDOTGraphTraits {
33 DOTGraphTraits (bool isSimple=false) : DefaultDOTGraphTraits(isSimple) {}
35 static std::string getGraphName(const ScheduleDAG *G) {
36 return G->MF.getName();
39 static bool renderGraphFromBottomUp() {
43 static bool isNodeHidden(const SUnit *Node) {
44 return (Node->NumPreds > 10 || Node->NumSuccs > 10);
47 static bool hasNodeAddressLabel(const SUnit *Node,
48 const ScheduleDAG *Graph) {
52 /// If you want to override the dot attributes printed for a particular
53 /// edge, override this method.
54 static std::string getEdgeAttributes(const SUnit *Node,
56 const ScheduleDAG *Graph) {
57 if (EI.isArtificialDep())
58 return "color=cyan,style=dashed";
60 return "color=blue,style=dashed";
65 std::string getNodeLabel(const SUnit *Node, const ScheduleDAG *Graph);
66 static std::string getNodeAttributes(const SUnit *N,
67 const ScheduleDAG *Graph) {
68 return "shape=Mrecord";
71 static void addCustomGraphFeatures(ScheduleDAG *G,
72 GraphWriter<ScheduleDAG*> &GW) {
73 return G->addCustomGraphFeatures(GW);
78 std::string DOTGraphTraits<ScheduleDAG*>::getNodeLabel(const SUnit *SU,
79 const ScheduleDAG *G) {
80 return G->getGraphNodeLabel(SU);
83 /// viewGraph - Pop up a ghostview window with the reachable parts of the DAG
84 /// rendered using 'dot'.
86 void ScheduleDAG::viewGraph(const Twine &Name, const Twine &Title) {
87 // This code is only for debugging!
89 ViewGraph(this, Name, false, Title);
91 errs() << "ScheduleDAG::viewGraph is only available in debug builds on "
92 << "systems with Graphviz or gv!\n";
96 /// Out-of-line implementation with no arguments is handy for gdb.
97 void ScheduleDAG::viewGraph() {
98 viewGraph(getDAGName(), "Scheduling-Units Graph for " + getDAGName());