1//===-- ScheduleDAGPrinter.cpp - Implement ScheduleDAG::viewGraph() -------===//
2//
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
6//
7//===----------------------------------------------------------------------===//
8//
9// This implements the ScheduleDAG::viewGraph method.
10//
11//===----------------------------------------------------------------------===//
12
13#include "llvm/CodeGen/MachineFunction.h"
14#include "llvm/CodeGen/ScheduleDAG.h"
15#include "llvm/Support/GraphWriter.h"
16#include "llvm/Support/raw_ostream.h"
17using namespace llvm;
18
19template <>
20struct llvm::DOTGraphTraits<ScheduleDAG *> : public DefaultDOTGraphTraits {
21
22 DOTGraphTraits(bool isSimple = false) : DefaultDOTGraphTraits(isSimple) {}
23
24 static std::string getGraphName(const ScheduleDAG *G) {
25 return std::string(G->MF.getName());
26 }
27
28 static bool renderGraphFromBottomUp() { return true; }
29
30 static bool isNodeHidden(const SUnit *Node, const ScheduleDAG *G) {
31 return (Node->NumPreds > 10 || Node->NumSuccs > 10);
32 }
33
34 static std::string getNodeIdentifierLabel(const SUnit *Node,
35 const ScheduleDAG *Graph) {
36 std::string R;
37 raw_string_ostream OS(R);
38 OS << static_cast<const void *>(Node);
39 return R;
40 }
41
42 /// If you want to override the dot attributes printed for a particular
43 /// edge, override this method.
44 static std::string getEdgeAttributes(const SUnit *Node, SUnitIterator EI,
45 const ScheduleDAG *Graph) {
46 if (EI.isArtificialDep())
47 return "color=cyan,style=dashed";
48 if (EI.isCtrlDep())
49 return "color=blue,style=dashed";
50 return "";
51 }
52
53 std::string getNodeLabel(const SUnit *SU, const ScheduleDAG *Graph);
54 static std::string getNodeAttributes(const SUnit *N,
55 const ScheduleDAG *Graph) {
56 return "shape=Mrecord";
57 }
58
59 static void addCustomGraphFeatures(ScheduleDAG *G,
60 GraphWriter<ScheduleDAG *> &GW) {
61 return G->addCustomGraphFeatures(GW);
62 }
63};
64
65std::string DOTGraphTraits<ScheduleDAG*>::getNodeLabel(const SUnit *SU,
66 const ScheduleDAG *G) {
67 return G->getGraphNodeLabel(SU);
68}
69
70/// viewGraph - Pop up a ghostview window with the reachable parts of the DAG
71/// rendered using 'dot'.
72///
73void ScheduleDAG::viewGraph(const Twine &Name, const Twine &Title) {
74 // This code is only for debugging!
75#ifndef NDEBUG
76 ViewGraph(this, Name, false, Title);
77#else
78 errs() << "ScheduleDAG::viewGraph is only available in debug builds on "
79 << "systems with Graphviz or gv!\n";
80#endif // NDEBUG
81}
82
83/// Out-of-line implementation with no arguments is handy for gdb.
84void ScheduleDAG::viewGraph() {
85 viewGraph(Name: getDAGName(), Title: "Scheduling-Units Graph for " + getDAGName());
86}
87