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