2
0

ScheduleDAGPrinter.cpp 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. #include "llvm/CodeGen/ScheduleDAG.h"
  14. #include "llvm/ADT/DenseSet.h"
  15. #include "llvm/ADT/StringExtras.h"
  16. #include "llvm/CodeGen/MachineConstantPool.h"
  17. #include "llvm/CodeGen/MachineFunction.h"
  18. #include "llvm/CodeGen/MachineModuleInfo.h"
  19. #include "llvm/IR/Constants.h"
  20. #include "llvm/Support/Debug.h"
  21. #include "llvm/Support/GraphWriter.h"
  22. #include "llvm/Support/raw_ostream.h"
  23. #include "llvm/Target/TargetRegisterInfo.h"
  24. #include <fstream>
  25. using namespace llvm;
  26. namespace llvm {
  27. template<>
  28. struct DOTGraphTraits<ScheduleDAG*> : public DefaultDOTGraphTraits {
  29. DOTGraphTraits (bool isSimple=false) : DefaultDOTGraphTraits(isSimple) {}
  30. static std::string getGraphName(const ScheduleDAG *G) {
  31. return G->MF.getName();
  32. }
  33. static bool renderGraphFromBottomUp() {
  34. return true;
  35. }
  36. static bool isNodeHidden(const SUnit *Node) {
  37. return (Node->NumPreds > 10 || Node->NumSuccs > 10);
  38. }
  39. static bool hasNodeAddressLabel(const SUnit *Node,
  40. const ScheduleDAG *Graph) {
  41. return true;
  42. }
  43. /// If you want to override the dot attributes printed for a particular
  44. /// edge, override this method.
  45. static std::string getEdgeAttributes(const SUnit *Node,
  46. SUnitIterator EI,
  47. const ScheduleDAG *Graph) {
  48. if (EI.isArtificialDep())
  49. return "color=cyan,style=dashed";
  50. if (EI.isCtrlDep())
  51. return "color=blue,style=dashed";
  52. return "";
  53. }
  54. std::string getNodeLabel(const SUnit *Node, const ScheduleDAG *Graph);
  55. static std::string getNodeAttributes(const SUnit *N,
  56. const ScheduleDAG *Graph) {
  57. return "shape=Mrecord";
  58. }
  59. static void addCustomGraphFeatures(ScheduleDAG *G,
  60. GraphWriter<ScheduleDAG*> &GW) {
  61. return G->addCustomGraphFeatures(GW);
  62. }
  63. };
  64. }
  65. std::string DOTGraphTraits<ScheduleDAG*>::getNodeLabel(const SUnit *SU,
  66. const ScheduleDAG *G) {
  67. return G->getGraphNodeLabel(SU);
  68. }
  69. /// viewGraph - Pop up a ghostview window with the reachable parts of the DAG
  70. /// rendered using 'dot'.
  71. ///
  72. void ScheduleDAG::viewGraph(const Twine &Name, const Twine &Title) {
  73. // This code is only for debugging!
  74. #ifndef NDEBUG
  75. ViewGraph(this, Name, false, Title);
  76. #else
  77. errs() << "ScheduleDAG::viewGraph is only available in debug builds on "
  78. << "systems with Graphviz or gv!\n";
  79. #endif // NDEBUG
  80. }
  81. /// Out-of-line implementation with no arguments is handy for gdb.
  82. void ScheduleDAG::viewGraph() {
  83. viewGraph(getDAGName(), "Scheduling-Units Graph for " + getDAGName());
  84. }