blob: 38feee95a58ef8671b70d80013bf3bcf249a62d9 [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"
Dan Gohman343f0c02008-11-19 23:18:57 +000028#include <fstream>
29using namespace llvm;
30
31namespace llvm {
32 template<>
33 struct DOTGraphTraits<ScheduleDAG*> : public DefaultDOTGraphTraits {
Tobias Grossera10d5982009-11-30 12:38:13 +000034
35 DOTGraphTraits (bool isSimple=false) : DefaultDOTGraphTraits(isSimple) {}
36
Dan Gohman343f0c02008-11-19 23:18:57 +000037 static std::string getGraphName(const ScheduleDAG *G) {
Dan Gohman79ce2762009-01-15 19:20:50 +000038 return G->MF.getFunction()->getName();
Dan Gohman343f0c02008-11-19 23:18:57 +000039 }
40
41 static bool renderGraphFromBottomUp() {
42 return true;
43 }
Andrew Trickacddd492012-03-07 00:18:15 +000044
Dan Gohman343f0c02008-11-19 23:18:57 +000045 static bool hasNodeAddressLabel(const SUnit *Node,
46 const ScheduleDAG *Graph) {
47 return true;
48 }
Andrew Trickacddd492012-03-07 00:18:15 +000049
Dan Gohman343f0c02008-11-19 23:18:57 +000050 /// If you want to override the dot attributes printed for a particular
51 /// edge, override this method.
Dan Gohman3ee74492008-12-16 00:55:00 +000052 static std::string getEdgeAttributes(const SUnit *Node,
Tobias Grossera91f86c2011-02-27 04:11:03 +000053 SUnitIterator EI,
54 const ScheduleDAG *Graph) {
Dan Gohman98adea12008-11-21 02:18:56 +000055 if (EI.isArtificialDep())
Dan Gohman343f0c02008-11-19 23:18:57 +000056 return "color=cyan,style=dashed";
57 if (EI.isCtrlDep())
58 return "color=blue,style=dashed";
59 return "";
60 }
Andrew Trickacddd492012-03-07 00:18:15 +000061
Dan Gohman343f0c02008-11-19 23:18:57 +000062
Tobias Grosser56f4ef32009-11-30 12:38:47 +000063 std::string getNodeLabel(const SUnit *Node, const ScheduleDAG *Graph);
Dan Gohman343f0c02008-11-19 23:18:57 +000064 static std::string getNodeAttributes(const SUnit *N,
65 const ScheduleDAG *Graph) {
66 return "shape=Mrecord";
67 }
68
69 static void addCustomGraphFeatures(ScheduleDAG *G,
70 GraphWriter<ScheduleDAG*> &GW) {
71 return G->addCustomGraphFeatures(GW);
72 }
73 };
74}
75
76std::string DOTGraphTraits<ScheduleDAG*>::getNodeLabel(const SUnit *SU,
Tobias Grosser56f4ef32009-11-30 12:38:47 +000077 const ScheduleDAG *G) {
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///
Andrew Trick56b94c52012-03-07 00:18:22 +000084void ScheduleDAG::viewGraph(const Twine &Name, const Twine &Title) {
85 // This code is only for debugging!
Dan Gohman343f0c02008-11-19 23:18:57 +000086#ifndef NDEBUG
Andrew Trick56b94c52012-03-07 00:18:22 +000087 ViewGraph(this, Name, false, Title);
Dan Gohman343f0c02008-11-19 23:18:57 +000088#else
Daniel Dunbar43ed2672009-08-23 08:50:52 +000089 errs() << "ScheduleDAG::viewGraph is only available in debug builds on "
90 << "systems with Graphviz or gv!\n";
Dan Gohman343f0c02008-11-19 23:18:57 +000091#endif // NDEBUG
92}
Andrew Trick56b94c52012-03-07 00:18:22 +000093
94/// Out-of-line implementation with no arguments is handy for gdb.
95void ScheduleDAG::viewGraph() {
96 viewGraph(getDAGName(), "Scheduling-Units Graph for " + getDAGName());
97}