PostDominators.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. //=- llvm/Analysis/PostDominators.h - Post Dominator Calculation-*- C++ -*-===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  10. // This file exposes interfaces to post dominance information.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #ifndef LLVM_ANALYSIS_POSTDOMINATORS_H
  14. #define LLVM_ANALYSIS_POSTDOMINATORS_H
  15. #include "llvm/IR/Dominators.h"
  16. namespace llvm {
  17. /// PostDominatorTree Class - Concrete subclass of DominatorTree that is used to
  18. /// compute the post-dominator tree.
  19. ///
  20. struct PostDominatorTree : public FunctionPass {
  21. static char ID; // Pass identification, replacement for typeid
  22. DominatorTreeBase<BasicBlock>* DT;
  23. PostDominatorTree() : FunctionPass(ID) {
  24. initializePostDominatorTreePass(*PassRegistry::getPassRegistry());
  25. DT = new DominatorTreeBase<BasicBlock>(true);
  26. }
  27. ~PostDominatorTree() override;
  28. bool runOnFunction(Function &F) override;
  29. void getAnalysisUsage(AnalysisUsage &AU) const override {
  30. AU.setPreservesAll();
  31. }
  32. inline const std::vector<BasicBlock*> &getRoots() const {
  33. return DT->getRoots();
  34. }
  35. inline DomTreeNode *getRootNode() const {
  36. return DT->getRootNode();
  37. }
  38. inline DomTreeNode *operator[](BasicBlock *BB) const {
  39. return DT->getNode(BB);
  40. }
  41. inline DomTreeNode *getNode(BasicBlock *BB) const {
  42. return DT->getNode(BB);
  43. }
  44. inline bool dominates(DomTreeNode* A, DomTreeNode* B) const {
  45. return DT->dominates(A, B);
  46. }
  47. inline bool dominates(const BasicBlock* A, const BasicBlock* B) const {
  48. return DT->dominates(A, B);
  49. }
  50. inline bool properlyDominates(const DomTreeNode* A, DomTreeNode* B) const {
  51. return DT->properlyDominates(A, B);
  52. }
  53. inline bool properlyDominates(BasicBlock* A, BasicBlock* B) const {
  54. return DT->properlyDominates(A, B);
  55. }
  56. inline BasicBlock *findNearestCommonDominator(BasicBlock *A, BasicBlock *B) {
  57. return DT->findNearestCommonDominator(A, B);
  58. }
  59. inline const BasicBlock *findNearestCommonDominator(const BasicBlock *A,
  60. const BasicBlock *B) {
  61. return DT->findNearestCommonDominator(A, B);
  62. }
  63. /// Get all nodes post-dominated by R, including R itself.
  64. void getDescendants(BasicBlock *R,
  65. SmallVectorImpl<BasicBlock *> &Result) const {
  66. DT->getDescendants(R, Result);
  67. }
  68. void releaseMemory() override {
  69. DT->releaseMemory();
  70. }
  71. void print(raw_ostream &OS, const Module*) const override;
  72. };
  73. FunctionPass* createPostDomTree();
  74. template <> struct GraphTraits<PostDominatorTree*>
  75. : public GraphTraits<DomTreeNode*> {
  76. static NodeType *getEntryNode(PostDominatorTree *DT) {
  77. return DT->getRootNode();
  78. }
  79. static nodes_iterator nodes_begin(PostDominatorTree *N) {
  80. if (getEntryNode(N))
  81. return df_begin(getEntryNode(N));
  82. else
  83. return df_end(getEntryNode(N));
  84. }
  85. static nodes_iterator nodes_end(PostDominatorTree *N) {
  86. return df_end(getEntryNode(N));
  87. }
  88. };
  89. } // End llvm namespace
  90. #endif