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 | |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 14 | #include "llvm/CodeGen/ScheduleDAG.h" |
Chandler Carruth | d04a8d4 | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 15 | #include "llvm/ADT/DenseSet.h" |
| 16 | #include "llvm/ADT/StringExtras.h" |
| 17 | #include "llvm/Assembly/Writer.h" |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 18 | #include "llvm/CodeGen/MachineConstantPool.h" |
| 19 | #include "llvm/CodeGen/MachineFunction.h" |
| 20 | #include "llvm/CodeGen/MachineModuleInfo.h" |
Chandler Carruth | 0b8c9a8 | 2013-01-02 11:36:10 +0000 | [diff] [blame^] | 21 | #include "llvm/IR/Constants.h" |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 22 | #include "llvm/Support/Debug.h" |
| 23 | #include "llvm/Support/GraphWriter.h" |
| 24 | #include "llvm/Support/raw_ostream.h" |
Chandler Carruth | d04a8d4 | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 25 | #include "llvm/Target/TargetMachine.h" |
| 26 | #include "llvm/Target/TargetRegisterInfo.h" |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 27 | #include <fstream> |
| 28 | using namespace llvm; |
| 29 | |
| 30 | namespace llvm { |
| 31 | template<> |
| 32 | struct DOTGraphTraits<ScheduleDAG*> : public DefaultDOTGraphTraits { |
Tobias Grosser | a10d598 | 2009-11-30 12:38:13 +0000 | [diff] [blame] | 33 | |
| 34 | DOTGraphTraits (bool isSimple=false) : DefaultDOTGraphTraits(isSimple) {} |
| 35 | |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 36 | static std::string getGraphName(const ScheduleDAG *G) { |
Craig Topper | 96601ca | 2012-08-22 06:07:19 +0000 | [diff] [blame] | 37 | return G->MF.getName(); |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | static bool renderGraphFromBottomUp() { |
| 41 | return true; |
| 42 | } |
Andrew Trick | acddd49 | 2012-03-07 00:18:15 +0000 | [diff] [blame] | 43 | |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 44 | static bool hasNodeAddressLabel(const SUnit *Node, |
| 45 | const ScheduleDAG *Graph) { |
| 46 | return true; |
| 47 | } |
Andrew Trick | acddd49 | 2012-03-07 00:18:15 +0000 | [diff] [blame] | 48 | |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 49 | /// If you want to override the dot attributes printed for a particular |
| 50 | /// edge, override this method. |
Dan Gohman | 3ee7449 | 2008-12-16 00:55:00 +0000 | [diff] [blame] | 51 | static std::string getEdgeAttributes(const SUnit *Node, |
Tobias Grosser | a91f86c | 2011-02-27 04:11:03 +0000 | [diff] [blame] | 52 | SUnitIterator EI, |
| 53 | const ScheduleDAG *Graph) { |
Dan Gohman | 98adea1 | 2008-11-21 02:18:56 +0000 | [diff] [blame] | 54 | if (EI.isArtificialDep()) |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 55 | return "color=cyan,style=dashed"; |
| 56 | if (EI.isCtrlDep()) |
| 57 | return "color=blue,style=dashed"; |
| 58 | return ""; |
| 59 | } |
Andrew Trick | acddd49 | 2012-03-07 00:18:15 +0000 | [diff] [blame] | 60 | |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 61 | |
Tobias Grosser | 56f4ef3 | 2009-11-30 12:38:47 +0000 | [diff] [blame] | 62 | std::string getNodeLabel(const SUnit *Node, const ScheduleDAG *Graph); |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 63 | static std::string getNodeAttributes(const SUnit *N, |
| 64 | const ScheduleDAG *Graph) { |
| 65 | return "shape=Mrecord"; |
| 66 | } |
| 67 | |
| 68 | static void addCustomGraphFeatures(ScheduleDAG *G, |
| 69 | GraphWriter<ScheduleDAG*> &GW) { |
| 70 | return G->addCustomGraphFeatures(GW); |
| 71 | } |
| 72 | }; |
| 73 | } |
| 74 | |
| 75 | std::string DOTGraphTraits<ScheduleDAG*>::getNodeLabel(const SUnit *SU, |
Tobias Grosser | 56f4ef3 | 2009-11-30 12:38:47 +0000 | [diff] [blame] | 76 | const ScheduleDAG *G) { |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 77 | return G->getGraphNodeLabel(SU); |
| 78 | } |
| 79 | |
| 80 | /// viewGraph - Pop up a ghostview window with the reachable parts of the DAG |
| 81 | /// rendered using 'dot'. |
| 82 | /// |
Andrew Trick | 56b94c5 | 2012-03-07 00:18:22 +0000 | [diff] [blame] | 83 | void ScheduleDAG::viewGraph(const Twine &Name, const Twine &Title) { |
| 84 | // This code is only for debugging! |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 85 | #ifndef NDEBUG |
Andrew Trick | 56b94c5 | 2012-03-07 00:18:22 +0000 | [diff] [blame] | 86 | ViewGraph(this, Name, false, Title); |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 87 | #else |
Daniel Dunbar | 43ed267 | 2009-08-23 08:50:52 +0000 | [diff] [blame] | 88 | errs() << "ScheduleDAG::viewGraph is only available in debug builds on " |
| 89 | << "systems with Graphviz or gv!\n"; |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 90 | #endif // NDEBUG |
| 91 | } |
Andrew Trick | 56b94c5 | 2012-03-07 00:18:22 +0000 | [diff] [blame] | 92 | |
| 93 | /// Out-of-line implementation with no arguments is handy for gdb. |
| 94 | void ScheduleDAG::viewGraph() { |
| 95 | viewGraph(getDAGName(), "Scheduling-Units Graph for " + getDAGName()); |
| 96 | } |