Do not use virtual function to identify an analysis pass.
[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 is distributed under the University of Illinois Open Source
6 // 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, true) {
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   virtual void print(std::ostream &OS, const Module* M= 0) const {
59     DT->print(OS, M);
60   }
61 };
62
63
64 /// PostDominanceFrontier Class - Concrete subclass of DominanceFrontier that is
65 /// used to compute the a post-dominance frontier.
66 ///
67 struct PostDominanceFrontier : public DominanceFrontierBase {
68   static char ID;
69   PostDominanceFrontier() 
70     : DominanceFrontierBase((intptr_t) &ID, true) {}
71
72   virtual bool runOnFunction(Function &) {
73     Frontiers.clear();
74     PostDominatorTree &DT = getAnalysis<PostDominatorTree>();
75     Roots = DT.getRoots();
76     if (const DomTreeNode *Root = DT.getRootNode())
77       calculate(DT, Root);
78     return false;
79   }
80
81   virtual void getAnalysisUsage(AnalysisUsage &AU) const {
82     AU.setPreservesAll();
83     AU.addRequired<PostDominatorTree>();
84   }
85
86 private:
87   const DomSetType &calculate(const PostDominatorTree &DT,
88                               const DomTreeNode *Node);
89 };
90
91 } // End llvm namespace
92
93 // Make sure that any clients of this file link in PostDominators.cpp
94 FORCE_DEFINING_FILE_TO_BE_LINKED(PostDominanceFrontier)
95
96 #endif