Remove ImmediateDominator analysis. The same information can be obtained from DomTre...
[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 /// PostDominatorTree Class - Concrete subclass of DominatorTree that is used to
22 /// compute the a post-dominator tree.
23 ///
24 struct PostDominatorTree : public DominatorTreeBase {
25   PostDominatorTree() : DominatorTreeBase(true) {}
26
27   virtual bool runOnFunction(Function &F) {
28     reset();     // Reset from the last time we were run...
29     calculate(F);
30     return false;
31   }
32
33   virtual void getAnalysisUsage(AnalysisUsage &AU) const {
34     AU.setPreservesAll();
35   }
36 private:
37   void calculate(Function &F);
38   Node *getNodeForBlock(BasicBlock *BB);
39   unsigned DFSPass(BasicBlock *V, InfoRec &VInfo,unsigned N);
40         void Compress(BasicBlock *V, InfoRec &VInfo);
41         BasicBlock *Eval(BasicBlock *V);
42         void Link(BasicBlock *V, BasicBlock *W, InfoRec &WInfo);
43
44   inline BasicBlock *getIDom(BasicBlock *BB) const {
45           std::map<BasicBlock*, BasicBlock*>::const_iterator I = IDoms.find(BB);
46           return I != IDoms.end() ? I->second : 0;
47         }
48 };
49
50
51 /// PostETForest Class - Concrete subclass of ETForestBase that is used to
52 /// compute a forwards post-dominator ET-Forest.
53 struct PostETForest : public ETForestBase {
54   PostETForest() : ETForestBase(true) {}
55
56   virtual void getAnalysisUsage(AnalysisUsage &AU) const {
57     AU.setPreservesAll();
58     AU.addRequired<PostDominatorTree>();
59   }
60
61   virtual bool runOnFunction(Function &F) {
62     reset();     // Reset from the last time we were run...
63     PostDominatorTree &DT = getAnalysis<PostDominatorTree>();
64     Roots = DT.getRoots();
65     calculate(DT);
66     return false;
67   }
68
69   void calculate(const PostDominatorTree &DT);
70   ETNode *getNodeForBlock(BasicBlock *BB);
71 };
72
73
74 /// PostDominanceFrontier Class - Concrete subclass of DominanceFrontier that is
75 /// used to compute the a post-dominance frontier.
76 ///
77 struct PostDominanceFrontier : public DominanceFrontierBase {
78   PostDominanceFrontier() : DominanceFrontierBase(true) {}
79
80   virtual bool runOnFunction(Function &) {
81     Frontiers.clear();
82     PostDominatorTree &DT = getAnalysis<PostDominatorTree>();
83     Roots = DT.getRoots();
84     if (const DominatorTree::Node *Root = DT.getRootNode())
85       calculate(DT, Root);
86     return false;
87   }
88
89   virtual void getAnalysisUsage(AnalysisUsage &AU) const {
90     AU.setPreservesAll();
91     AU.addRequired<PostDominatorTree>();
92   }
93
94 private:
95   const DomSetType &calculate(const PostDominatorTree &DT,
96                               const DominatorTree::Node *Node);
97 };
98
99 } // End llvm namespace
100
101 // Make sure that any clients of this file link in PostDominators.cpp
102 FORCE_DEFINING_FILE_TO_BE_LINKED(PostDominanceFrontier)
103
104 #endif