Note to self: SAVE FILES!
[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 /// PostDominanceFrontier Class - Concrete subclass of DominanceFrontier that is
88 /// used to compute the a post-dominance frontier.
89 ///
90 struct PostDominanceFrontier : public DominanceFrontierBase {
91   PostDominanceFrontier() : DominanceFrontierBase(true) {}
92
93   virtual bool runOnFunction(Function &) {
94     Frontiers.clear();
95     PostDominatorTree &DT = getAnalysis<PostDominatorTree>();
96     Roots = DT.getRoots();
97     if (const DominatorTree::Node *Root = DT.getRootNode())
98       calculate(DT, Root);
99     return false;
100   }
101
102   virtual void getAnalysisUsage(AnalysisUsage &AU) const {
103     AU.setPreservesAll();
104     AU.addRequired<PostDominatorTree>();
105   }
106
107   // stub - dummy function, just ignore it
108   static void stub();
109
110 private:
111   const DomSetType &calculate(const PostDominatorTree &DT,
112                               const DominatorTree::Node *Node);
113 };
114
115 // Make sure that any clients of this file link in PostDominators.cpp
116 static IncludeFile
117 POST_DOMINATOR_INCLUDE_FILE((void*)&PostDominanceFrontier::stub);
118
119 } // End llvm namespace
120
121 #endif