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