Make DomTreeBase not a FunctionPass.
[oota-llvm.git] / include / llvm / Analysis / PostDominators.h
1 //=- llvm/Analysis/PostDominators.h - Post Dominator Calculation-*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file exposes interfaces to post dominance information.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_ANALYSIS_POST_DOMINATORS_H
15 #define LLVM_ANALYSIS_POST_DOMINATORS_H
16
17 #include "llvm/Analysis/Dominators.h"
18
19 namespace llvm {
20
21 /// PostDominatorTree Class - Concrete subclass of DominatorTree that is used to
22 /// compute the a post-dominator tree.
23 ///
24 struct PostDominatorTree : public FunctionPass {
25   static char ID; // Pass identification, replacement for typeid
26   DominatorTreeBase<BasicBlock>* DT;
27
28   PostDominatorTree() : FunctionPass((intptr_t)&ID) {
29     DT = new DominatorTreeBase<BasicBlock>(true);
30   }
31
32   virtual bool runOnFunction(Function &F);
33
34   virtual void getAnalysisUsage(AnalysisUsage &AU) const {
35     AU.setPreservesAll();
36   }
37   
38   inline const std::vector<BasicBlock*> &getRoots() const {
39     return DT->getRoots();
40   }
41   
42   inline DomTreeNode *getRootNode() const {
43     return DT->getRootNode();
44   }
45   
46   inline DomTreeNode *operator[](BasicBlock *BB) const {
47     return DT->getNode(BB);
48   }
49   
50   inline bool properlyDominates(const DomTreeNode* A, DomTreeNode* B) const {
51     return DT->properlyDominates(A, B);
52   }
53   
54   inline bool properlyDominates(BasicBlock* A, BasicBlock* B) const {
55     return DT->properlyDominates(A, B);
56   }
57 };
58
59
60 /// PostDominanceFrontier Class - Concrete subclass of DominanceFrontier that is
61 /// used to compute the a post-dominance frontier.
62 ///
63 struct PostDominanceFrontier : public DominanceFrontierBase {
64   static char ID;
65   PostDominanceFrontier() 
66     : DominanceFrontierBase((intptr_t) &ID, true) {}
67
68   virtual bool runOnFunction(Function &) {
69     Frontiers.clear();
70     PostDominatorTree &DT = getAnalysis<PostDominatorTree>();
71     Roots = DT.getRoots();
72     if (const DomTreeNode *Root = DT.getRootNode())
73       calculate(DT, Root);
74     return false;
75   }
76
77   virtual void getAnalysisUsage(AnalysisUsage &AU) const {
78     AU.setPreservesAll();
79     AU.addRequired<PostDominatorTree>();
80   }
81
82 private:
83   const DomSetType &calculate(const PostDominatorTree &DT,
84                               const DomTreeNode *Node);
85 };
86
87 } // End llvm namespace
88
89 // Make sure that any clients of this file link in PostDominators.cpp
90 FORCE_DEFINING_FILE_TO_BE_LINKED(PostDominanceFrontier)
91
92 #endif