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::DomTreeBase<CFGBlock>*
DT;
44 DT =
new llvm::DomTreeBase<CFGBlock>();
49 llvm::DomTreeBase<CFGBlock>&
getBase() {
return *DT; }
60 return DT->getRootNode();
68 DomTreeNode *R = getRootNode();
71 if (!R || !OtherR || R->getBlock() != OtherR->getBlock())
74 if (DT->compare(Other.
getBase()))
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 {
174 static ChildIteratorType
child_begin(NodeRef N) {
return N->begin(); }
175 static ChildIteratorType
child_end(NodeRef N) {
return N->end(); }
177 typedef llvm::pointer_iterator<df_iterator<::clang::DomTreeNode *>>
196 return nodes_iterator(df_begin(getEntryNode(N)));
200 return nodes_iterator(df_end(getEntryNode(N)));
The base class of a hierarchy of objects representing analyses tied to AnalysisDeclContext.
void dump()
This method dumps immediate dominators for each block, mainly used for debug purposes.
::clang::DomTreeNode::iterator ChildIteratorType
static nodes_iterator nodes_end(::clang::DomTreeNode *N)
DominatorTree GraphTraits specialization so the DominatorTree can be iterable by generic graph iterat...
const CFGBlock * findNearestCommonDominator(const CFGBlock *A, const CFGBlock *B)
::clang::DomTreeNode * NodeRef
llvm::DomTreeBase< CFGBlock > & getBase()
AnalysisDeclContext contains the context data for the function or method under analysis.
bool isReachableFromEntry(const CFGBlock *A)
This method tests if the given CFGBlock can be reachable from root.
static NodeRef getEntryNode(NodeRef N)
static NodeRef getEntryNode(::clang::DominatorTree *DT)
static ChildIteratorType child_begin(NodeRef N)
Concrete subclass of DominatorTreeBase for Clang This class implements the dominators tree functional...
CFGBlockListTy::const_iterator const_iterator
CFGBlock - Represents a single basic block in a source-level CFG.
CFG - Represents a source-level, intra-procedural CFG that represents the control-flow of a Stmt...
void buildDominatorTree(AnalysisDeclContext &AC)
This method builds the dominator tree for a given CFG The CFG information is passed via AnalysisDeclC...
virtual void releaseMemory()
This method releases the memory held by the dominator tree.
bool compare(DominatorTree &Other) const
This method compares two dominator trees.
static ChildIteratorType child_end(NodeRef N)
llvm::DomTreeNodeBase< CFGBlock > DomTreeNode
static nodes_iterator nodes_begin(::clang::DominatorTree *N)
CFGBlock * getRoot() const
This method returns the root CFGBlock of the dominators tree.
static nodes_iterator nodes_begin(::clang::DomTreeNode *N)
CFGBlock * findNearestCommonDominator(CFGBlock *A, CFGBlock *B)
This method finds the nearest common dominator CFG block for CFG block A and B.
DomTreeNode * getRootNode() const
This method returns the root DomTreeNode, which is the wrapper for CFGBlock.
static nodes_iterator nodes_end(::clang::DominatorTree *N)
Dataflow Directional Tag Classes.
virtual void print(raw_ostream &OS, const llvm::Module *M=nullptr) const
This method converts the dominator tree to human readable form.
bool dominates(const CFGBlock *A, const CFGBlock *B) const
This method tests if one CFGBlock dominates the other.
llvm::DomTreeBase< CFGBlock > * DT
bool properlyDominates(const CFGBlock *A, const CFGBlock *B) const
This method tests if one CFGBlock properly dominates the other.
llvm::pointer_iterator< df_iterator<::clang::DomTreeNode * > > nodes_iterator
~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...