blob: 594c24d11d1ee499e4a4cd65e6b06d8f0094c536 [file] [log] [blame]
Dan Gohman343f0c02008-11-19 23:18:57 +00001//===-- 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/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"
30#include <fstream>
31using namespace llvm;
32
33namespace llvm {
34 template<>
35 struct DOTGraphTraits<ScheduleDAG*> : public DefaultDOTGraphTraits {
36 static std::string getGraphName(const ScheduleDAG *G) {
Dan Gohman79ce2762009-01-15 19:20:50 +000037 return G->MF.getFunction()->getName();
Dan Gohman343f0c02008-11-19 23:18:57 +000038 }
39
40 static bool renderGraphFromBottomUp() {
41 return true;
42 }
43
44 static bool hasNodeAddressLabel(const SUnit *Node,
45 const ScheduleDAG *Graph) {
46 return true;
47 }
48
49 /// If you want to override the dot attributes printed for a particular
50 /// edge, override this method.
Dan Gohman3ee74492008-12-16 00:55:00 +000051 static std::string getEdgeAttributes(const SUnit *Node,
52 SUnitIterator EI) {
Dan Gohman98adea12008-11-21 02:18:56 +000053 if (EI.isArtificialDep())
Dan Gohman343f0c02008-11-19 23:18:57 +000054 return "color=cyan,style=dashed";
55 if (EI.isCtrlDep())
56 return "color=blue,style=dashed";
57 return "";
58 }
59
60
61 static std::string getNodeLabel(const SUnit *Node,
62 const ScheduleDAG *Graph);
63 static std::string getNodeAttributes(const SUnit *N,
64 const ScheduleDAG *Graph) {
65 return "shape=Mrecord";
66 }
67
68 static void addCustomGraphFeatures(ScheduleDAG *G,
69 GraphWriter<ScheduleDAG*> &GW) {
70 return G->addCustomGraphFeatures(GW);
71 }
72 };
73}
74
75std::string DOTGraphTraits<ScheduleDAG*>::getNodeLabel(const SUnit *SU,
76 const ScheduleDAG *G) {
77 return G->getGraphNodeLabel(SU);
78}
79
80/// viewGraph - Pop up a ghostview window with the reachable parts of the DAG
81/// rendered using 'dot'.
82///
83void ScheduleDAG::viewGraph() {
84// This code is only for debugging!
85#ifndef NDEBUG
Evan Chengf412f7c2009-02-11 23:42:39 +000086 if (BB->getBasicBlock())
87 ViewGraph(this, "dag." + MF.getFunction()->getName(),
88 "Scheduling-Units Graph for " + MF.getFunction()->getName() + ':' +
89 BB->getBasicBlock()->getName());
90 else
91 ViewGraph(this, "dag." + MF.getFunction()->getName(),
92 "Scheduling-Units Graph for " + MF.getFunction()->getName());
Dan Gohman343f0c02008-11-19 23:18:57 +000093#else
94 cerr << "ScheduleDAG::viewGraph is only available in debug builds on "
95 << "systems with Graphviz or gv!\n";
96#endif // NDEBUG
97}