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_POST_DOMINATORS_H 00015 #define LLVM_ANALYSIS_POST_DOMINATORS_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((intptr_t)&ID) { 00029 DT = new DominatorTreeBase<BasicBlock>(true); 00030 } 00031 00032 ~PostDominatorTree(); 00033 00034 virtual bool runOnFunction(Function &F); 00035 00036 virtual void getAnalysisUsage(AnalysisUsage &AU) const { 00037 AU.setPreservesAll(); 00038 } 00039 00040 inline const std::vector<BasicBlock*> &getRoots() const { 00041 return DT->getRoots(); 00042 } 00043 00044 inline DomTreeNode *getRootNode() const { 00045 return DT->getRootNode(); 00046 } 00047 00048 inline DomTreeNode *operator[](BasicBlock *BB) const { 00049 return DT->getNode(BB); 00050 } 00051 00052 inline bool properlyDominates(const DomTreeNode* A, DomTreeNode* B) const { 00053 return DT->properlyDominates(A, B); 00054 } 00055 00056 inline bool properlyDominates(BasicBlock* A, BasicBlock* B) const { 00057 return DT->properlyDominates(A, B); 00058 } 00059 00060 virtual void print(std::ostream &OS, const Module* M= 0) const { 00061 DT->print(OS, M); 00062 } 00063 }; 00064 00065 FunctionPass* createPostDomTree(); 00066 00067 /// PostDominanceFrontier Class - Concrete subclass of DominanceFrontier that is 00068 /// used to compute the a post-dominance frontier. 00069 /// 00070 struct PostDominanceFrontier : public DominanceFrontierBase { 00071 static char ID; 00072 PostDominanceFrontier() 00073 : DominanceFrontierBase((intptr_t) &ID, true) {} 00074 00075 virtual bool runOnFunction(Function &) { 00076 Frontiers.clear(); 00077 PostDominatorTree &DT = getAnalysis<PostDominatorTree>(); 00078 Roots = DT.getRoots(); 00079 if (const DomTreeNode *Root = DT.getRootNode()) 00080 calculate(DT, Root); 00081 return false; 00082 } 00083 00084 virtual void getAnalysisUsage(AnalysisUsage &AU) const { 00085 AU.setPreservesAll(); 00086 AU.addRequired<PostDominatorTree>(); 00087 } 00088 00089 private: 00090 const DomSetType &calculate(const PostDominatorTree &DT, 00091 const DomTreeNode *Node); 00092 }; 00093 00094 FunctionPass* createPostDomFrontier(); 00095 00096 } // End llvm namespace 00097 00098 #endif