DomPrinter.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===-- DomPrinter.h - Dom printer external interface ------------*- 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. // This file defines external functions that can be called to explicitly
  15. // instantiate the dominance tree printer.
  16. //
  17. //===----------------------------------------------------------------------===//
  18. #ifndef LLVM_ANALYSIS_DOMPRINTER_H
  19. #define LLVM_ANALYSIS_DOMPRINTER_H
  20. #include "llvm/Analysis/DOTGraphTraitsPass.h"
  21. #include "llvm/Analysis/PostDominators.h"
  22. #include "llvm/IR/Dominators.h"
  23. #include "llvm/IR/PassManager.h"
  24. namespace llvm {
  25. template <>
  26. struct DOTGraphTraits<DomTreeNode *> : public DefaultDOTGraphTraits {
  27. DOTGraphTraits(bool isSimple = false) : DefaultDOTGraphTraits(isSimple) {}
  28. std::string getNodeLabel(DomTreeNode *Node, DomTreeNode *Graph) {
  29. BasicBlock *BB = Node->getBlock();
  30. if (!BB)
  31. return "Post dominance root node";
  32. if (isSimple())
  33. return DOTGraphTraits<DOTFuncInfo *>::getSimpleNodeLabel(BB, nullptr);
  34. return DOTGraphTraits<DOTFuncInfo *>::getCompleteNodeLabel(BB, nullptr);
  35. }
  36. };
  37. template <>
  38. struct DOTGraphTraits<DominatorTree *>
  39. : public DOTGraphTraits<DomTreeNode *> {
  40. DOTGraphTraits(bool isSimple = false)
  41. : DOTGraphTraits<DomTreeNode *>(isSimple) {}
  42. static std::string getGraphName(DominatorTree *DT) {
  43. return "Dominator tree";
  44. }
  45. std::string getNodeLabel(DomTreeNode *Node, DominatorTree *G) {
  46. return DOTGraphTraits<DomTreeNode *>::getNodeLabel(Node,
  47. G->getRootNode());
  48. }
  49. };
  50. template<>
  51. struct DOTGraphTraits<PostDominatorTree *>
  52. : public DOTGraphTraits<DomTreeNode*> {
  53. DOTGraphTraits (bool isSimple=false)
  54. : DOTGraphTraits<DomTreeNode*>(isSimple) {}
  55. static std::string getGraphName(PostDominatorTree *DT) {
  56. return "Post dominator tree";
  57. }
  58. std::string getNodeLabel(DomTreeNode *Node,
  59. PostDominatorTree *G) {
  60. return DOTGraphTraits<DomTreeNode*>::getNodeLabel(Node, G->getRootNode());
  61. }
  62. };
  63. struct DomViewer final : DOTGraphTraitsViewer<DominatorTreeAnalysis, false> {
  64. DomViewer() : DOTGraphTraitsViewer<DominatorTreeAnalysis, false>("dom") {}
  65. };
  66. struct DomOnlyViewer final : DOTGraphTraitsViewer<DominatorTreeAnalysis, true> {
  67. DomOnlyViewer()
  68. : DOTGraphTraitsViewer<DominatorTreeAnalysis, true>("domonly") {}
  69. };
  70. struct PostDomViewer final
  71. : DOTGraphTraitsViewer<PostDominatorTreeAnalysis, false> {
  72. PostDomViewer()
  73. : DOTGraphTraitsViewer<PostDominatorTreeAnalysis, false>("postdom") {}
  74. };
  75. struct PostDomOnlyViewer final
  76. : DOTGraphTraitsViewer<PostDominatorTreeAnalysis, true> {
  77. PostDomOnlyViewer()
  78. : DOTGraphTraitsViewer<PostDominatorTreeAnalysis, true>("postdomonly") {}
  79. };
  80. struct DomPrinter final : DOTGraphTraitsPrinter<DominatorTreeAnalysis, false> {
  81. DomPrinter() : DOTGraphTraitsPrinter<DominatorTreeAnalysis, false>("dom") {}
  82. };
  83. struct DomOnlyPrinter final
  84. : DOTGraphTraitsPrinter<DominatorTreeAnalysis, true> {
  85. DomOnlyPrinter()
  86. : DOTGraphTraitsPrinter<DominatorTreeAnalysis, true>("domonly") {}
  87. };
  88. struct PostDomPrinter final
  89. : DOTGraphTraitsPrinter<PostDominatorTreeAnalysis, false> {
  90. PostDomPrinter()
  91. : DOTGraphTraitsPrinter<PostDominatorTreeAnalysis, false>("postdom") {}
  92. };
  93. struct PostDomOnlyPrinter final
  94. : DOTGraphTraitsPrinter<PostDominatorTreeAnalysis, true> {
  95. PostDomOnlyPrinter()
  96. : DOTGraphTraitsPrinter<PostDominatorTreeAnalysis, true>("postdomonly") {}
  97. };
  98. } // namespace llvm
  99. namespace llvm {
  100. class FunctionPass;
  101. FunctionPass *createDomPrinterWrapperPassPass();
  102. FunctionPass *createDomOnlyPrinterWrapperPassPass();
  103. FunctionPass *createDomViewerWrapperPassPass();
  104. FunctionPass *createDomOnlyViewerWrapperPassPass();
  105. FunctionPass *createPostDomPrinterWrapperPassPass();
  106. FunctionPass *createPostDomOnlyPrinterWrapperPassPass();
  107. FunctionPass *createPostDomViewerWrapperPassPass();
  108. FunctionPass *createPostDomOnlyViewerWrapperPassPass();
  109. } // End llvm namespace
  110. #endif
  111. #ifdef __GNUC__
  112. #pragma GCC diagnostic pop
  113. #endif