ScheduleDAGPrinter.cpp 3.0 KB

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