diff options
Diffstat (limited to 'include/clang/Analysis/Analyses/Dominators.h')
-rw-r--r-- | include/clang/Analysis/Analyses/Dominators.h | 91 |
1 files changed, 44 insertions, 47 deletions
diff --git a/include/clang/Analysis/Analyses/Dominators.h b/include/clang/Analysis/Analyses/Dominators.h index 6cb161ab37c8a..a9cdc5560bc07 100644 --- a/include/clang/Analysis/Analyses/Dominators.h +++ b/include/clang/Analysis/Analyses/Dominators.h @@ -1,4 +1,4 @@ -//==- Dominators.h - Implementation of dominators tree for Clang CFG C++ -*-==// +//- Dominators.h - Implementation of dominators tree for Clang CFG -*- C++ -*-// // // The LLVM Compiler Infrastructure // @@ -16,29 +16,35 @@ #include "clang/Analysis/AnalysisDeclContext.h" #include "clang/Analysis/CFG.h" +#include "llvm/ADT/DepthFirstIterator.h" #include "llvm/ADT/GraphTraits.h" +#include "llvm/ADT/iterator.h" #include "llvm/Support/GenericDomTree.h" -#include "llvm/Support/GenericDomTreeConstruction.h" +#include "llvm/Support/GenericDomTreeConstruction.h" +#include "llvm/Support/raw_ostream.h" // FIXME: There is no good reason for the domtree to require a print method // which accepts an LLVM Module, so remove this (and the method's argument that // needs it) when that is fixed. + namespace llvm { + class Module; -} + +} // namespace llvm namespace clang { -class CFGBlock; -typedef llvm::DomTreeNodeBase<CFGBlock> DomTreeNode; +using DomTreeNode = llvm::DomTreeNodeBase<CFGBlock>; -/// \brief Concrete subclass of DominatorTreeBase for Clang +/// Concrete subclass of DominatorTreeBase for Clang /// This class implements the dominators tree functionality given a Clang CFG. /// class DominatorTree : public ManagedAnalysis { virtual void anchor(); + public: - llvm::DomTreeBase<CFGBlock>* DT; + llvm::DomTreeBase<CFGBlock> *DT; DominatorTree() { DT = new llvm::DomTreeBase<CFGBlock>(); @@ -48,23 +54,21 @@ public: llvm::DomTreeBase<CFGBlock>& getBase() { return *DT; } - /// \brief This method returns the root CFGBlock of the dominators tree. - /// - inline CFGBlock *getRoot() const { + /// This method returns the root CFGBlock of the dominators tree. + CFGBlock *getRoot() const { return DT->getRoot(); } - /// \brief This method returns the root DomTreeNode, which is the wrapper + /// This method returns the root DomTreeNode, which is the wrapper /// for CFGBlock. - inline DomTreeNode *getRootNode() const { + DomTreeNode *getRootNode() const { return DT->getRootNode(); } - /// \brief This method compares two dominator trees. + /// This method compares two dominator trees. /// The method returns false if the other dominator tree matches this /// dominator tree, otherwise returns true. - /// - inline bool compare(DominatorTree &Other) const { + bool compare(DominatorTree &Other) const { DomTreeNode *R = getRootNode(); DomTreeNode *OtherR = Other.getRootNode(); @@ -77,17 +81,15 @@ public: return false; } - /// \brief This method builds the dominator tree for a given CFG + /// This method builds the dominator tree for a given CFG /// The CFG information is passed via AnalysisDeclContext - /// void buildDominatorTree(AnalysisDeclContext &AC) { cfg = AC.getCFG(); DT->recalculate(*cfg); } - /// \brief This method dumps immediate dominators for each block, + /// This method dumps immediate dominators for each block, /// mainly used for debug purposes. - /// void dump() { llvm::errs() << "Immediate dominance tree (Node#,IDom#):\n"; for (CFG::const_iterator I = cfg->begin(), @@ -102,55 +104,48 @@ public: } } - /// \brief This method tests if one CFGBlock dominates the other. + /// This method tests if one CFGBlock dominates the other. /// The method return true if A dominates B, false otherwise. /// Note a block always dominates itself. - /// - inline bool dominates(const CFGBlock* A, const CFGBlock* B) const { + bool dominates(const CFGBlock *A, const CFGBlock *B) const { return DT->dominates(A, B); } - /// \brief This method tests if one CFGBlock properly dominates the other. + /// This method tests if one CFGBlock properly dominates the other. /// The method return true if A properly dominates B, false otherwise. - /// - bool properlyDominates(const CFGBlock*A, const CFGBlock*B) const { + bool properlyDominates(const CFGBlock *A, const CFGBlock *B) const { return DT->properlyDominates(A, B); } - /// \brief This method finds the nearest common dominator CFG block + /// This method finds the nearest common dominator CFG block /// for CFG block A and B. If there is no such block then return NULL. - /// - inline CFGBlock *findNearestCommonDominator(CFGBlock *A, CFGBlock *B) { + CFGBlock *findNearestCommonDominator(CFGBlock *A, CFGBlock *B) { return DT->findNearestCommonDominator(A, B); } - inline const CFGBlock *findNearestCommonDominator(const CFGBlock *A, - const CFGBlock *B) { + const CFGBlock *findNearestCommonDominator(const CFGBlock *A, + const CFGBlock *B) { return DT->findNearestCommonDominator(A, B); } - /// \brief This method is used to update the dominator + /// This method is used to update the dominator /// tree information when a node's immediate dominator changes. - /// - inline void changeImmediateDominator(CFGBlock *N, CFGBlock *NewIDom) { + void changeImmediateDominator(CFGBlock *N, CFGBlock *NewIDom) { DT->changeImmediateDominator(N, NewIDom); } - /// \brief This method tests if the given CFGBlock can be reachable from root. + /// This method tests if the given CFGBlock can be reachable from root. /// Returns true if reachable, false otherwise. - /// bool isReachableFromEntry(const CFGBlock *A) { return DT->isReachableFromEntry(A); } - /// \brief This method releases the memory held by the dominator tree. - /// + /// This method releases the memory held by the dominator tree. virtual void releaseMemory() { DT->releaseMemory(); } - /// \brief This method converts the dominator tree to human readable form. - /// + /// This method converts the dominator tree to human readable form. virtual void print(raw_ostream &OS, const llvm::Module* M= nullptr) const { DT->print(OS); } @@ -159,23 +154,24 @@ private: CFG *cfg; }; -} // end namespace clang +} // namespace clang //===------------------------------------- /// DominatorTree GraphTraits specialization so the DominatorTree can be /// iterable by generic graph iterators. /// namespace llvm { + template <> struct GraphTraits< ::clang::DomTreeNode* > { - typedef ::clang::DomTreeNode *NodeRef; - typedef ::clang::DomTreeNode::iterator ChildIteratorType; + using NodeRef = ::clang::DomTreeNode *; + using ChildIteratorType = ::clang::DomTreeNode::iterator; static NodeRef getEntryNode(NodeRef N) { return N; } static ChildIteratorType child_begin(NodeRef N) { return N->begin(); } static ChildIteratorType child_end(NodeRef N) { return N->end(); } - typedef llvm::pointer_iterator<df_iterator<::clang::DomTreeNode *>> - nodes_iterator; + using nodes_iterator = + llvm::pointer_iterator<df_iterator<::clang::DomTreeNode *>>; static nodes_iterator nodes_begin(::clang::DomTreeNode *N) { return nodes_iterator(df_begin(getEntryNode(N))); @@ -187,7 +183,7 @@ template <> struct GraphTraits< ::clang::DomTreeNode* > { }; template <> struct GraphTraits< ::clang::DominatorTree* > - : public GraphTraits< ::clang::DomTreeNode* > { + : public GraphTraits< ::clang::DomTreeNode* > { static NodeRef getEntryNode(::clang::DominatorTree *DT) { return DT->getRootNode(); } @@ -200,6 +196,7 @@ template <> struct GraphTraits< ::clang::DominatorTree* > return nodes_iterator(df_end(getEntryNode(N))); } }; -} // end namespace llvm -#endif +} // namespace llvm + +#endif // LLVM_CLANG_ANALYSIS_ANALYSES_DOMINATORS_H |