Template DominatorTreeBase by node type. This is the next major step towards
[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<BasicBlock> {
25   static char ID; // Pass identification, replacement for typeid
26
27   PostDominatorTree() : 
28     DominatorTreeBase<BasicBlock>((intptr_t)&ID, true) {}
29
30   virtual bool runOnFunction(Function &F);
31
32   virtual void getAnalysisUsage(AnalysisUsage &AU) const {
33     AU.setPreservesAll();
34   }
35 };
36
37
38 /// PostDominanceFrontier Class - Concrete subclass of DominanceFrontier that is
39 /// used to compute the a post-dominance frontier.
40 ///
41 struct PostDominanceFrontier : public DominanceFrontierBase {
42   static char ID;
43   PostDominanceFrontier() 
44     : DominanceFrontierBase((intptr_t) &ID, true) {}
45
46   virtual bool runOnFunction(Function &) {
47     Frontiers.clear();
48     PostDominatorTree &DT = getAnalysis<PostDominatorTree>();
49     Roots = DT.getRoots();
50     if (const DomTreeNode *Root = DT.getRootNode())
51       calculate(DT, Root);
52     return false;
53   }
54
55   virtual void getAnalysisUsage(AnalysisUsage &AU) const {
56     AU.setPreservesAll();
57     AU.addRequired<PostDominatorTree>();
58   }
59
60 private:
61   const DomSetType &calculate(const PostDominatorTree &DT,
62                               const DomTreeNode *Node);
63 };
64
65 } // End llvm namespace
66
67 // Make sure that any clients of this file link in PostDominators.cpp
68 FORCE_DEFINING_FILE_TO_BE_LINKED(PostDominanceFrontier)
69
70 #endif