1 //=- llvm/Analysis/PostDominators.h - Post Dominator Calculation-*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file exposes interfaces to post dominance information.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_ANALYSIS_POST_DOMINATORS_H
15 #define LLVM_ANALYSIS_POST_DOMINATORS_H
17 #include "llvm/Analysis/Dominators.h"
21 /// PostDominatorTree Class - Concrete subclass of DominatorTree that is used to
22 /// compute the a post-dominator tree.
24 struct PostDominatorTree : public FunctionPass {
25 static char ID; // Pass identification, replacement for typeid
26 DominatorTreeBase<BasicBlock>* DT;
28 PostDominatorTree() : FunctionPass(&ID) {
29 DT = new DominatorTreeBase<BasicBlock>(true);
34 virtual bool runOnFunction(Function &F);
36 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
40 inline const std::vector<BasicBlock*> &getRoots() const {
41 return DT->getRoots();
44 inline DomTreeNode *getRootNode() const {
45 return DT->getRootNode();
48 inline DomTreeNode *operator[](BasicBlock *BB) const {
49 return DT->getNode(BB);
52 inline bool dominates(DomTreeNode* A, DomTreeNode* B) const {
53 return DT->dominates(A, B);
56 inline bool dominates(const BasicBlock* A, const BasicBlock* B) const {
57 return DT->dominates(A, B);
60 inline bool properlyDominates(const DomTreeNode* A, DomTreeNode* B) const {
61 return DT->properlyDominates(A, B);
64 inline bool properlyDominates(BasicBlock* A, BasicBlock* B) const {
65 return DT->properlyDominates(A, B);
68 virtual void releaseMemory() {
72 virtual void print(raw_ostream &OS, const Module*) const;
75 FunctionPass* createPostDomTree();
77 template <> struct GraphTraits<PostDominatorTree*>
78 : public GraphTraits<DomTreeNode*> {
79 static NodeType *getEntryNode(PostDominatorTree *DT) {
80 return DT->getRootNode();
83 static nodes_iterator nodes_begin(PostDominatorTree *N) {
84 return df_begin(getEntryNode(N));
87 static nodes_iterator nodes_end(PostDominatorTree *N) {
88 return df_end(getEntryNode(N));
92 /// PostDominanceFrontier Class - Concrete subclass of DominanceFrontier that is
93 /// used to compute the a post-dominance frontier.
95 struct PostDominanceFrontier : public DominanceFrontierBase {
97 PostDominanceFrontier()
98 : DominanceFrontierBase(&ID, true) {}
100 virtual bool runOnFunction(Function &) {
102 PostDominatorTree &DT = getAnalysis<PostDominatorTree>();
103 Roots = DT.getRoots();
104 if (const DomTreeNode *Root = DT.getRootNode())
109 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
110 AU.setPreservesAll();
111 AU.addRequired<PostDominatorTree>();
115 const DomSetType &calculate(const PostDominatorTree &DT,
116 const DomTreeNode *Node);
119 FunctionPass* createPostDomFrontier();
121 } // End llvm namespace