DDGPrinter.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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/Pass.h"
  22. #include "llvm/Support/DOTGraphTraits.h"
  23. namespace llvm {
  24. //===--------------------------------------------------------------------===//
  25. // Implementation of DDG DOT Printer for a loop.
  26. //===--------------------------------------------------------------------===//
  27. class DDGDotPrinterPass : public PassInfoMixin<DDGDotPrinterPass> {
  28. public:
  29. PreservedAnalyses run(Loop &L, LoopAnalysisManager &AM,
  30. LoopStandardAnalysisResults &AR, LPMUpdater &U);
  31. };
  32. //===--------------------------------------------------------------------===//
  33. // Specialization of DOTGraphTraits.
  34. //===--------------------------------------------------------------------===//
  35. template <>
  36. struct DOTGraphTraits<const DataDependenceGraph *>
  37. : public DefaultDOTGraphTraits {
  38. DOTGraphTraits(bool IsSimple = false) : DefaultDOTGraphTraits(IsSimple) {}
  39. /// Generate a title for the graph in DOT format
  40. std::string getGraphName(const DataDependenceGraph *G) {
  41. assert(G && "expected a valid pointer to the graph.");
  42. return "DDG for '" + std::string(G->getName()) + "'";
  43. }
  44. /// Print a DDG node either in concise form (-ddg-dot-only) or
  45. /// verbose mode (-ddg-dot).
  46. std::string getNodeLabel(const DDGNode *Node,
  47. const DataDependenceGraph *Graph);
  48. /// Print attributes of an edge in the DDG graph. If the edge
  49. /// is a MemoryDependence edge, then detailed dependence info
  50. /// available from DependenceAnalysis is displayed.
  51. std::string
  52. getEdgeAttributes(const DDGNode *Node,
  53. GraphTraits<const DDGNode *>::ChildIteratorType I,
  54. const DataDependenceGraph *G);
  55. /// Do not print nodes that are part of a pi-block separately. They
  56. /// will be printed when their containing pi-block is being printed.
  57. bool isNodeHidden(const DDGNode *Node, const DataDependenceGraph *G);
  58. private:
  59. /// Print a DDG node in concise form.
  60. static std::string getSimpleNodeLabel(const DDGNode *Node,
  61. const DataDependenceGraph *G);
  62. /// Print a DDG node with more information including containing instructions
  63. /// and detailed information about the dependence edges.
  64. static std::string getVerboseNodeLabel(const DDGNode *Node,
  65. const DataDependenceGraph *G);
  66. /// Print a DDG edge in concise form.
  67. static std::string getSimpleEdgeAttributes(const DDGNode *Src,
  68. const DDGEdge *Edge,
  69. const DataDependenceGraph *G);
  70. /// Print a DDG edge with more information including detailed information
  71. /// about the dependence edges.
  72. static std::string getVerboseEdgeAttributes(const DDGNode *Src,
  73. const DDGEdge *Edge,
  74. const DataDependenceGraph *G);
  75. };
  76. using DDGDotGraphTraits = DOTGraphTraits<const DataDependenceGraph *>;
  77. } // namespace llvm
  78. #endif // LLVM_ANALYSIS_DDGPRINTER_H
  79. #ifdef __GNUC__
  80. #pragma GCC diagnostic pop
  81. #endif