14 #ifndef LLVM_CLANG_ANALYSIS_ANALYSES_DOMINATORS_H 15 #define LLVM_CLANG_ANALYSIS_ANALYSES_DOMINATORS_H 19 #include "llvm/ADT/DepthFirstIterator.h" 20 #include "llvm/ADT/GraphTraits.h" 21 #include "llvm/ADT/iterator.h" 22 #include "llvm/Support/GenericDomTree.h" 23 #include "llvm/Support/GenericDomTreeConstruction.h" 24 #include "llvm/Support/raw_ostream.h" 44 virtual void anchor();
47 llvm::DomTreeBase<CFGBlock> *
DT;
50 DT =
new llvm::DomTreeBase<CFGBlock>();
55 llvm::DomTreeBase<CFGBlock>&
getBase() {
return *DT; }
65 return DT->getRootNode();
75 if (!R || !OtherR || R->getBlock() != OtherR->getBlock())
78 if (DT->compare(Other.
getBase()))
88 DT->recalculate(*cfg);
94 llvm::errs() <<
"Immediate dominance tree (Node#,IDom#):\n";
96 E = cfg->end(); I != E; ++I) {
97 if(DT->getNode(*I)->getIDom())
98 llvm::errs() <<
"(" << (*I)->getBlockID()
100 << DT->getNode(*I)->getIDom()->getBlock()->getBlockID()
102 else llvm::errs() <<
"(" << (*I)->getBlockID()
103 <<
"," << (*I)->getBlockID() <<
")\n";
111 return DT->dominates(A, B);
117 return DT->properlyDominates(A, B);
123 return DT->findNearestCommonDominator(A, B);
128 return DT->findNearestCommonDominator(A, B);
134 DT->changeImmediateDominator(N, NewIDom);
140 return DT->isReachableFromEntry(A);
149 virtual void print(raw_ostream &OS,
const llvm::Module* M=
nullptr)
const {
174 llvm::pointer_iterator<df_iterator<::clang::DomTreeNode *>>;
192 return nodes_iterator(df_begin(getEntryNode(N)));
196 return nodes_iterator(df_end(getEntryNode(N)));
202 #endif // LLVM_CLANG_ANALYSIS_ANALYSES_DOMINATORS_H 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.
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)
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)
::clang::DomTreeNode * NodeRef
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
Represents a single basic block in a source-level CFG.
llvm::DomTreeNodeBase< CFGBlock > DomTreeNode
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)
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.
::clang::DomTreeNode::iterator ChildIteratorType
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.
llvm::pointer_iterator< df_iterator<::clang::DomTreeNode * > > nodes_iterator
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.
~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...