blob: 8d04711f07c64962799344d9698048a15e89e268 [file] [log] [blame]
Dan Gohman60cb69e2008-11-19 23:18:57 +00001//===-- ScheduleDAGPrinter.cpp - Implement ScheduleDAG::viewGraph() -------===//
2//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Dan Gohman60cb69e2008-11-19 23:18:57 +00006//
7//===----------------------------------------------------------------------===//
8//
9// This implements the ScheduleDAG::viewGraph method.
10//
11//===----------------------------------------------------------------------===//
12
Chandler Carruthed0881b2012-12-03 16:50:05 +000013#include "llvm/ADT/StringExtras.h"
Dan Gohman60cb69e2008-11-19 23:18:57 +000014#include "llvm/CodeGen/MachineConstantPool.h"
15#include "llvm/CodeGen/MachineFunction.h"
Chandler Carruth6bda14b2017-06-06 11:49:48 +000016#include "llvm/CodeGen/ScheduleDAG.h"
David Blaikieb3bde2e2017-11-17 01:07:10 +000017#include "llvm/CodeGen/TargetRegisterInfo.h"
Chandler Carruth9fb823b2013-01-02 11:36:10 +000018#include "llvm/IR/Constants.h"
Dan Gohman60cb69e2008-11-19 23:18:57 +000019#include "llvm/Support/Debug.h"
20#include "llvm/Support/GraphWriter.h"
21#include "llvm/Support/raw_ostream.h"
Dan Gohman60cb69e2008-11-19 23:18:57 +000022using namespace llvm;
23
24namespace llvm {
25 template<>
26 struct DOTGraphTraits<ScheduleDAG*> : public DefaultDOTGraphTraits {
Tobias Grosser90d33402009-11-30 12:38:13 +000027
28 DOTGraphTraits (bool isSimple=false) : DefaultDOTGraphTraits(isSimple) {}
29
Dan Gohman60cb69e2008-11-19 23:18:57 +000030 static std::string getGraphName(const ScheduleDAG *G) {
Craig Toppera538d832012-08-22 06:07:19 +000031 return G->MF.getName();
Dan Gohman60cb69e2008-11-19 23:18:57 +000032 }
33
34 static bool renderGraphFromBottomUp() {
35 return true;
36 }
Andrew Trick5297d8d2012-03-07 00:18:15 +000037
Andrew Trickb36388a2013-01-25 07:45:25 +000038 static bool isNodeHidden(const SUnit *Node) {
39 return (Node->NumPreds > 10 || Node->NumSuccs > 10);
40 }
41
James Y Knight14eedd12015-10-27 23:09:03 +000042 static std::string getNodeIdentifierLabel(const SUnit *Node,
43 const ScheduleDAG *Graph) {
44 std::string R;
45 raw_string_ostream OS(R);
46 OS << static_cast<const void *>(Node);
47 return R;
Dan Gohman60cb69e2008-11-19 23:18:57 +000048 }
Andrew Trick5297d8d2012-03-07 00:18:15 +000049
Dan Gohman60cb69e2008-11-19 23:18:57 +000050 /// If you want to override the dot attributes printed for a particular
51 /// edge, override this method.
Dan Gohmancb6accf2008-12-16 00:55:00 +000052 static std::string getEdgeAttributes(const SUnit *Node,
Tobias Grosser3ac86892011-02-27 04:11:03 +000053 SUnitIterator EI,
54 const ScheduleDAG *Graph) {
Dan Gohman67b35bd2008-11-21 02:18:56 +000055 if (EI.isArtificialDep())
Dan Gohman60cb69e2008-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 Trick5297d8d2012-03-07 00:18:15 +000061
Dan Gohman60cb69e2008-11-19 23:18:57 +000062
Fangrui Songcb0bab82018-07-16 18:51:40 +000063 std::string getNodeLabel(const SUnit *SU, const ScheduleDAG *Graph);
Dan Gohman60cb69e2008-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 };
Alexander Kornienkof00654e2015-06-23 09:49:53 +000074}
Dan Gohman60cb69e2008-11-19 23:18:57 +000075
76std::string DOTGraphTraits<ScheduleDAG*>::getNodeLabel(const SUnit *SU,
Tobias Grosserdd7f2e72009-11-30 12:38:47 +000077 const ScheduleDAG *G) {
Dan Gohman60cb69e2008-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 Trick1b2324d2012-03-07 00:18:22 +000084void ScheduleDAG::viewGraph(const Twine &Name, const Twine &Title) {
85 // This code is only for debugging!
Dan Gohman60cb69e2008-11-19 23:18:57 +000086#ifndef NDEBUG
Andrew Trick1b2324d2012-03-07 00:18:22 +000087 ViewGraph(this, Name, false, Title);
Dan Gohman60cb69e2008-11-19 23:18:57 +000088#else
Daniel Dunbar34ee2032009-08-23 08:50:52 +000089 errs() << "ScheduleDAG::viewGraph is only available in debug builds on "
90 << "systems with Graphviz or gv!\n";
Dan Gohman60cb69e2008-11-19 23:18:57 +000091#endif // NDEBUG
92}
Andrew Trick1b2324d2012-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}