blob: 950a62fac42a0adf66b34a7f49b293c42355261f [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
Dan Gohman343f0c02008-11-19 23:18:57 +000014#include "llvm/CodeGen/ScheduleDAG.h"
Chandler Carruthd04a8d42012-12-03 16:50:05 +000015#include "llvm/ADT/DenseSet.h"
16#include "llvm/ADT/StringExtras.h"
17#include "llvm/Assembly/Writer.h"
Dan Gohman343f0c02008-11-19 23:18:57 +000018#include "llvm/CodeGen/MachineConstantPool.h"
19#include "llvm/CodeGen/MachineFunction.h"
20#include "llvm/CodeGen/MachineModuleInfo.h"
Chandler Carruthd04a8d42012-12-03 16:50:05 +000021#include "llvm/Constants.h"
Dan Gohman343f0c02008-11-19 23:18:57 +000022#include "llvm/Support/Debug.h"
23#include "llvm/Support/GraphWriter.h"
24#include "llvm/Support/raw_ostream.h"
Chandler Carruthd04a8d42012-12-03 16:50:05 +000025#include "llvm/Target/TargetMachine.h"
26#include "llvm/Target/TargetRegisterInfo.h"
Dan Gohman343f0c02008-11-19 23:18:57 +000027#include <fstream>
28using namespace llvm;
29
30namespace llvm {
31 template<>
32 struct DOTGraphTraits<ScheduleDAG*> : public DefaultDOTGraphTraits {
Tobias Grossera10d5982009-11-30 12:38:13 +000033
34 DOTGraphTraits (bool isSimple=false) : DefaultDOTGraphTraits(isSimple) {}
35
Dan Gohman343f0c02008-11-19 23:18:57 +000036 static std::string getGraphName(const ScheduleDAG *G) {
Craig Topper96601ca2012-08-22 06:07:19 +000037 return G->MF.getName();
Dan Gohman343f0c02008-11-19 23:18:57 +000038 }
39
40 static bool renderGraphFromBottomUp() {
41 return true;
42 }
Andrew Trickacddd492012-03-07 00:18:15 +000043
Dan Gohman343f0c02008-11-19 23:18:57 +000044 static bool hasNodeAddressLabel(const SUnit *Node,
45 const ScheduleDAG *Graph) {
46 return true;
47 }
Andrew Trickacddd492012-03-07 00:18:15 +000048
Dan Gohman343f0c02008-11-19 23:18:57 +000049 /// 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,
Tobias Grossera91f86c2011-02-27 04:11:03 +000052 SUnitIterator EI,
53 const ScheduleDAG *Graph) {
Dan Gohman98adea12008-11-21 02:18:56 +000054 if (EI.isArtificialDep())
Dan Gohman343f0c02008-11-19 23:18:57 +000055 return "color=cyan,style=dashed";
56 if (EI.isCtrlDep())
57 return "color=blue,style=dashed";
58 return "";
59 }
Andrew Trickacddd492012-03-07 00:18:15 +000060
Dan Gohman343f0c02008-11-19 23:18:57 +000061
Tobias Grosser56f4ef32009-11-30 12:38:47 +000062 std::string getNodeLabel(const SUnit *Node, const ScheduleDAG *Graph);
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,
Tobias Grosser56f4ef32009-11-30 12:38:47 +000076 const ScheduleDAG *G) {
Dan Gohman343f0c02008-11-19 23:18:57 +000077 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///
Andrew Trick56b94c52012-03-07 00:18:22 +000083void ScheduleDAG::viewGraph(const Twine &Name, const Twine &Title) {
84 // This code is only for debugging!
Dan Gohman343f0c02008-11-19 23:18:57 +000085#ifndef NDEBUG
Andrew Trick56b94c52012-03-07 00:18:22 +000086 ViewGraph(this, Name, false, Title);
Dan Gohman343f0c02008-11-19 23:18:57 +000087#else
Daniel Dunbar43ed2672009-08-23 08:50:52 +000088 errs() << "ScheduleDAG::viewGraph is only available in debug builds on "
89 << "systems with Graphviz or gv!\n";
Dan Gohman343f0c02008-11-19 23:18:57 +000090#endif // NDEBUG
91}
Andrew Trick56b94c52012-03-07 00:18:22 +000092
93/// Out-of-line implementation with no arguments is handy for gdb.
94void ScheduleDAG::viewGraph() {
95 viewGraph(getDAGName(), "Scheduling-Units Graph for " + getDAGName());
96}