c55022b7637dfe35892a8862a36018fccb106606
[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) {
29     DT = new DominatorTreeBase<BasicBlock>(true);
30   }
31
32   /// isAnalysis - Return true if this pass is  implementing an analysis pass.
33   virtual bool isAnalysis() const { return true; }
34
35   virtual bool runOnFunction(Function &F);
36
37   virtual void getAnalysisUsage(AnalysisUsage &AU) const {
38     AU.setPreservesAll();
39   }
40   
41   inline const std::vector<BasicBlock*> &getRoots() const {
42     return DT->getRoots();
43   }
44   
45   inline DomTreeNode *getRootNode() const {
46     return DT->getRootNode();
47   }
48   
49   inline DomTreeNode *operator[](BasicBlock *BB) const {
50     return DT->getNode(BB);
51   }
52   
53   inline bool properlyDominates(const DomTreeNode* A, DomTreeNode* B) const {
54     return DT->properlyDominates(A, B);
55   }
56   
57   inline bool properlyDominates(BasicBlock* A, BasicBlock* B) const {
58     return DT->properlyDominates(A, B);
59   }
60
61   virtual void print(std::ostream &OS, const Module* M= 0) const {
62     DT->print(OS, M);
63   }
64 };
65
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((intptr_t) &ID, true) {}
74
75   /// isAnalysis - Return true if this pass is  implementing an analysis pass.
76   virtual bool isAnalysis() const { return true; }
77
78   virtual bool runOnFunction(Function &) {
79     Frontiers.clear();
80     PostDominatorTree &DT = getAnalysis<PostDominatorTree>();
81     Roots = DT.getRoots();
82     if (const DomTreeNode *Root = DT.getRootNode())
83       calculate(DT, Root);
84     return false;
85   }
86
87   virtual void getAnalysisUsage(AnalysisUsage &AU) const {
88     AU.setPreservesAll();
89     AU.addRequired<PostDominatorTree>();
90   }
91
92 private:
93   const DomSetType &calculate(const PostDominatorTree &DT,
94                               const DomTreeNode *Node);
95 };
96
97 } // End llvm namespace
98
99 // Make sure that any clients of this file link in PostDominators.cpp
100 FORCE_DEFINING_FILE_TO_BE_LINKED(PostDominanceFrontier)
101
102 #endif