14 #ifndef LLVM_CLANG_ANALYSIS_ANALYSES_DOMINATORS_H
15 #define LLVM_CLANG_ANALYSIS_ANALYSES_DOMINATORS_H
19 #include "llvm/ADT/GraphTraits.h"
20 #include "llvm/Support/GenericDomTree.h"
21 #include "llvm/Support/GenericDomTreeConstruction.h"
33 typedef llvm::DomTreeNodeBase<CFGBlock>
DomTreeNode;
39 virtual void anchor();
41 llvm::DominatorTreeBase<CFGBlock>*
DT;
44 DT =
new llvm::DominatorTreeBase<CFGBlock>(
false);
49 llvm::DominatorTreeBase<CFGBlock>&
getBase() {
return *
DT; }
60 return DT->getRootNode();
71 if (!R || !OtherR || R->getBlock() != OtherR->getBlock())
85 DT->recalculate(*cfg);
92 llvm::errs() <<
"Immediate dominance tree (Node#,IDom#):\n";
94 E = cfg->
end(); I != E; ++I) {
95 if(
DT->getNode(*I)->getIDom())
96 llvm::errs() <<
"(" << (*I)->getBlockID()
98 <<
DT->getNode(*I)->getIDom()->getBlock()->getBlockID()
100 else llvm::errs() <<
"(" << (*I)->getBlockID()
101 <<
"," << (*I)->getBlockID() <<
")\n";
110 return DT->dominates(A, B);
117 return DT->properlyDominates(A, B);
124 return DT->findNearestCommonDominator(A, B);
129 return DT->findNearestCommonDominator(A, B);
136 DT->changeImmediateDominator(N, NewIDom);
143 return DT->isReachableFromEntry(A);
154 virtual void print(raw_ostream &OS,
const llvm::Module* M=
nullptr)
const {
186 return df_begin(getEntryNode(N));
190 return df_end(getEntryNode(N));
195 :
public GraphTraits< ::clang::DomTreeNode* > {
201 return df_begin(getEntryNode(N));
205 return df_end(getEntryNode(N));
void dump()
This method dumps immediate dominators for each block, mainly used for debug purposes.
llvm::DominatorTreeBase< CFGBlock > & getBase()
static nodes_iterator nodes_begin(::clang::DominatorTree *N)
const CFGBlock * findNearestCommonDominator(const CFGBlock *A, const CFGBlock *B)
bool dominates(const CFGBlock *A, const CFGBlock *B) const
This method tests if one CFGBlock dominates the other. The method return true if A dominates B...
CFGBlock * getRoot() const
This method returns the root CFGBlock of the dominators tree.
bool isReachableFromEntry(const CFGBlock *A)
This method tests if the given CFGBlock can be reachable from root. Returns true if reachable...
df_iterator< ::clang::DomTreeNode * > nodes_iterator
virtual void print(raw_ostream &OS, const llvm::Module *M=nullptr) const
This method converts the dominator tree to human readable form.
Concrete subclass of DominatorTreeBase for Clang This class implements the dominators tree functional...
::clang::DomTreeNode NodeType
void buildDominatorTree(AnalysisDeclContext &AC)
This method builds the dominator tree for a given CFG The CFG information is passed via AnalysisDeclC...
static NodeType * getEntryNode(NodeType *N)
bool properlyDominates(const CFGBlock *A, const CFGBlock *B) const
This method tests if one CFGBlock properly dominates the other. The method return true if A properly ...
virtual void releaseMemory()
This method releases the memory held by the dominator tree.
llvm::DomTreeNodeBase< CFGBlock > DomTreeNode
NodeType::iterator ChildIteratorType
CFGBlock * findNearestCommonDominator(CFGBlock *A, CFGBlock *B)
This method finds the nearest common dominator CFG block for CFG block A and B. If there is no such b...
static ChildIteratorType child_begin(NodeType *N)
static ChildIteratorType child_end(NodeType *N)
static nodes_iterator nodes_begin(::clang::DomTreeNode *N)
static nodes_iterator nodes_end(::clang::DominatorTree *N)
static nodes_iterator nodes_end(::clang::DomTreeNode *N)
bool compare(DominatorTree &Other) const
This method compares two dominator trees. The method returns false if the other dominator tree matche...
llvm::DominatorTreeBase< CFGBlock > * DT
DomTreeNode * getRootNode() const
This method returns the root DomTreeNode, which is the wrapper for CFGBlock.
static NodeType * getEntryNode(::clang::DominatorTree *DT)
~DominatorTree() override
void changeImmediateDominator(CFGBlock *N, CFGBlock *NewIDom)
This method is used to update the dominator tree information when a node's immediate dominator change...