1 //===-- ScheduleDAGPrinter.cpp - Implement ScheduleDAG::viewGraph() -------===//
3 // 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
7 //===----------------------------------------------------------------------===//
9 // This implements the ScheduleDAG::viewGraph method.
11 //===----------------------------------------------------------------------===//
13 #include "llvm/ADT/StringExtras.h"
14 #include "llvm/CodeGen/MachineConstantPool.h"
15 #include "llvm/CodeGen/MachineFunction.h"
16 #include "llvm/CodeGen/ScheduleDAG.h"
17 #include "llvm/CodeGen/TargetRegisterInfo.h"
18 #include "llvm/IR/Constants.h"
19 #include "llvm/Support/Debug.h"
20 #include "llvm/Support/GraphWriter.h"
21 #include "llvm/Support/raw_ostream.h"
26 struct DOTGraphTraits
<ScheduleDAG
*> : public DefaultDOTGraphTraits
{
28 DOTGraphTraits (bool isSimple
=false) : DefaultDOTGraphTraits(isSimple
) {}
30 static std::string
getGraphName(const ScheduleDAG
*G
) {
31 return G
->MF
.getName();
34 static bool renderGraphFromBottomUp() {
38 static bool isNodeHidden(const SUnit
*Node
) {
39 return (Node
->NumPreds
> 10 || Node
->NumSuccs
> 10);
42 static std::string
getNodeIdentifierLabel(const SUnit
*Node
,
43 const ScheduleDAG
*Graph
) {
45 raw_string_ostream
OS(R
);
46 OS
<< static_cast<const void *>(Node
);
50 /// If you want to override the dot attributes printed for a particular
51 /// edge, override this method.
52 static std::string
getEdgeAttributes(const SUnit
*Node
,
54 const ScheduleDAG
*Graph
) {
55 if (EI
.isArtificialDep())
56 return "color=cyan,style=dashed";
58 return "color=blue,style=dashed";
63 std::string
getNodeLabel(const SUnit
*SU
, const ScheduleDAG
*Graph
);
64 static std::string
getNodeAttributes(const SUnit
*N
,
65 const ScheduleDAG
*Graph
) {
66 return "shape=Mrecord";
69 static void addCustomGraphFeatures(ScheduleDAG
*G
,
70 GraphWriter
<ScheduleDAG
*> &GW
) {
71 return G
->addCustomGraphFeatures(GW
);
76 std::string DOTGraphTraits
<ScheduleDAG
*>::getNodeLabel(const SUnit
*SU
,
77 const ScheduleDAG
*G
) {
78 return G
->getGraphNodeLabel(SU
);
81 /// viewGraph - Pop up a ghostview window with the reachable parts of the DAG
82 /// rendered using 'dot'.
84 void ScheduleDAG::viewGraph(const Twine
&Name
, const Twine
&Title
) {
85 // This code is only for debugging!
87 ViewGraph(this, Name
, false, Title
);
89 errs() << "ScheduleDAG::viewGraph is only available in debug builds on "
90 << "systems with Graphviz or gv!\n";
94 /// Out-of-line implementation with no arguments is handy for gdb.
95 void ScheduleDAG::viewGraph() {
96 viewGraph(getDAGName(), "Scheduling-Units Graph for " + getDAGName());