/3rd_party/llvm/lib/CodeGen/ScheduleDAGPrinter.cpp

https://code.google.com/p/softart/ · C++ · 100 lines · 67 code · 14 blank · 19 comment · 3 complexity · 56654e6d553d650b33e4878ff76a9d0a MD5 · raw file

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