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/Analysis/Dominators.h" 00018 00019 namespace llvm { 00020 00021 /// PostDominatorTree Class - Concrete subclass of DominatorTree that is used to 00022 /// compute the a 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 virtual bool runOnFunction(Function &F); 00036 00037 virtual void getAnalysisUsage(AnalysisUsage &AU) const { 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 virtual void releaseMemory() { 00083 DT->releaseMemory(); 00084 } 00085 00086 virtual void print(raw_ostream &OS, const Module*) const; 00087 }; 00088 00089 FunctionPass* createPostDomTree(); 00090 00091 template <> struct GraphTraits<PostDominatorTree*> 00092 : public GraphTraits<DomTreeNode*> { 00093 static NodeType *getEntryNode(PostDominatorTree *DT) { 00094 return DT->getRootNode(); 00095 } 00096 00097 static nodes_iterator nodes_begin(PostDominatorTree *N) { 00098 if (getEntryNode(N)) 00099 return df_begin(getEntryNode(N)); 00100 else 00101 return df_end(getEntryNode(N)); 00102 } 00103 00104 static nodes_iterator nodes_end(PostDominatorTree *N) { 00105 return df_end(getEntryNode(N)); 00106 } 00107 }; 00108 00109 } // End llvm namespace 00110 00111 #endif