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 | |
Andrew Trick | c6ada8e | 2013-01-25 07:45:25 +0000 | [diff] [blame^] | 44 | static bool isNodeHidden(const SUnit *Node) { |
| 45 | return (Node->NumPreds > 10 || Node->NumSuccs > 10); |
| 46 | } |
| 47 | |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 48 | static bool hasNodeAddressLabel(const SUnit *Node, |
| 49 | const ScheduleDAG *Graph) { |
| 50 | return true; |
| 51 | } |
Andrew Trick | acddd49 | 2012-03-07 00:18:15 +0000 | [diff] [blame] | 52 | |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 53 | /// If you want to override the dot attributes printed for a particular |
| 54 | /// edge, override this method. |
Dan Gohman | 3ee7449 | 2008-12-16 00:55:00 +0000 | [diff] [blame] | 55 | static std::string getEdgeAttributes(const SUnit *Node, |
Tobias Grosser | a91f86c | 2011-02-27 04:11:03 +0000 | [diff] [blame] | 56 | SUnitIterator EI, |
| 57 | const ScheduleDAG *Graph) { |
Dan Gohman | 98adea1 | 2008-11-21 02:18:56 +0000 | [diff] [blame] | 58 | if (EI.isArtificialDep()) |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 59 | return "color=cyan,style=dashed"; |
| 60 | if (EI.isCtrlDep()) |
| 61 | return "color=blue,style=dashed"; |
| 62 | return ""; |
| 63 | } |
Andrew Trick | acddd49 | 2012-03-07 00:18:15 +0000 | [diff] [blame] | 64 | |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 65 | |
Tobias Grosser | 56f4ef3 | 2009-11-30 12:38:47 +0000 | [diff] [blame] | 66 | std::string getNodeLabel(const SUnit *Node, const ScheduleDAG *Graph); |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 67 | static std::string getNodeAttributes(const SUnit *N, |
| 68 | const ScheduleDAG *Graph) { |
| 69 | return "shape=Mrecord"; |
| 70 | } |
| 71 | |
| 72 | static void addCustomGraphFeatures(ScheduleDAG *G, |
| 73 | GraphWriter<ScheduleDAG*> &GW) { |
| 74 | return G->addCustomGraphFeatures(GW); |
| 75 | } |
| 76 | }; |
| 77 | } |
| 78 | |
| 79 | std::string DOTGraphTraits<ScheduleDAG*>::getNodeLabel(const SUnit *SU, |
Tobias Grosser | 56f4ef3 | 2009-11-30 12:38:47 +0000 | [diff] [blame] | 80 | const ScheduleDAG *G) { |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 81 | return G->getGraphNodeLabel(SU); |
| 82 | } |
| 83 | |
| 84 | /// viewGraph - Pop up a ghostview window with the reachable parts of the DAG |
| 85 | /// rendered using 'dot'. |
| 86 | /// |
Andrew Trick | 56b94c5 | 2012-03-07 00:18:22 +0000 | [diff] [blame] | 87 | void ScheduleDAG::viewGraph(const Twine &Name, const Twine &Title) { |
| 88 | // This code is only for debugging! |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 89 | #ifndef NDEBUG |
Andrew Trick | 56b94c5 | 2012-03-07 00:18:22 +0000 | [diff] [blame] | 90 | ViewGraph(this, Name, false, Title); |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 91 | #else |
Daniel Dunbar | 43ed267 | 2009-08-23 08:50:52 +0000 | [diff] [blame] | 92 | errs() << "ScheduleDAG::viewGraph is only available in debug builds on " |
| 93 | << "systems with Graphviz or gv!\n"; |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 94 | #endif // NDEBUG |
| 95 | } |
Andrew Trick | 56b94c5 | 2012-03-07 00:18:22 +0000 | [diff] [blame] | 96 | |
| 97 | /// Out-of-line implementation with no arguments is handy for gdb. |
| 98 | void ScheduleDAG::viewGraph() { |
| 99 | viewGraph(getDAGName(), "Scheduling-Units Graph for " + getDAGName()); |
| 100 | } |