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