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/CodeGen/MachineConstantPool.h"
18*f4a2713aSLionel Sambuc #include "llvm/CodeGen/MachineFunction.h"
19*f4a2713aSLionel Sambuc #include "llvm/CodeGen/MachineModuleInfo.h"
20*f4a2713aSLionel Sambuc #include "llvm/IR/Constants.h"
21*f4a2713aSLionel Sambuc #include "llvm/Support/Debug.h"
22*f4a2713aSLionel Sambuc #include "llvm/Support/GraphWriter.h"
23*f4a2713aSLionel Sambuc #include "llvm/Support/raw_ostream.h"
24*f4a2713aSLionel Sambuc #include "llvm/Target/TargetRegisterInfo.h"
25*f4a2713aSLionel Sambuc #include <fstream>
26*f4a2713aSLionel Sambuc using namespace llvm;
27*f4a2713aSLionel Sambuc
28*f4a2713aSLionel Sambuc namespace llvm {
29*f4a2713aSLionel Sambuc template<>
30*f4a2713aSLionel Sambuc struct DOTGraphTraits<ScheduleDAG*> : public DefaultDOTGraphTraits {
31*f4a2713aSLionel Sambuc
DOTGraphTraitsllvm::DOTGraphTraits32*f4a2713aSLionel Sambuc DOTGraphTraits (bool isSimple=false) : DefaultDOTGraphTraits(isSimple) {}
33*f4a2713aSLionel Sambuc
getGraphNamellvm::DOTGraphTraits34*f4a2713aSLionel Sambuc static std::string getGraphName(const ScheduleDAG *G) {
35*f4a2713aSLionel Sambuc return G->MF.getName();
36*f4a2713aSLionel Sambuc }
37*f4a2713aSLionel Sambuc
renderGraphFromBottomUpllvm::DOTGraphTraits38*f4a2713aSLionel Sambuc static bool renderGraphFromBottomUp() {
39*f4a2713aSLionel Sambuc return true;
40*f4a2713aSLionel Sambuc }
41*f4a2713aSLionel Sambuc
isNodeHiddenllvm::DOTGraphTraits42*f4a2713aSLionel Sambuc static bool isNodeHidden(const SUnit *Node) {
43*f4a2713aSLionel Sambuc return (Node->NumPreds > 10 || Node->NumSuccs > 10);
44*f4a2713aSLionel Sambuc }
45*f4a2713aSLionel Sambuc
hasNodeAddressLabelllvm::DOTGraphTraits46*f4a2713aSLionel Sambuc static bool hasNodeAddressLabel(const SUnit *Node,
47*f4a2713aSLionel Sambuc const ScheduleDAG *Graph) {
48*f4a2713aSLionel Sambuc return true;
49*f4a2713aSLionel Sambuc }
50*f4a2713aSLionel Sambuc
51*f4a2713aSLionel Sambuc /// If you want to override the dot attributes printed for a particular
52*f4a2713aSLionel Sambuc /// edge, override this method.
getEdgeAttributesllvm::DOTGraphTraits53*f4a2713aSLionel Sambuc static std::string getEdgeAttributes(const SUnit *Node,
54*f4a2713aSLionel Sambuc SUnitIterator EI,
55*f4a2713aSLionel Sambuc const ScheduleDAG *Graph) {
56*f4a2713aSLionel Sambuc if (EI.isArtificialDep())
57*f4a2713aSLionel Sambuc return "color=cyan,style=dashed";
58*f4a2713aSLionel Sambuc if (EI.isCtrlDep())
59*f4a2713aSLionel Sambuc return "color=blue,style=dashed";
60*f4a2713aSLionel Sambuc return "";
61*f4a2713aSLionel Sambuc }
62*f4a2713aSLionel Sambuc
63*f4a2713aSLionel Sambuc
64*f4a2713aSLionel Sambuc std::string getNodeLabel(const SUnit *Node, const ScheduleDAG *Graph);
getNodeAttributesllvm::DOTGraphTraits65*f4a2713aSLionel Sambuc static std::string getNodeAttributes(const SUnit *N,
66*f4a2713aSLionel Sambuc const ScheduleDAG *Graph) {
67*f4a2713aSLionel Sambuc return "shape=Mrecord";
68*f4a2713aSLionel Sambuc }
69*f4a2713aSLionel Sambuc
addCustomGraphFeaturesllvm::DOTGraphTraits70*f4a2713aSLionel Sambuc static void addCustomGraphFeatures(ScheduleDAG *G,
71*f4a2713aSLionel Sambuc GraphWriter<ScheduleDAG*> &GW) {
72*f4a2713aSLionel Sambuc return G->addCustomGraphFeatures(GW);
73*f4a2713aSLionel Sambuc }
74*f4a2713aSLionel Sambuc };
75*f4a2713aSLionel Sambuc }
76*f4a2713aSLionel Sambuc
getNodeLabel(const SUnit * SU,const ScheduleDAG * G)77*f4a2713aSLionel Sambuc std::string DOTGraphTraits<ScheduleDAG*>::getNodeLabel(const SUnit *SU,
78*f4a2713aSLionel Sambuc const ScheduleDAG *G) {
79*f4a2713aSLionel Sambuc return G->getGraphNodeLabel(SU);
80*f4a2713aSLionel Sambuc }
81*f4a2713aSLionel Sambuc
82*f4a2713aSLionel Sambuc /// viewGraph - Pop up a ghostview window with the reachable parts of the DAG
83*f4a2713aSLionel Sambuc /// rendered using 'dot'.
84*f4a2713aSLionel Sambuc ///
viewGraph(const Twine & Name,const Twine & Title)85*f4a2713aSLionel Sambuc void ScheduleDAG::viewGraph(const Twine &Name, const Twine &Title) {
86*f4a2713aSLionel Sambuc // This code is only for debugging!
87*f4a2713aSLionel Sambuc #ifndef NDEBUG
88*f4a2713aSLionel Sambuc ViewGraph(this, Name, false, Title);
89*f4a2713aSLionel Sambuc #else
90*f4a2713aSLionel Sambuc errs() << "ScheduleDAG::viewGraph is only available in debug builds on "
91*f4a2713aSLionel Sambuc << "systems with Graphviz or gv!\n";
92*f4a2713aSLionel Sambuc #endif // NDEBUG
93*f4a2713aSLionel Sambuc }
94*f4a2713aSLionel Sambuc
95*f4a2713aSLionel Sambuc /// Out-of-line implementation with no arguments is handy for gdb.
viewGraph()96*f4a2713aSLionel Sambuc void ScheduleDAG::viewGraph() {
97*f4a2713aSLionel Sambuc viewGraph(getDAGName(), "Scheduling-Units Graph for " + getDAGName());
98*f4a2713aSLionel Sambuc }
99