xref: /minix3/external/bsd/llvm/dist/llvm/lib/CodeGen/ScheduleDAGPrinter.cpp (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc //===-- ScheduleDAGPrinter.cpp - Implement ScheduleDAG::viewGraph() -------===//
2*f4a2713aSLionel Sambuc //
3*f4a2713aSLionel Sambuc //                     The LLVM Compiler Infrastructure
4*f4a2713aSLionel Sambuc //
5*f4a2713aSLionel Sambuc // This file is distributed under the University of Illinois Open Source
6*f4a2713aSLionel Sambuc // License. See LICENSE.TXT for details.
7*f4a2713aSLionel Sambuc //
8*f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
9*f4a2713aSLionel Sambuc //
10*f4a2713aSLionel Sambuc // This implements the ScheduleDAG::viewGraph method.
11*f4a2713aSLionel Sambuc //
12*f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
13*f4a2713aSLionel Sambuc 
14*f4a2713aSLionel Sambuc #include "llvm/CodeGen/ScheduleDAG.h"
15*f4a2713aSLionel Sambuc #include "llvm/ADT/DenseSet.h"
16*f4a2713aSLionel Sambuc #include "llvm/ADT/StringExtras.h"
17*f4a2713aSLionel Sambuc #include "llvm/Assembly/Writer.h"
18*f4a2713aSLionel Sambuc #include "llvm/CodeGen/MachineConstantPool.h"
19*f4a2713aSLionel Sambuc #include "llvm/CodeGen/MachineFunction.h"
20*f4a2713aSLionel Sambuc #include "llvm/CodeGen/MachineModuleInfo.h"
21*f4a2713aSLionel Sambuc #include "llvm/IR/Constants.h"
22*f4a2713aSLionel Sambuc #include "llvm/Support/Debug.h"
23*f4a2713aSLionel Sambuc #include "llvm/Support/GraphWriter.h"
24*f4a2713aSLionel Sambuc #include "llvm/Support/raw_ostream.h"
25*f4a2713aSLionel Sambuc #include "llvm/Target/TargetMachine.h"
26*f4a2713aSLionel Sambuc #include "llvm/Target/TargetRegisterInfo.h"
27*f4a2713aSLionel Sambuc #include <fstream>
28*f4a2713aSLionel Sambuc using namespace llvm;
29*f4a2713aSLionel Sambuc 
30*f4a2713aSLionel Sambuc namespace llvm {
31*f4a2713aSLionel Sambuc   template<>
32*f4a2713aSLionel Sambuc   struct DOTGraphTraits<ScheduleDAG*> : public DefaultDOTGraphTraits {
33*f4a2713aSLionel Sambuc 
34*f4a2713aSLionel Sambuc   DOTGraphTraits (bool isSimple=false) : DefaultDOTGraphTraits(isSimple) {}
35*f4a2713aSLionel Sambuc 
36*f4a2713aSLionel Sambuc     static std::string getGraphName(const ScheduleDAG *G) {
37*f4a2713aSLionel Sambuc       return G->MF.getName();
38*f4a2713aSLionel Sambuc     }
39*f4a2713aSLionel Sambuc 
40*f4a2713aSLionel Sambuc     static bool renderGraphFromBottomUp() {
41*f4a2713aSLionel Sambuc       return true;
42*f4a2713aSLionel Sambuc     }
43*f4a2713aSLionel Sambuc 
44*f4a2713aSLionel Sambuc     static bool isNodeHidden(const SUnit *Node) {
45*f4a2713aSLionel Sambuc       return (Node->NumPreds > 10 || Node->NumSuccs > 10);
46*f4a2713aSLionel Sambuc     }
47*f4a2713aSLionel Sambuc 
48*f4a2713aSLionel Sambuc     static bool hasNodeAddressLabel(const SUnit *Node,
49*f4a2713aSLionel Sambuc                                     const ScheduleDAG *Graph) {
50*f4a2713aSLionel Sambuc       return true;
51*f4a2713aSLionel Sambuc     }
52*f4a2713aSLionel Sambuc 
53*f4a2713aSLionel Sambuc     /// If you want to override the dot attributes printed for a particular
54*f4a2713aSLionel Sambuc     /// edge, override this method.
55*f4a2713aSLionel Sambuc     static std::string getEdgeAttributes(const SUnit *Node,
56*f4a2713aSLionel Sambuc                                          SUnitIterator EI,
57*f4a2713aSLionel Sambuc                                          const ScheduleDAG *Graph) {
58*f4a2713aSLionel Sambuc       if (EI.isArtificialDep())
59*f4a2713aSLionel Sambuc         return "color=cyan,style=dashed";
60*f4a2713aSLionel Sambuc       if (EI.isCtrlDep())
61*f4a2713aSLionel Sambuc         return "color=blue,style=dashed";
62*f4a2713aSLionel Sambuc       return "";
63*f4a2713aSLionel Sambuc     }
64*f4a2713aSLionel Sambuc 
65*f4a2713aSLionel Sambuc 
66*f4a2713aSLionel Sambuc     std::string getNodeLabel(const SUnit *Node, const ScheduleDAG *Graph);
67*f4a2713aSLionel Sambuc     static std::string getNodeAttributes(const SUnit *N,
68*f4a2713aSLionel Sambuc                                          const ScheduleDAG *Graph) {
69*f4a2713aSLionel Sambuc       return "shape=Mrecord";
70*f4a2713aSLionel Sambuc     }
71*f4a2713aSLionel Sambuc 
72*f4a2713aSLionel Sambuc     static void addCustomGraphFeatures(ScheduleDAG *G,
73*f4a2713aSLionel Sambuc                                        GraphWriter<ScheduleDAG*> &GW) {
74*f4a2713aSLionel Sambuc       return G->addCustomGraphFeatures(GW);
75*f4a2713aSLionel Sambuc     }
76*f4a2713aSLionel Sambuc   };
77*f4a2713aSLionel Sambuc }
78*f4a2713aSLionel Sambuc 
79*f4a2713aSLionel Sambuc std::string DOTGraphTraits<ScheduleDAG*>::getNodeLabel(const SUnit *SU,
80*f4a2713aSLionel Sambuc                                                        const ScheduleDAG *G) {
81*f4a2713aSLionel Sambuc   return G->getGraphNodeLabel(SU);
82*f4a2713aSLionel Sambuc }
83*f4a2713aSLionel Sambuc 
84*f4a2713aSLionel Sambuc /// viewGraph - Pop up a ghostview window with the reachable parts of the DAG
85*f4a2713aSLionel Sambuc /// rendered using 'dot'.
86*f4a2713aSLionel Sambuc ///
87*f4a2713aSLionel Sambuc void ScheduleDAG::viewGraph(const Twine &Name, const Twine &Title) {
88*f4a2713aSLionel Sambuc   // This code is only for debugging!
89*f4a2713aSLionel Sambuc #ifndef NDEBUG
90*f4a2713aSLionel Sambuc   ViewGraph(this, Name, false, Title);
91*f4a2713aSLionel Sambuc #else
92*f4a2713aSLionel Sambuc   errs() << "ScheduleDAG::viewGraph is only available in debug builds on "
93*f4a2713aSLionel Sambuc          << "systems with Graphviz or gv!\n";
94*f4a2713aSLionel Sambuc #endif  // NDEBUG
95*f4a2713aSLionel Sambuc }
96*f4a2713aSLionel Sambuc 
97*f4a2713aSLionel Sambuc /// Out-of-line implementation with no arguments is handy for gdb.
98*f4a2713aSLionel Sambuc void ScheduleDAG::viewGraph() {
99*f4a2713aSLionel Sambuc   viewGraph(getDAGName(), "Scheduling-Units Graph for " + getDAGName());
100*f4a2713aSLionel Sambuc }
101