diff options
author | Dan Gohman <gohman@apple.com> | 2007-08-28 20:32:58 +0000 |
---|---|---|
committer | Dan Gohman <gohman@apple.com> | 2007-08-28 20:32:58 +0000 |
commit | 3e1a7aef17575d9c7058a035449d57e3c7295ed0 (patch) | |
tree | 617ea3293c3d0db2315e4d7990a8ac85300a34b6 /lib/CodeGen/SelectionDAG/SelectionDAGPrinter.cpp | |
parent | f5a69fe81f8c50e483e2c5ee1a890fc33383fdfb (diff) |
Add an option, -view-sunit-dags, for viewing the actual SUnit DAGs used by
scheduling.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@41556 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/SelectionDAG/SelectionDAGPrinter.cpp')
-rw-r--r-- | lib/CodeGen/SelectionDAG/SelectionDAGPrinter.cpp | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/lib/CodeGen/SelectionDAG/SelectionDAGPrinter.cpp b/lib/CodeGen/SelectionDAG/SelectionDAGPrinter.cpp index 12b5682624..0ce46fdf04 100644 --- a/lib/CodeGen/SelectionDAG/SelectionDAGPrinter.cpp +++ b/lib/CodeGen/SelectionDAG/SelectionDAGPrinter.cpp @@ -15,6 +15,7 @@ #include "llvm/Function.h" #include "llvm/Assembly/Writer.h" #include "llvm/CodeGen/SelectionDAG.h" +#include "llvm/CodeGen/ScheduleDAG.h" #include "llvm/CodeGen/MachineConstantPool.h" #include "llvm/CodeGen/MachineFunction.h" #include "llvm/Target/MRegisterInfo.h" @@ -243,3 +244,72 @@ void SelectionDAG::setGraphColor(const SDNode *N, const char *Color) { #endif } +namespace llvm { + template<> + struct DOTGraphTraits<ScheduleDAG*> : public DefaultDOTGraphTraits { + static std::string getGraphName(const ScheduleDAG *G) { + return DOTGraphTraits<SelectionDAG*>::getGraphName(&G->DAG); + } + + static bool renderGraphFromBottomUp() { + return true; + } + + static bool hasNodeAddressLabel(const SUnit *Node, + const ScheduleDAG *Graph) { + return true; + } + + /// If you want to override the dot attributes printed for a particular + /// edge, override this method. + template<typename EdgeIter> + static std::string getEdgeAttributes(const void *Node, EdgeIter EI) { + if (EI.isChain()) + return "color=blue,style=dashed"; + return ""; + } + + + static std::string getNodeLabel(const SUnit *Node, + const ScheduleDAG *Graph); + static std::string getNodeAttributes(const SUnit *N, + const ScheduleDAG *Graph) { + return "shape=Mrecord"; + } + + static void addCustomGraphFeatures(ScheduleDAG *G, + GraphWriter<ScheduleDAG*> &GW) { + GW.emitSimpleNode(0, "plaintext=circle", "GraphRoot"); + if (G->DAG.getRoot().Val) + GW.emitEdge(0, -1, G->SUnitMap[G->DAG.getRoot().Val], -1, ""); + } + }; +} + +std::string DOTGraphTraits<ScheduleDAG*>::getNodeLabel(const SUnit *SU, + const ScheduleDAG *G) { + std::string Op; + + for (unsigned i = 0; i < SU->FlaggedNodes.size(); ++i) { + Op += DOTGraphTraits<SelectionDAG*>::getNodeLabel(SU->FlaggedNodes[i], + &G->DAG) + "\n"; + } + + Op += DOTGraphTraits<SelectionDAG*>::getNodeLabel(SU->Node, &G->DAG); + + return Op; +} + + +/// viewGraph - Pop up a ghostview window with the reachable parts of the DAG +/// rendered using 'dot'. +/// +void ScheduleDAG::viewGraph() { +// This code is only for debugging! +#ifndef NDEBUG + ViewGraph(this, "dag." + DAG.getMachineFunction().getFunction()->getName()); +#else + cerr << "ScheduleDAG::viewGraph is only available in debug builds on " + << "systems with Graphviz or gv!\n"; +#endif // NDEBUG +} |