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((intptr_t)&ID) {
29 DT = new DominatorTreeBase<BasicBlock>(true);
32 virtual bool runOnFunction(Function &F);
34 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
38 inline const std::vector<BasicBlock*> &getRoots() const {
39 return DT->getRoots();
42 inline DomTreeNode *getRootNode() const {
43 return DT->getRootNode();
46 inline DomTreeNode *operator[](BasicBlock *BB) const {
47 return DT->getNode(BB);
50 inline bool properlyDominates(const DomTreeNode* A, DomTreeNode* B) const {
51 return DT->properlyDominates(A, B);
54 inline bool properlyDominates(BasicBlock* A, BasicBlock* B) const {
55 return DT->properlyDominates(A, B);
60 /// PostDominanceFrontier Class - Concrete subclass of DominanceFrontier that is
61 /// used to compute the a post-dominance frontier.
63 struct PostDominanceFrontier : public DominanceFrontierBase {
65 PostDominanceFrontier()
66 : DominanceFrontierBase((intptr_t) &ID, true) {}
68 virtual bool runOnFunction(Function &) {
70 PostDominatorTree &DT = getAnalysis<PostDominatorTree>();
71 Roots = DT.getRoots();
72 if (const DomTreeNode *Root = DT.getRootNode())
77 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
79 AU.addRequired<PostDominatorTree>();
83 const DomSetType &calculate(const PostDominatorTree &DT,
84 const DomTreeNode *Node);
87 } // End llvm namespace
89 // Make sure that any clients of this file link in PostDominators.cpp
90 FORCE_DEFINING_FILE_TO_BE_LINKED(PostDominanceFrontier)