LLVM API Documentation
00001 //=- llvm/Analysis/PostDominators.h - Post Dominator Calculation-*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file exposes interfaces to post dominance information. 00011 // 00012 //===----------------------------------------------------------------------===// 00013 00014 #ifndef LLVM_ANALYSIS_POSTDOMINATORS_H 00015 #define LLVM_ANALYSIS_POSTDOMINATORS_H 00016 00017 #include "llvm/IR/Dominators.h" 00018 00019 namespace llvm { 00020 00021 /// PostDominatorTree Class - Concrete subclass of DominatorTree that is used to 00022 /// compute the post-dominator tree. 00023 /// 00024 struct PostDominatorTree : public FunctionPass { 00025 static char ID; // Pass identification, replacement for typeid 00026 DominatorTreeBase<BasicBlock>* DT; 00027 00028 PostDominatorTree() : FunctionPass(ID) { 00029 initializePostDominatorTreePass(*PassRegistry::getPassRegistry()); 00030 DT = new DominatorTreeBase<BasicBlock>(true); 00031 } 00032 00033 ~PostDominatorTree(); 00034 00035 bool runOnFunction(Function &F) override; 00036 00037 void getAnalysisUsage(AnalysisUsage &AU) const override { 00038 AU.setPreservesAll(); 00039 } 00040 00041 inline const std::vector<BasicBlock*> &getRoots() const { 00042 return DT->getRoots(); 00043 } 00044 00045 inline DomTreeNode *getRootNode() const { 00046 return DT->getRootNode(); 00047 } 00048 00049 inline DomTreeNode *operator[](BasicBlock *BB) const { 00050 return DT->getNode(BB); 00051 } 00052 00053 inline DomTreeNode *getNode(BasicBlock *BB) const { 00054 return DT->getNode(BB); 00055 } 00056 00057 inline bool dominates(DomTreeNode* A, DomTreeNode* B) const { 00058 return DT->dominates(A, B); 00059 } 00060 00061 inline bool dominates(const BasicBlock* A, const BasicBlock* B) const { 00062 return DT->dominates(A, B); 00063 } 00064 00065 inline bool properlyDominates(const DomTreeNode* A, DomTreeNode* B) const { 00066 return DT->properlyDominates(A, B); 00067 } 00068 00069 inline bool properlyDominates(BasicBlock* A, BasicBlock* B) const { 00070 return DT->properlyDominates(A, B); 00071 } 00072 00073 inline BasicBlock *findNearestCommonDominator(BasicBlock *A, BasicBlock *B) { 00074 return DT->findNearestCommonDominator(A, B); 00075 } 00076 00077 inline const BasicBlock *findNearestCommonDominator(const BasicBlock *A, 00078 const BasicBlock *B) { 00079 return DT->findNearestCommonDominator(A, B); 00080 } 00081 00082 /// Get all nodes post-dominated by R, including R itself. 00083 void getDescendants(BasicBlock *R, 00084 SmallVectorImpl<BasicBlock *> &Result) const { 00085 DT->getDescendants(R, Result); 00086 } 00087 00088 void releaseMemory() override { 00089 DT->releaseMemory(); 00090 } 00091 00092 void print(raw_ostream &OS, const Module*) const override; 00093 }; 00094 00095 FunctionPass* createPostDomTree(); 00096 00097 template <> struct GraphTraits<PostDominatorTree*> 00098 : public GraphTraits<DomTreeNode*> { 00099 static NodeType *getEntryNode(PostDominatorTree *DT) { 00100 return DT->getRootNode(); 00101 } 00102 00103 static nodes_iterator nodes_begin(PostDominatorTree *N) { 00104 if (getEntryNode(N)) 00105 return df_begin(getEntryNode(N)); 00106 else 00107 return df_end(getEntryNode(N)); 00108 } 00109 00110 static nodes_iterator nodes_end(PostDominatorTree *N) { 00111 return df_end(getEntryNode(N)); 00112 } 00113 }; 00114 00115 } // End llvm namespace 00116 00117 #endif