blob: 4851d496bdbd3a4ef76af79be988408a7a3351bf [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"
Dan Gohman343f0c02008-11-19 23:18:57 +000021#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"
28#include "llvm/Config/config.h"
29#include <fstream>
30using namespace llvm;
31
32namespace llvm {
33 template<>
34 struct DOTGraphTraits<ScheduleDAG*> : public DefaultDOTGraphTraits {
35 static std::string getGraphName(const ScheduleDAG *G) {
Dan Gohman79ce2762009-01-15 19:20:50 +000036 return G->MF.getFunction()->getName();
Dan Gohman343f0c02008-11-19 23:18:57 +000037 }
38
39 static bool renderGraphFromBottomUp() {
40 return true;
41 }
42
43 static bool hasNodeAddressLabel(const SUnit *Node,
44 const ScheduleDAG *Graph) {
45 return true;
46 }
47
48 /// If you want to override the dot attributes printed for a particular
49 /// edge, override this method.
Dan Gohman3ee74492008-12-16 00:55:00 +000050 static std::string getEdgeAttributes(const SUnit *Node,
51 SUnitIterator EI) {
Dan Gohman98adea12008-11-21 02:18:56 +000052 if (EI.isArtificialDep())
Dan Gohman343f0c02008-11-19 23:18:57 +000053 return "color=cyan,style=dashed";
54 if (EI.isCtrlDep())
55 return "color=blue,style=dashed";
56 return "";
57 }
58
59
60 static std::string getNodeLabel(const SUnit *Node,
Owen Anderson8cbc94a2009-06-24 17:37:09 +000061 const ScheduleDAG *Graph,
62 bool ShortNames);
Dan Gohman343f0c02008-11-19 23:18:57 +000063 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,
Owen Anderson8cbc94a2009-06-24 17:37:09 +000076 const ScheduleDAG *G,
77 bool ShortNames) {
Dan Gohman343f0c02008-11-19 23:18:57 +000078 return G->getGraphNodeLabel(SU);
79}
80
81/// viewGraph - Pop up a ghostview window with the reachable parts of the DAG
82/// rendered using 'dot'.
83///
84void ScheduleDAG::viewGraph() {
85// This code is only for debugging!
86#ifndef NDEBUG
Evan Chengf412f7c2009-02-11 23:42:39 +000087 if (BB->getBasicBlock())
Daniel Dunbarf6ccee52009-07-24 08:24:36 +000088 ViewGraph(this, "dag." + MF.getFunction()->getNameStr(), false,
89 "Scheduling-Units Graph for " + MF.getFunction()->getNameStr() +
90 ":" + BB->getBasicBlock()->getNameStr());
Evan Chengf412f7c2009-02-11 23:42:39 +000091 else
Daniel Dunbarf6ccee52009-07-24 08:24:36 +000092 ViewGraph(this, "dag." + MF.getFunction()->getNameStr(), false,
93 "Scheduling-Units Graph for " + MF.getFunction()->getNameStr());
Dan Gohman343f0c02008-11-19 23:18:57 +000094#else
Daniel Dunbar43ed2672009-08-23 08:50:52 +000095 errs() << "ScheduleDAG::viewGraph is only available in debug builds on "
96 << "systems with Graphviz or gv!\n";
Dan Gohman343f0c02008-11-19 23:18:57 +000097#endif // NDEBUG
98}