ScheduleDAGPrinter.cpp 3.2 KB

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