Factor the calculation details for PostDomTree out of PostDominators.cpp and
[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     PDTcalculate(*this, F);
33     return false;
34   }
35
36   virtual void getAnalysisUsage(AnalysisUsage &AU) const {
37     AU.setPreservesAll();
38   }
39 private:
40   unsigned DFSPass(BasicBlock *V, unsigned N);
41   friend void PDTcalculate(PostDominatorTree& PDT, Function &F);
42   friend void PDTCompress(PostDominatorTree& PDT, BasicBlock *V,
43                           InfoRec &VInfo);
44   friend BasicBlock *PDTEval(PostDominatorTree& PDT, BasicBlock *V);
45   friend void PDTLink(PostDominatorTree& PDT,BasicBlock *V,
46                       BasicBlock *W, InfoRec &WInfo);
47 };
48
49
50 /// PostDominanceFrontier Class - Concrete subclass of DominanceFrontier that is
51 /// used to compute the a post-dominance frontier.
52 ///
53 struct PostDominanceFrontier : public DominanceFrontierBase {
54   static char ID;
55   PostDominanceFrontier() 
56     : DominanceFrontierBase((intptr_t) &ID, true) {}
57
58   virtual bool runOnFunction(Function &) {
59     Frontiers.clear();
60     PostDominatorTree &DT = getAnalysis<PostDominatorTree>();
61     Roots = DT.getRoots();
62     if (const DomTreeNode *Root = DT.getRootNode())
63       calculate(DT, Root);
64     return false;
65   }
66
67   virtual void getAnalysisUsage(AnalysisUsage &AU) const {
68     AU.setPreservesAll();
69     AU.addRequired<PostDominatorTree>();
70   }
71
72 private:
73   const DomSetType &calculate(const PostDominatorTree &DT,
74                               const DomTreeNode *Node);
75 };
76
77 } // End llvm namespace
78
79 // Make sure that any clients of this file link in PostDominators.cpp
80 FORCE_DEFINING_FILE_TO_BE_LINKED(PostDominanceFrontier)
81
82 #endif