2ee6efbae41448c63ffd46d737bfb1d9aee66e38
[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   static char ID; // Pass identification, replacement for typeid
26
27   PostDominatorTree() : 
28     DominatorTreeBase((intptr_t)&ID, true) {}
29
30   virtual bool runOnFunction(Function &F) {
31     reset();     // Reset from the last time we were run...
32     calculate(F);
33     return false;
34   }
35
36   virtual void getAnalysisUsage(AnalysisUsage &AU) const {
37     AU.setPreservesAll();
38   }
39 private:
40   void calculate(Function &F);
41   unsigned DFSPass(BasicBlock *V, unsigned N);
42   void Compress(BasicBlock *V, InfoRec &VInfo);
43   BasicBlock *Eval(BasicBlock *V);
44   void Link(BasicBlock *V, BasicBlock *W, InfoRec &WInfo);
45 };
46
47
48 /// PostDominanceFrontier Class - Concrete subclass of DominanceFrontier that is
49 /// used to compute the a post-dominance frontier.
50 ///
51 struct PostDominanceFrontier : public DominanceFrontierBase {
52   static char ID;
53   PostDominanceFrontier() 
54     : DominanceFrontierBase((intptr_t) &ID, true) {}
55
56   virtual bool runOnFunction(Function &) {
57     Frontiers.clear();
58     PostDominatorTree &DT = getAnalysis<PostDominatorTree>();
59     Roots = DT.getRoots();
60     if (const DomTreeNode *Root = DT.getRootNode())
61       calculate(DT, Root);
62     return false;
63   }
64
65   virtual void getAnalysisUsage(AnalysisUsage &AU) const {
66     AU.setPreservesAll();
67     AU.addRequired<PostDominatorTree>();
68   }
69
70 private:
71   const DomSetType &calculate(const PostDominatorTree &DT,
72                               const DomTreeNode *Node);
73 };
74
75 } // End llvm namespace
76
77 // Make sure that any clients of this file link in PostDominators.cpp
78 FORCE_DEFINING_FILE_TO_BE_LINKED(PostDominanceFrontier)
79
80 #endif