Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

106 lines
2.8 KiB

  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/Analysis/Dominators.h"
  16. namespace llvm {
  17. /// PostDominatorTree Class - Concrete subclass of DominatorTree that is used to
  18. /// compute the a 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();
  28. virtual bool runOnFunction(Function &F);
  29. virtual void getAnalysisUsage(AnalysisUsage &AU) const {
  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. virtual void releaseMemory() {
  60. DT->releaseMemory();
  61. }
  62. virtual void print(raw_ostream &OS, const Module*) const;
  63. };
  64. FunctionPass* createPostDomTree();
  65. template <> struct GraphTraits<PostDominatorTree*>
  66. : public GraphTraits<DomTreeNode*> {
  67. static NodeType *getEntryNode(PostDominatorTree *DT) {
  68. return DT->getRootNode();
  69. }
  70. static nodes_iterator nodes_begin(PostDominatorTree *N) {
  71. if (getEntryNode(N))
  72. return df_begin(getEntryNode(N));
  73. else
  74. return df_end(getEntryNode(N));
  75. }
  76. static nodes_iterator nodes_end(PostDominatorTree *N) {
  77. return df_end(getEntryNode(N));
  78. }
  79. };
  80. } // End llvm namespace
  81. #endif