blob: ff2085aae8653126d77998e6fa131f96ea409193 [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
Chandler Carruthd04a8d42012-12-03 16:50:05 +000014#include "llvm/ADT/StringExtras.h"
Dan Gohman343f0c02008-11-19 23:18:57 +000015#include "llvm/CodeGen/MachineConstantPool.h"
16#include "llvm/CodeGen/MachineFunction.h"
Chandler Carruthe3e43d92017-06-06 11:49:48 +000017#include "llvm/CodeGen/ScheduleDAG.h"
David Blaikiee3a9b4c2017-11-17 01:07:10 +000018#include "llvm/CodeGen/TargetRegisterInfo.h"
Chandler Carruth0b8c9a82013-01-02 11:36:10 +000019#include "llvm/IR/Constants.h"
Dan Gohman343f0c02008-11-19 23:18:57 +000020#include "llvm/Support/Debug.h"
21#include "llvm/Support/GraphWriter.h"
22#include "llvm/Support/raw_ostream.h"
Dan Gohman343f0c02008-11-19 23:18:57 +000023using namespace llvm;
24
25namespace llvm {
26 template<>
27 struct DOTGraphTraits<ScheduleDAG*> : public DefaultDOTGraphTraits {
Tobias Grossera10d5982009-11-30 12:38:13 +000028
29 DOTGraphTraits (bool isSimple=false) : DefaultDOTGraphTraits(isSimple) {}
30
Dan Gohman343f0c02008-11-19 23:18:57 +000031 static std::string getGraphName(const ScheduleDAG *G) {
Craig Topper96601ca2012-08-22 06:07:19 +000032 return G->MF.getName();
Dan Gohman343f0c02008-11-19 23:18:57 +000033 }
34
35 static bool renderGraphFromBottomUp() {
36 return true;
37 }
Andrew Trickacddd492012-03-07 00:18:15 +000038
Andrew Trickc6ada8e2013-01-25 07:45:25 +000039 static bool isNodeHidden(const SUnit *Node) {
40 return (Node->NumPreds > 10 || Node->NumSuccs > 10);
41 }
42
James Y Knighta0e9c6f2015-10-27 23:09:03 +000043 static std::string getNodeIdentifierLabel(const SUnit *Node,
44 const ScheduleDAG *Graph) {
45 std::string R;
46 raw_string_ostream OS(R);
47 OS << static_cast<const void *>(Node);
48 return R;
Dan Gohman343f0c02008-11-19 23:18:57 +000049 }
Andrew Trickacddd492012-03-07 00:18:15 +000050
Dan Gohman343f0c02008-11-19 23:18:57 +000051 /// If you want to override the dot attributes printed for a particular
52 /// edge, override this method.
Dan Gohman3ee74492008-12-16 00:55:00 +000053 static std::string getEdgeAttributes(const SUnit *Node,
Tobias Grossera91f86c2011-02-27 04:11:03 +000054 SUnitIterator EI,
55 const ScheduleDAG *Graph) {
Dan Gohman98adea12008-11-21 02:18:56 +000056 if (EI.isArtificialDep())
Dan Gohman343f0c02008-11-19 23:18:57 +000057 return "color=cyan,style=dashed";
58 if (EI.isCtrlDep())
59 return "color=blue,style=dashed";
60 return "";
61 }
Andrew Trickacddd492012-03-07 00:18:15 +000062
Dan Gohman343f0c02008-11-19 23:18:57 +000063
Fangrui Song7d882862018-07-16 18:51:40 +000064 std::string getNodeLabel(const SUnit *SU, const ScheduleDAG *Graph);
Dan Gohman343f0c02008-11-19 23:18:57 +000065 static std::string getNodeAttributes(const SUnit *N,
66 const ScheduleDAG *Graph) {
67 return "shape=Mrecord";
68 }
69
70 static void addCustomGraphFeatures(ScheduleDAG *G,
71 GraphWriter<ScheduleDAG*> &GW) {
72 return G->addCustomGraphFeatures(GW);
73 }
74 };
Alexander Kornienkocd52a7a2015-06-23 09:49:53 +000075}
Dan Gohman343f0c02008-11-19 23:18:57 +000076
77std::string DOTGraphTraits<ScheduleDAG*>::getNodeLabel(const SUnit *SU,
Tobias Grosser56f4ef32009-11-30 12:38:47 +000078 const ScheduleDAG *G) {
Dan Gohman343f0c02008-11-19 23:18:57 +000079 return G->getGraphNodeLabel(SU);
80}
81
82/// viewGraph - Pop up a ghostview window with the reachable parts of the DAG
83/// rendered using 'dot'.
84///
Andrew Trick56b94c52012-03-07 00:18:22 +000085void ScheduleDAG::viewGraph(const Twine &Name, const Twine &Title) {
86 // This code is only for debugging!
Dan Gohman343f0c02008-11-19 23:18:57 +000087#ifndef NDEBUG
Andrew Trick56b94c52012-03-07 00:18:22 +000088 ViewGraph(this, Name, false, Title);
Dan Gohman343f0c02008-11-19 23:18:57 +000089#else
Daniel Dunbar43ed2672009-08-23 08:50:52 +000090 errs() << "ScheduleDAG::viewGraph is only available in debug builds on "
91 << "systems with Graphviz or gv!\n";
Dan Gohman343f0c02008-11-19 23:18:57 +000092#endif // NDEBUG
93}
Andrew Trick56b94c52012-03-07 00:18:22 +000094
95/// Out-of-line implementation with no arguments is handy for gdb.
96void ScheduleDAG::viewGraph() {
97 viewGraph(getDAGName(), "Scheduling-Units Graph for " + getDAGName());
98}