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