LLVM  3.7.0
PostDominators.h
Go to the documentation of this file.
1 //=- llvm/Analysis/PostDominators.h - Post Dominator Calculation-*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // 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_POSTDOMINATORS_H
15 #define LLVM_ANALYSIS_POSTDOMINATORS_H
16 
17 #include "llvm/IR/Dominators.h"
18 
19 namespace llvm {
20 
21 /// PostDominatorTree Class - Concrete subclass of DominatorTree that is used to
22 /// compute the post-dominator tree.
23 ///
25  static char ID; // Pass identification, replacement for typeid
27 
31  }
32 
33  ~PostDominatorTree() override;
34 
35  bool runOnFunction(Function &F) override;
36 
37  void getAnalysisUsage(AnalysisUsage &AU) const override {
38  AU.setPreservesAll();
39  }
40 
41  inline const std::vector<BasicBlock*> &getRoots() const {
42  return DT->getRoots();
43  }
44 
45  inline DomTreeNode *getRootNode() const {
46  return DT->getRootNode();
47  }
48 
49  inline DomTreeNode *operator[](BasicBlock *BB) const {
50  return DT->getNode(BB);
51  }
52 
53  inline DomTreeNode *getNode(BasicBlock *BB) const {
54  return DT->getNode(BB);
55  }
56 
57  inline bool dominates(DomTreeNode* A, DomTreeNode* B) const {
58  return DT->dominates(A, B);
59  }
60 
61  inline bool dominates(const BasicBlock* A, const BasicBlock* B) const {
62  return DT->dominates(A, B);
63  }
64 
65  inline bool properlyDominates(const DomTreeNode* A, DomTreeNode* B) const {
66  return DT->properlyDominates(A, B);
67  }
68 
69  inline bool properlyDominates(BasicBlock* A, BasicBlock* B) const {
70  return DT->properlyDominates(A, B);
71  }
72 
74  return DT->findNearestCommonDominator(A, B);
75  }
76 
78  const BasicBlock *B) {
79  return DT->findNearestCommonDominator(A, B);
80  }
81 
82  /// Get all nodes post-dominated by R, including R itself.
84  SmallVectorImpl<BasicBlock *> &Result) const {
85  DT->getDescendants(R, Result);
86  }
87 
88  void releaseMemory() override {
89  DT->releaseMemory();
90  }
91 
92  void print(raw_ostream &OS, const Module*) const override;
93 };
94 
95 FunctionPass* createPostDomTree();
96 
97 template <> struct GraphTraits<PostDominatorTree*>
98  : public GraphTraits<DomTreeNode*> {
100  return DT->getRootNode();
101  }
102 
104  if (getEntryNode(N))
105  return df_begin(getEntryNode(N));
106  else
107  return df_end(getEntryNode(N));
108  }
109 
111  return df_end(getEntryNode(N));
112  }
113 };
114 
115 } // End llvm namespace
116 
117 #endif
bool properlyDominates(const DomTreeNodeBase< NodeT > *A, const DomTreeNodeBase< NodeT > *B) const
properlyDominates - Returns true iff A dominates B and A != B.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
const BasicBlock * findNearestCommonDominator(const BasicBlock *A, const BasicBlock *B)
bool runOnFunction(Function &F) override
runOnFunction - Virtual method overriden by subclasses to do the per-function processing of the pass...
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:114
DominatorTree GraphTraits specialization so the DominatorTree can be iterable by generic graph iterat...
Definition: GraphTraits.h:27
void getDescendants(NodeT *R, SmallVectorImpl< NodeT * > &Result) const
Get all nodes dominated by R, including R itself.
bool properlyDominates(BasicBlock *A, BasicBlock *B) const
F(f)
static NodeType * getEntryNode(PostDominatorTree *DT)
DominatorTreeBase< BasicBlock > * DT
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: APInt.h:33
DomTreeNodeBase< NodeT > * getRootNode()
getRootNode - This returns the entry node for the CFG of the function.
static nodes_iterator nodes_end(PostDominatorTree *N)
const std::vector< BasicBlock * > & getRoots() const
Base class for the actual dominator tree node.
void print(raw_ostream &OS, const Module *) const override
print - Print out the internal state of the pass.
const std::vector< NodeT * > & getRoots() const
getRoots - Return the root blocks of the current CFG.
LLVM Basic Block Representation.
Definition: BasicBlock.h:65
bool dominates(const DomTreeNodeBase< NodeT > *A, const DomTreeNodeBase< NodeT > *B) const
dominates - Returns true iff A dominates B.
df_iterator< T > df_end(const T &G)
static nodes_iterator nodes_begin(PostDominatorTree *N)
DomTreeNode * operator[](BasicBlock *BB) const
Represent the analysis usage information of a pass.
void getDescendants(BasicBlock *R, SmallVectorImpl< BasicBlock * > &Result) const
Get all nodes post-dominated by R, including R itself.
FunctionPass class - This class is used to implement most global optimizations.
Definition: Pass.h:294
bool dominates(const BasicBlock *A, const BasicBlock *B) const
NodeT * findNearestCommonDominator(NodeT *A, NodeT *B)
findNearestCommonDominator - Find nearest common dominator basic block for basic block A and B...
bool dominates(DomTreeNode *A, DomTreeNode *B) const
void releaseMemory() override
releaseMemory() - This member can be implemented by a pass if it wants to be able to release its memo...
df_iterator< T > df_begin(const T &G)
void initializePostDominatorTreePass(PassRegistry &)
void setPreservesAll()
Set by analyses that do not transform their input at all.
PostDominatorTree Class - Concrete subclass of DominatorTree that is used to compute the post-dominat...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
bool properlyDominates(const DomTreeNode *A, DomTreeNode *B) const
BasicBlock * findNearestCommonDominator(BasicBlock *A, BasicBlock *B)
#define N
DomTreeNode * getRootNode() const
FunctionPass * createPostDomTree()
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:38
DomTreeNodeBase< NodeT > * getNode(NodeT *BB) const
getNode - return the (Post)DominatorTree node for the specified basic block.
DomTreeNode * getNode(BasicBlock *BB) const