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 /// isAnalysis - Return true if this pass is implementing an analysis pass.
33 virtual bool isAnalysis() const { return true; }
35 virtual bool runOnFunction(Function &F);
37 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
41 inline const std::vector<BasicBlock*> &getRoots() const {
42 return DT->getRoots();
45 inline DomTreeNode *getRootNode() const {
46 return DT->getRootNode();
49 inline DomTreeNode *operator[](BasicBlock *BB) const {
50 return DT->getNode(BB);
53 inline bool properlyDominates(const DomTreeNode* A, DomTreeNode* B) const {
54 return DT->properlyDominates(A, B);
57 inline bool properlyDominates(BasicBlock* A, BasicBlock* B) const {
58 return DT->properlyDominates(A, B);
61 virtual void print(std::ostream &OS, const Module* M= 0) const {
67 /// PostDominanceFrontier Class - Concrete subclass of DominanceFrontier that is
68 /// used to compute the a post-dominance frontier.
70 struct PostDominanceFrontier : public DominanceFrontierBase {
72 PostDominanceFrontier()
73 : DominanceFrontierBase((intptr_t) &ID, true) {}
75 /// isAnalysis - Return true if this pass is implementing an analysis pass.
76 virtual bool isAnalysis() const { return true; }
78 virtual bool runOnFunction(Function &) {
80 PostDominatorTree &DT = getAnalysis<PostDominatorTree>();
81 Roots = DT.getRoots();
82 if (const DomTreeNode *Root = DT.getRootNode())
87 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
89 AU.addRequired<PostDominatorTree>();
93 const DomSetType &calculate(const PostDominatorTree &DT,
94 const DomTreeNode *Node);
97 } // End llvm namespace
99 // Make sure that any clients of this file link in PostDominators.cpp
100 FORCE_DEFINING_FILE_TO_BE_LINKED(PostDominanceFrontier)