blob: 6c753bbb8faa01fc32d0910db5b6a7675e955b6b [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
Chandler Carruthed0881b2012-12-03 16:50:05 +000014#include "llvm/ADT/StringExtras.h"
Dan Gohman60cb69e2008-11-19 23:18:57 +000015#include "llvm/CodeGen/MachineConstantPool.h"
16#include "llvm/CodeGen/MachineFunction.h"
17#include "llvm/CodeGen/MachineModuleInfo.h"
Chandler Carruth6bda14b2017-06-06 11:49:48 +000018#include "llvm/CodeGen/ScheduleDAG.h"
David Blaikieb3bde2e2017-11-17 01:07:10 +000019#include "llvm/CodeGen/TargetRegisterInfo.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"
Dan Gohman60cb69e2008-11-19 23:18:57 +000024#include <fstream>
25using namespace llvm;
26
27namespace llvm {
28 template<>
29 struct DOTGraphTraits<ScheduleDAG*> : public DefaultDOTGraphTraits {
Tobias Grosser90d33402009-11-30 12:38:13 +000030
31 DOTGraphTraits (bool isSimple=false) : DefaultDOTGraphTraits(isSimple) {}
32
Dan Gohman60cb69e2008-11-19 23:18:57 +000033 static std::string getGraphName(const ScheduleDAG *G) {
Craig Toppera538d832012-08-22 06:07:19 +000034 return G->MF.getName();
Dan Gohman60cb69e2008-11-19 23:18:57 +000035 }
36
37 static bool renderGraphFromBottomUp() {
38 return true;
39 }
Andrew Trick5297d8d2012-03-07 00:18:15 +000040
Andrew Trickb36388a2013-01-25 07:45:25 +000041 static bool isNodeHidden(const SUnit *Node) {
42 return (Node->NumPreds > 10 || Node->NumSuccs > 10);
43 }
44
James Y Knight14eedd12015-10-27 23:09:03 +000045 static std::string getNodeIdentifierLabel(const SUnit *Node,
46 const ScheduleDAG *Graph) {
47 std::string R;
48 raw_string_ostream OS(R);
49 OS << static_cast<const void *>(Node);
50 return R;
Dan Gohman60cb69e2008-11-19 23:18:57 +000051 }
Andrew Trick5297d8d2012-03-07 00:18:15 +000052
Dan Gohman60cb69e2008-11-19 23:18:57 +000053 /// If you want to override the dot attributes printed for a particular
54 /// edge, override this method.
Dan Gohmancb6accf2008-12-16 00:55:00 +000055 static std::string getEdgeAttributes(const SUnit *Node,
Tobias Grosser3ac86892011-02-27 04:11:03 +000056 SUnitIterator EI,
57 const ScheduleDAG *Graph) {
Dan Gohman67b35bd2008-11-21 02:18:56 +000058 if (EI.isArtificialDep())
Dan Gohman60cb69e2008-11-19 23:18:57 +000059 return "color=cyan,style=dashed";
60 if (EI.isCtrlDep())
61 return "color=blue,style=dashed";
62 return "";
63 }
Andrew Trick5297d8d2012-03-07 00:18:15 +000064
Dan Gohman60cb69e2008-11-19 23:18:57 +000065
Tobias Grosserdd7f2e72009-11-30 12:38:47 +000066 std::string getNodeLabel(const SUnit *Node, const ScheduleDAG *Graph);
Dan Gohman60cb69e2008-11-19 23:18:57 +000067 static std::string getNodeAttributes(const SUnit *N,
68 const ScheduleDAG *Graph) {
69 return "shape=Mrecord";
70 }
71
72 static void addCustomGraphFeatures(ScheduleDAG *G,
73 GraphWriter<ScheduleDAG*> &GW) {
74 return G->addCustomGraphFeatures(GW);
75 }
76 };
Alexander Kornienkof00654e2015-06-23 09:49:53 +000077}
Dan Gohman60cb69e2008-11-19 23:18:57 +000078
79std::string DOTGraphTraits<ScheduleDAG*>::getNodeLabel(const SUnit *SU,
Tobias Grosserdd7f2e72009-11-30 12:38:47 +000080 const ScheduleDAG *G) {
Dan Gohman60cb69e2008-11-19 23:18:57 +000081 return G->getGraphNodeLabel(SU);
82}
83
84/// viewGraph - Pop up a ghostview window with the reachable parts of the DAG
85/// rendered using 'dot'.
86///
Andrew Trick1b2324d2012-03-07 00:18:22 +000087void ScheduleDAG::viewGraph(const Twine &Name, const Twine &Title) {
88 // This code is only for debugging!
Dan Gohman60cb69e2008-11-19 23:18:57 +000089#ifndef NDEBUG
Andrew Trick1b2324d2012-03-07 00:18:22 +000090 ViewGraph(this, Name, false, Title);
Dan Gohman60cb69e2008-11-19 23:18:57 +000091#else
Daniel Dunbar34ee2032009-08-23 08:50:52 +000092 errs() << "ScheduleDAG::viewGraph is only available in debug builds on "
93 << "systems with Graphviz or gv!\n";
Dan Gohman60cb69e2008-11-19 23:18:57 +000094#endif // NDEBUG
95}
Andrew Trick1b2324d2012-03-07 00:18:22 +000096
97/// Out-of-line implementation with no arguments is handy for gdb.
98void ScheduleDAG::viewGraph() {
99 viewGraph(getDAGName(), "Scheduling-Units Graph for " + getDAGName());
100}