1 //=- llvm/Analysis/PostDominators.h - Post Dominator Calculation-*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file exposes interfaces to post dominance information.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_ANALYSIS_POST_DOMINATORS_H
15 #define LLVM_ANALYSIS_POST_DOMINATORS_H
17 #include "llvm/Analysis/Dominators.h"
21 /// PostDominatorTree Class - Concrete subclass of DominatorTree that is used to
22 /// compute the a post-dominator tree.
24 struct PostDominatorTree : public FunctionPass {
25 static char ID; // Pass identification, replacement for typeid
26 DominatorTreeBase<BasicBlock>* DT;
28 PostDominatorTree() : FunctionPass(ID) {
29 initializePostDominatorTreePass(*PassRegistry::getPassRegistry());
30 DT = new DominatorTreeBase<BasicBlock>(true);
35 virtual bool runOnFunction(Function &F);
37 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
41 inline const std::vector<BasicBlock*> &getRoots() const {
42 return DT->getRoots();
45 inline DomTreeNode *getRootNode() const {
46 return DT->getRootNode();
49 inline DomTreeNode *operator[](BasicBlock *BB) const {
50 return DT->getNode(BB);
53 inline DomTreeNode *getNode(BasicBlock *BB) const {
54 return DT->getNode(BB);
57 inline bool dominates(DomTreeNode* A, DomTreeNode* B) const {
58 return DT->dominates(A, B);
61 inline bool dominates(const BasicBlock* A, const BasicBlock* B) const {
62 return DT->dominates(A, B);
65 inline bool properlyDominates(const DomTreeNode* A, DomTreeNode* B) const {
66 return DT->properlyDominates(A, B);
69 inline bool properlyDominates(BasicBlock* A, BasicBlock* B) const {
70 return DT->properlyDominates(A, B);
73 inline BasicBlock *findNearestCommonDominator(BasicBlock *A, BasicBlock *B) {
74 return DT->findNearestCommonDominator(A, B);
77 virtual void releaseMemory() {
81 virtual void print(raw_ostream &OS, const Module*) const;
84 FunctionPass* createPostDomTree();
86 template <> struct GraphTraits<PostDominatorTree*>
87 : public GraphTraits<DomTreeNode*> {
88 static NodeType *getEntryNode(PostDominatorTree *DT) {
89 return DT->getRootNode();
92 static nodes_iterator nodes_begin(PostDominatorTree *N) {
94 return df_begin(getEntryNode(N));
96 return df_end(getEntryNode(N));
99 static nodes_iterator nodes_end(PostDominatorTree *N) {
100 return df_end(getEntryNode(N));
104 } // End llvm namespace