Initial implementation of the ET-Forest data structure for dominators and
[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 /// PostDominatorSet Class - Concrete subclass of DominatorSetBase that is used
22 /// to compute the post-dominator set.  Because there can be multiple exit nodes
23 /// in an LLVM function, we calculate post dominators with a special null block
24 /// which is the virtual exit node that the real exit nodes all virtually branch
25 /// to.  Clients should be prepared to see an entry in the dominator sets with a
26 /// null BasicBlock*.
27 ///
28 struct PostDominatorSet : public DominatorSetBase {
29   PostDominatorSet() : DominatorSetBase(true) {}
30
31   virtual bool runOnFunction(Function &F);
32
33   /// getAnalysisUsage - This pass does not modify the function at all.
34   ///
35   virtual void getAnalysisUsage(AnalysisUsage &AU) const {
36     AU.setPreservesAll();
37   }
38 };
39
40
41 /// ImmediatePostDominators Class - Concrete subclass of ImmediateDominatorsBase
42 /// that is used to compute the immediate post-dominators.
43 ///
44 struct ImmediatePostDominators : public ImmediateDominatorsBase {
45   ImmediatePostDominators() : ImmediateDominatorsBase(true) {}
46
47   virtual bool runOnFunction(Function &F) {
48     IDoms.clear();     // Reset from the last time we were run...
49     PostDominatorSet &DS = getAnalysis<PostDominatorSet>();
50     Roots = DS.getRoots();
51     calcIDoms(DS);
52     return false;
53   }
54
55   virtual void getAnalysisUsage(AnalysisUsage &AU) const {
56     AU.setPreservesAll();
57     AU.addRequired<PostDominatorSet>();
58   }
59 private:
60   void calcIDoms(const DominatorSetBase &DS);
61 };
62
63
64 /// PostDominatorTree Class - Concrete subclass of DominatorTree that is used to
65 /// compute the a post-dominator tree.
66 ///
67 struct PostDominatorTree : public DominatorTreeBase {
68   PostDominatorTree() : DominatorTreeBase(true) {}
69
70   virtual bool runOnFunction(Function &F) {
71     reset();     // Reset from the last time we were run...
72     PostDominatorSet &DS = getAnalysis<PostDominatorSet>();
73     Roots = DS.getRoots();
74     calculate(DS);
75     return false;
76   }
77
78   virtual void getAnalysisUsage(AnalysisUsage &AU) const {
79     AU.setPreservesAll();
80     AU.addRequired<PostDominatorSet>();
81   }
82 private:
83   void calculate(const PostDominatorSet &DS);
84 };
85
86
87 /// PostETForest Class - Concrete subclass of ETForestBase that is used to
88 /// compute a forwards post-dominator ET-Forest.
89 struct PostETForest : public ETForestBase {
90   PostETForest() : ETForestBase(true) {}
91
92   virtual void getAnalysisUsage(AnalysisUsage &AU) const {
93     AU.setPreservesAll();
94     AU.addRequired<ImmediatePostDominators>();
95   }
96
97   virtual bool runOnFunction(Function &F) {
98     reset();     // Reset from the last time we were run...
99     ImmediatePostDominators &ID = getAnalysis<ImmediatePostDominators>();
100     Roots = ID.getRoots();
101     calculate(ID);
102     return false;
103   }
104
105   void calculate(const ImmediatePostDominators &ID);
106   ETNode *getNodeForBlock(BasicBlock *BB);
107 };
108
109
110 /// PostDominanceFrontier Class - Concrete subclass of DominanceFrontier that is
111 /// used to compute the a post-dominance frontier.
112 ///
113 struct PostDominanceFrontier : public DominanceFrontierBase {
114   PostDominanceFrontier() : DominanceFrontierBase(true) {}
115
116   virtual bool runOnFunction(Function &) {
117     Frontiers.clear();
118     PostDominatorTree &DT = getAnalysis<PostDominatorTree>();
119     Roots = DT.getRoots();
120     if (const DominatorTree::Node *Root = DT.getRootNode())
121       calculate(DT, Root);
122     return false;
123   }
124
125   virtual void getAnalysisUsage(AnalysisUsage &AU) const {
126     AU.setPreservesAll();
127     AU.addRequired<PostDominatorTree>();
128   }
129
130   // stub - dummy function, just ignore it
131   static void stub();
132
133 private:
134   const DomSetType &calculate(const PostDominatorTree &DT,
135                               const DominatorTree::Node *Node);
136 };
137
138 // Make sure that any clients of this file link in PostDominators.cpp
139 static IncludeFile
140 POST_DOMINATOR_INCLUDE_FILE((void*)&PostDominanceFrontier::stub);
141
142 } // End llvm namespace
143
144 #endif