DDGPrinter.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- llvm/Analysis/DDGPrinter.h -------------------------------*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. //===----------------------------------------------------------------------===//
  14. //
  15. // This file defines the DOT printer for the Data-Dependence Graph (DDG).
  16. //
  17. //===----------------------------------------------------------------------===//
  18. #ifndef LLVM_ANALYSIS_DDGPRINTER_H
  19. #define LLVM_ANALYSIS_DDGPRINTER_H
  20. #include "llvm/Analysis/DDG.h"
  21. #include "llvm/Support/DOTGraphTraits.h"
  22. namespace llvm {
  23. class LPMUpdater;
  24. class Loop;
  25. //===--------------------------------------------------------------------===//
  26. // Implementation of DDG DOT Printer for a loop.
  27. //===--------------------------------------------------------------------===//
  28. class DDGDotPrinterPass : public PassInfoMixin<DDGDotPrinterPass> {
  29. public:
  30. PreservedAnalyses run(Loop &L, LoopAnalysisManager &AM,
  31. LoopStandardAnalysisResults &AR, LPMUpdater &U);
  32. };
  33. //===--------------------------------------------------------------------===//
  34. // Specialization of DOTGraphTraits.
  35. //===--------------------------------------------------------------------===//
  36. template <>
  37. struct DOTGraphTraits<const DataDependenceGraph *>
  38. : public DefaultDOTGraphTraits {
  39. DOTGraphTraits(bool IsSimple = false) : DefaultDOTGraphTraits(IsSimple) {}
  40. /// Generate a title for the graph in DOT format
  41. std::string getGraphName(const DataDependenceGraph *G) {
  42. assert(G && "expected a valid pointer to the graph.");
  43. return "DDG for '" + std::string(G->getName()) + "'";
  44. }
  45. /// Print a DDG node either in concise form (-ddg-dot-only) or
  46. /// verbose mode (-ddg-dot).
  47. std::string getNodeLabel(const DDGNode *Node,
  48. const DataDependenceGraph *Graph);
  49. /// Print attributes of an edge in the DDG graph. If the edge
  50. /// is a MemoryDependence edge, then detailed dependence info
  51. /// available from DependenceAnalysis is displayed.
  52. std::string
  53. getEdgeAttributes(const DDGNode *Node,
  54. GraphTraits<const DDGNode *>::ChildIteratorType I,
  55. const DataDependenceGraph *G);
  56. /// Do not print nodes that are part of a pi-block separately. They
  57. /// will be printed when their containing pi-block is being printed.
  58. bool isNodeHidden(const DDGNode *Node, const DataDependenceGraph *G);
  59. private:
  60. /// Print a DDG node in concise form.
  61. static std::string getSimpleNodeLabel(const DDGNode *Node,
  62. const DataDependenceGraph *G);
  63. /// Print a DDG node with more information including containing instructions
  64. /// and detailed information about the dependence edges.
  65. static std::string getVerboseNodeLabel(const DDGNode *Node,
  66. const DataDependenceGraph *G);
  67. /// Print a DDG edge in concise form.
  68. static std::string getSimpleEdgeAttributes(const DDGNode *Src,
  69. const DDGEdge *Edge,
  70. const DataDependenceGraph *G);
  71. /// Print a DDG edge with more information including detailed information
  72. /// about the dependence edges.
  73. static std::string getVerboseEdgeAttributes(const DDGNode *Src,
  74. const DDGEdge *Edge,
  75. const DataDependenceGraph *G);
  76. };
  77. using DDGDotGraphTraits = DOTGraphTraits<const DataDependenceGraph *>;
  78. } // namespace llvm
  79. #endif // LLVM_ANALYSIS_DDGPRINTER_H
  80. #ifdef __GNUC__
  81. #pragma GCC diagnostic pop
  82. #endif