Extend ScalarEvolution's multiple-exit support to compute exact
[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(&ID) {
29     DT = new DominatorTreeBase<BasicBlock>(true);
30   }
31
32   ~PostDominatorTree();
33
34   virtual bool runOnFunction(Function &F);
35
36   virtual void getAnalysisUsage(AnalysisUsage &AU) const {
37     AU.setPreservesAll();
38   }
39   
40   inline const std::vector<BasicBlock*> &getRoots() const {
41     return DT->getRoots();
42   }
43   
44   inline DomTreeNode *getRootNode() const {
45     return DT->getRootNode();
46   }
47   
48   inline DomTreeNode *operator[](BasicBlock *BB) const {
49     return DT->getNode(BB);
50   }
51   
52   inline bool properlyDominates(const DomTreeNode* A, DomTreeNode* B) const {
53     return DT->properlyDominates(A, B);
54   }
55   
56   inline bool properlyDominates(BasicBlock* A, BasicBlock* B) const {
57     return DT->properlyDominates(A, B);
58   }
59
60   virtual void print(std::ostream &OS, const Module* M= 0) const {
61     DT->print(OS, M);
62   }
63 };
64
65 FunctionPass* createPostDomTree();
66
67 /// PostDominanceFrontier Class - Concrete subclass of DominanceFrontier that is
68 /// used to compute the a post-dominance frontier.
69 ///
70 struct PostDominanceFrontier : public DominanceFrontierBase {
71   static char ID;
72   PostDominanceFrontier() 
73     : DominanceFrontierBase(&ID, true) {}
74
75   virtual bool runOnFunction(Function &) {
76     Frontiers.clear();
77     PostDominatorTree &DT = getAnalysis<PostDominatorTree>();
78     Roots = DT.getRoots();
79     if (const DomTreeNode *Root = DT.getRootNode())
80       calculate(DT, Root);
81     return false;
82   }
83
84   virtual void getAnalysisUsage(AnalysisUsage &AU) const {
85     AU.setPreservesAll();
86     AU.addRequired<PostDominatorTree>();
87   }
88
89 private:
90   const DomSetType &calculate(const PostDominatorTree &DT,
91                               const DomTreeNode *Node);
92 };
93
94 FunctionPass* createPostDomFrontier();
95
96 } // End llvm namespace
97
98 #endif