Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 1 | //===-- ScheduleDAGPrinter.cpp - Implement ScheduleDAG::viewGraph() -------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This implements the ScheduleDAG::viewGraph method. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "llvm/Constants.h" |
| 15 | #include "llvm/Function.h" |
| 16 | #include "llvm/Assembly/Writer.h" |
| 17 | #include "llvm/CodeGen/ScheduleDAG.h" |
| 18 | #include "llvm/CodeGen/MachineConstantPool.h" |
| 19 | #include "llvm/CodeGen/MachineFunction.h" |
| 20 | #include "llvm/CodeGen/MachineModuleInfo.h" |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 21 | #include "llvm/Target/TargetRegisterInfo.h" |
| 22 | #include "llvm/Target/TargetMachine.h" |
| 23 | #include "llvm/Support/Debug.h" |
| 24 | #include "llvm/Support/GraphWriter.h" |
| 25 | #include "llvm/Support/raw_ostream.h" |
| 26 | #include "llvm/ADT/DenseSet.h" |
| 27 | #include "llvm/ADT/StringExtras.h" |
| 28 | #include "llvm/Config/config.h" |
| 29 | #include <fstream> |
| 30 | using namespace llvm; |
| 31 | |
| 32 | namespace llvm { |
| 33 | template<> |
| 34 | struct DOTGraphTraits<ScheduleDAG*> : public DefaultDOTGraphTraits { |
Tobias Grosser | a10d598 | 2009-11-30 12:38:13 +0000 | [diff] [blame] | 35 | |
| 36 | DOTGraphTraits (bool isSimple=false) : DefaultDOTGraphTraits(isSimple) {} |
| 37 | |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 38 | static std::string getGraphName(const ScheduleDAG *G) { |
Dan Gohman | 79ce276 | 2009-01-15 19:20:50 +0000 | [diff] [blame] | 39 | return G->MF.getFunction()->getName(); |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | static bool renderGraphFromBottomUp() { |
| 43 | return true; |
| 44 | } |
| 45 | |
| 46 | static bool hasNodeAddressLabel(const SUnit *Node, |
| 47 | const ScheduleDAG *Graph) { |
| 48 | return true; |
| 49 | } |
| 50 | |
| 51 | /// If you want to override the dot attributes printed for a particular |
| 52 | /// edge, override this method. |
Dan Gohman | 3ee7449 | 2008-12-16 00:55:00 +0000 | [diff] [blame] | 53 | static std::string getEdgeAttributes(const SUnit *Node, |
| 54 | SUnitIterator EI) { |
Dan Gohman | 98adea1 | 2008-11-21 02:18:56 +0000 | [diff] [blame] | 55 | if (EI.isArtificialDep()) |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 56 | return "color=cyan,style=dashed"; |
| 57 | if (EI.isCtrlDep()) |
| 58 | return "color=blue,style=dashed"; |
| 59 | return ""; |
| 60 | } |
| 61 | |
| 62 | |
Tobias Grosser | 56f4ef3 | 2009-11-30 12:38:47 +0000 | [diff] [blame] | 63 | std::string getNodeLabel(const SUnit *Node, const ScheduleDAG *Graph); |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 64 | static std::string getNodeAttributes(const SUnit *N, |
| 65 | const ScheduleDAG *Graph) { |
| 66 | return "shape=Mrecord"; |
| 67 | } |
| 68 | |
| 69 | static void addCustomGraphFeatures(ScheduleDAG *G, |
| 70 | GraphWriter<ScheduleDAG*> &GW) { |
| 71 | return G->addCustomGraphFeatures(GW); |
| 72 | } |
| 73 | }; |
| 74 | } |
| 75 | |
| 76 | std::string DOTGraphTraits<ScheduleDAG*>::getNodeLabel(const SUnit *SU, |
Tobias Grosser | 56f4ef3 | 2009-11-30 12:38:47 +0000 | [diff] [blame] | 77 | const ScheduleDAG *G) { |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 78 | return G->getGraphNodeLabel(SU); |
| 79 | } |
| 80 | |
| 81 | /// viewGraph - Pop up a ghostview window with the reachable parts of the DAG |
| 82 | /// rendered using 'dot'. |
| 83 | /// |
| 84 | void ScheduleDAG::viewGraph() { |
| 85 | // This code is only for debugging! |
| 86 | #ifndef NDEBUG |
Evan Cheng | f412f7c | 2009-02-11 23:42:39 +0000 | [diff] [blame] | 87 | if (BB->getBasicBlock()) |
Daniel Dunbar | f6ccee5 | 2009-07-24 08:24:36 +0000 | [diff] [blame] | 88 | ViewGraph(this, "dag." + MF.getFunction()->getNameStr(), false, |
| 89 | "Scheduling-Units Graph for " + MF.getFunction()->getNameStr() + |
| 90 | ":" + BB->getBasicBlock()->getNameStr()); |
Evan Cheng | f412f7c | 2009-02-11 23:42:39 +0000 | [diff] [blame] | 91 | else |
Daniel Dunbar | f6ccee5 | 2009-07-24 08:24:36 +0000 | [diff] [blame] | 92 | ViewGraph(this, "dag." + MF.getFunction()->getNameStr(), false, |
| 93 | "Scheduling-Units Graph for " + MF.getFunction()->getNameStr()); |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 94 | #else |
Daniel Dunbar | 43ed267 | 2009-08-23 08:50:52 +0000 | [diff] [blame] | 95 | errs() << "ScheduleDAG::viewGraph is only available in debug builds on " |
| 96 | << "systems with Graphviz or gv!\n"; |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 97 | #endif // NDEBUG |
| 98 | } |