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