6e5e0981a15e4aecd6b42b16bec50293c82a72b7
[oota-llvm.git] / include / llvm / Analysis / PostDominators.h
1 //=- llvm/Analysis/PostDominators.h - Post Dominator Calculation-*- C++ -*-===//
2 //
3 // This file exposes interfaces to post dominance information.
4 //
5 //===----------------------------------------------------------------------===//
6
7 #ifndef LLVM_ANALYSIS_POST_DOMINATORS_H
8 #define LLVM_ANALYSIS_POST_DOMINATORS_H
9
10 #include "llvm/Analysis/Dominators.h"
11
12
13 /// PostDominatorSet Class - Concrete subclass of DominatorSetBase that is used
14 /// to compute the post-dominator set.  Because there can be multiple exit nodes
15 /// in an LLVM function, we calculate post dominators with a special null block
16 /// which is the virtual exit node that the real exit nodes all virtually branch
17 /// to.  Clients should be prepared to see an entry in the dominator sets with a
18 /// null BasicBlock*.
19 ///
20 struct PostDominatorSet : public DominatorSetBase {
21   PostDominatorSet() : DominatorSetBase(true) {}
22
23   virtual bool runOnFunction(Function &F);
24
25   // getAnalysisUsage - This pass does not modify the function at all.
26   //
27   virtual void getAnalysisUsage(AnalysisUsage &AU) const {
28     AU.setPreservesAll();
29   }
30 };
31
32
33
34 //===-------------------------------------
35 // ImmediatePostDominators Class - Concrete subclass of ImmediateDominatorsBase
36 // that is used to compute the immediate post-dominators.
37 //
38 struct ImmediatePostDominators : public ImmediateDominatorsBase {
39   ImmediatePostDominators() : ImmediateDominatorsBase(true) {}
40
41   virtual bool runOnFunction(Function &F) {
42     IDoms.clear();     // Reset from the last time we were run...
43     PostDominatorSet &DS = getAnalysis<PostDominatorSet>();
44     Roots = DS.getRoots();
45     calcIDoms(DS);
46     return false;
47   }
48
49   virtual void getAnalysisUsage(AnalysisUsage &AU) const {
50     AU.setPreservesAll();
51     AU.addRequired<PostDominatorSet>();
52   }
53 };
54
55
56 //===-------------------------------------
57 // PostDominatorTree Class - Concrete subclass of DominatorTree that is used to
58 // compute the a post-dominator tree.
59 //
60 struct PostDominatorTree : public DominatorTreeBase {
61   PostDominatorTree() : DominatorTreeBase(true) {}
62
63   virtual bool runOnFunction(Function &F) {
64     reset();     // Reset from the last time we were run...
65     PostDominatorSet &DS = getAnalysis<PostDominatorSet>();
66     Roots = DS.getRoots();
67     calculate(DS);
68     return false;
69   }
70
71   virtual void getAnalysisUsage(AnalysisUsage &AU) const {
72     AU.setPreservesAll();
73     AU.addRequired<PostDominatorSet>();
74   }
75 private:
76   void calculate(const PostDominatorSet &DS);
77 };
78
79
80 //===-------------------------------------
81 // PostDominanceFrontier Class - Concrete subclass of DominanceFrontier that is
82 // used to compute the a post-dominance frontier.
83 //
84 struct PostDominanceFrontier : public DominanceFrontierBase {
85   PostDominanceFrontier() : DominanceFrontierBase(true) {}
86
87   virtual bool runOnFunction(Function &) {
88     Frontiers.clear();
89     PostDominatorTree &DT = getAnalysis<PostDominatorTree>();
90     Roots = DT.getRoots();
91     if (const DominatorTree::Node *Root = DT.getRootNode())
92       calculate(DT, Root);
93     return false;
94   }
95
96   virtual void getAnalysisUsage(AnalysisUsage &AU) const {
97     AU.setPreservesAll();
98     AU.addRequired<PostDominatorTree>();
99   }
100
101   // stub - dummy function, just ignore it
102   static void stub();
103
104 private:
105   const DomSetType &calculate(const PostDominatorTree &DT,
106                               const DominatorTree::Node *Node);
107 };
108
109 // Make sure that any clients of this file link in PostDominators.cpp
110 static IncludeFile
111 POST_DOMINATOR_INCLUDE_FILE((void*)&PostDominanceFrontier::stub);
112
113 #endif