blob: f59c6cfd828462cb7cf7c1f9cc359fcae19320ce [file] [log] [blame]
Dan Gohman60cb69e2008-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 Gohman60cb69e2008-11-19 23:18:57 +000014#include "llvm/CodeGen/ScheduleDAG.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000015#include "llvm/ADT/DenseSet.h"
16#include "llvm/ADT/StringExtras.h"
Dan Gohman60cb69e2008-11-19 23:18:57 +000017#include "llvm/CodeGen/MachineConstantPool.h"
18#include "llvm/CodeGen/MachineFunction.h"
19#include "llvm/CodeGen/MachineModuleInfo.h"
Chandler Carruth9fb823b2013-01-02 11:36:10 +000020#include "llvm/IR/Constants.h"
Dan Gohman60cb69e2008-11-19 23:18:57 +000021#include "llvm/Support/Debug.h"
22#include "llvm/Support/GraphWriter.h"
23#include "llvm/Support/raw_ostream.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000024#include "llvm/Target/TargetMachine.h"
25#include "llvm/Target/TargetRegisterInfo.h"
Dan Gohman60cb69e2008-11-19 23:18:57 +000026#include <fstream>
27using namespace llvm;
28
29namespace llvm {
30 template<>
31 struct DOTGraphTraits<ScheduleDAG*> : public DefaultDOTGraphTraits {
Tobias Grosser90d33402009-11-30 12:38:13 +000032
33 DOTGraphTraits (bool isSimple=false) : DefaultDOTGraphTraits(isSimple) {}
34
Dan Gohman60cb69e2008-11-19 23:18:57 +000035 static std::string getGraphName(const ScheduleDAG *G) {
Craig Toppera538d832012-08-22 06:07:19 +000036 return G->MF.getName();
Dan Gohman60cb69e2008-11-19 23:18:57 +000037 }
38
39 static bool renderGraphFromBottomUp() {
40 return true;
41 }
Andrew Trick5297d8d2012-03-07 00:18:15 +000042
Andrew Trickb36388a2013-01-25 07:45:25 +000043 static bool isNodeHidden(const SUnit *Node) {
44 return (Node->NumPreds > 10 || Node->NumSuccs > 10);
45 }
46
Dan Gohman60cb69e2008-11-19 23:18:57 +000047 static bool hasNodeAddressLabel(const SUnit *Node,
48 const ScheduleDAG *Graph) {
49 return true;
50 }
Andrew Trick5297d8d2012-03-07 00:18:15 +000051
Dan Gohman60cb69e2008-11-19 23:18:57 +000052 /// If you want to override the dot attributes printed for a particular
53 /// edge, override this method.
Dan Gohmancb6accf2008-12-16 00:55:00 +000054 static std::string getEdgeAttributes(const SUnit *Node,
Tobias Grosser3ac86892011-02-27 04:11:03 +000055 SUnitIterator EI,
56 const ScheduleDAG *Graph) {
Dan Gohman67b35bd2008-11-21 02:18:56 +000057 if (EI.isArtificialDep())
Dan Gohman60cb69e2008-11-19 23:18:57 +000058 return "color=cyan,style=dashed";
59 if (EI.isCtrlDep())
60 return "color=blue,style=dashed";
61 return "";
62 }
Andrew Trick5297d8d2012-03-07 00:18:15 +000063
Dan Gohman60cb69e2008-11-19 23:18:57 +000064
Tobias Grosserdd7f2e72009-11-30 12:38:47 +000065 std::string getNodeLabel(const SUnit *Node, const ScheduleDAG *Graph);
Dan Gohman60cb69e2008-11-19 23:18:57 +000066 static std::string getNodeAttributes(const SUnit *N,
67 const ScheduleDAG *Graph) {
68 return "shape=Mrecord";
69 }
70
71 static void addCustomGraphFeatures(ScheduleDAG *G,
72 GraphWriter<ScheduleDAG*> &GW) {
73 return G->addCustomGraphFeatures(GW);
74 }
75 };
76}
77
78std::string DOTGraphTraits<ScheduleDAG*>::getNodeLabel(const SUnit *SU,
Tobias Grosserdd7f2e72009-11-30 12:38:47 +000079 const ScheduleDAG *G) {
Dan Gohman60cb69e2008-11-19 23:18:57 +000080 return G->getGraphNodeLabel(SU);
81}
82
83/// viewGraph - Pop up a ghostview window with the reachable parts of the DAG
84/// rendered using 'dot'.
85///
Andrew Trick1b2324d2012-03-07 00:18:22 +000086void ScheduleDAG::viewGraph(const Twine &Name, const Twine &Title) {
87 // This code is only for debugging!
Dan Gohman60cb69e2008-11-19 23:18:57 +000088#ifndef NDEBUG
Andrew Trick1b2324d2012-03-07 00:18:22 +000089 ViewGraph(this, Name, false, Title);
Dan Gohman60cb69e2008-11-19 23:18:57 +000090#else
Daniel Dunbar34ee2032009-08-23 08:50:52 +000091 errs() << "ScheduleDAG::viewGraph is only available in debug builds on "
92 << "systems with Graphviz or gv!\n";
Dan Gohman60cb69e2008-11-19 23:18:57 +000093#endif // NDEBUG
94}
Andrew Trick1b2324d2012-03-07 00:18:22 +000095
96/// Out-of-line implementation with no arguments is handy for gdb.
97void ScheduleDAG::viewGraph() {
98 viewGraph(getDAGName(), "Scheduling-Units Graph for " + getDAGName());
99}