From 5a5ac124e1efaf208671f01c46edb15f29ed2a0b Mon Sep 17 00:00:00 2001 From: Dimitry Andric Date: Wed, 27 May 2015 18:44:32 +0000 Subject: Vendor import of llvm trunk r238337: https://llvm.org/svn/llvm-project/llvm/trunk@238337 --- include/llvm/Support/GenericDomTree.h | 95 ++++++++++++++++++----------------- 1 file changed, 48 insertions(+), 47 deletions(-) (limited to 'include/llvm/Support/GenericDomTree.h') diff --git a/include/llvm/Support/GenericDomTree.h b/include/llvm/Support/GenericDomTree.h index fde56135a962..63678bb98bb1 100644 --- a/include/llvm/Support/GenericDomTree.h +++ b/include/llvm/Support/GenericDomTree.h @@ -21,6 +21,7 @@ #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/DepthFirstIterator.h" #include "llvm/ADT/GraphTraits.h" +#include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SmallPtrSet.h" #include "llvm/ADT/SmallVector.h" #include "llvm/Support/Compiler.h" @@ -93,8 +94,9 @@ public: DomTreeNodeBase(NodeT *BB, DomTreeNodeBase *iDom) : TheBB(BB), IDom(iDom), DFSNumIn(-1), DFSNumOut(-1) {} - DomTreeNodeBase *addChild(DomTreeNodeBase *C) { - Children.push_back(C); + std::unique_ptr> + addChild(std::unique_ptr> C) { + Children.push_back(C.get()); return C; } @@ -182,8 +184,8 @@ void Calculate(DominatorTreeBase::NodeType> &DT, /// This class is a generic template over graph nodes. It is instantiated for /// various graphs in the LLVM IR or in the code generator. template class DominatorTreeBase : public DominatorBase { - DominatorTreeBase(const DominatorTreeBase &) LLVM_DELETED_FUNCTION; - DominatorTreeBase &operator=(const DominatorTreeBase &) LLVM_DELETED_FUNCTION; + DominatorTreeBase(const DominatorTreeBase &) = delete; + DominatorTreeBase &operator=(const DominatorTreeBase &) = delete; bool dominatedBySlowTreeWalk(const DomTreeNodeBase *A, const DomTreeNodeBase *B) const { @@ -210,7 +212,8 @@ template class DominatorTreeBase : public DominatorBase { } protected: - typedef DenseMap *> DomTreeNodeMapType; + typedef DenseMap>> + DomTreeNodeMapType; DomTreeNodeMapType DomTreeNodes; DomTreeNodeBase *RootNode; @@ -235,15 +238,13 @@ protected: DenseMap Info; void reset() { - for (typename DomTreeNodeMapType::iterator I = this->DomTreeNodes.begin(), - E = DomTreeNodes.end(); - I != E; ++I) - delete I->second; DomTreeNodes.clear(); IDoms.clear(); this->Roots.clear(); Vertex.clear(); RootNode = nullptr; + DFSInfoValid = false; + SlowQueries = 0; } // NewBB is split and now it has one successor. Update dominator tree to @@ -314,7 +315,6 @@ protected: public: explicit DominatorTreeBase(bool isPostDom) : DominatorBase(isPostDom), DFSInfoValid(false), SlowQueries(0) {} - ~DominatorTreeBase() { reset(); } DominatorTreeBase(DominatorTreeBase &&Arg) : DominatorBase( @@ -358,10 +358,10 @@ public: if (OI == OtherDomTreeNodes.end()) return true; - DomTreeNodeBase *MyNd = I->second; - DomTreeNodeBase *OtherNd = OI->second; + DomTreeNodeBase &MyNd = *I->second; + DomTreeNodeBase &OtherNd = *OI->second; - if (MyNd->compare(OtherNd)) + if (MyNd.compare(&OtherNd)) return true; } @@ -374,7 +374,10 @@ public: /// block. This is the same as using operator[] on this class. /// DomTreeNodeBase *getNode(NodeT *BB) const { - return DomTreeNodes.lookup(BB); + auto I = DomTreeNodes.find(BB); + if (I != DomTreeNodes.end()) + return I->second.get(); + return nullptr; } DomTreeNodeBase *operator[](NodeT *BB) const { return getNode(BB); } @@ -555,8 +558,8 @@ public: DomTreeNodeBase *IDomNode = getNode(DomBB); assert(IDomNode && "Not immediate dominator specified for block!"); DFSInfoValid = false; - return DomTreeNodes[BB] = - IDomNode->addChild(new DomTreeNodeBase(BB, IDomNode)); + return (DomTreeNodes[BB] = IDomNode->addChild( + llvm::make_unique>(BB, IDomNode))).get(); } /// changeImmediateDominator - This method is used to update the dominator @@ -593,15 +596,6 @@ public: } DomTreeNodes.erase(BB); - delete Node; - } - - /// removeNode - Removes a node from the dominator tree. Block must not - /// dominate any other blocks. Invalidates any node pointing to removed - /// block. - void removeNode(NodeT *BB) { - assert(getNode(BB) && "Removing node that isn't in dominator tree."); - DomTreeNodes.erase(BB); } /// splitBlock - BB is split and now it has one successor. Update dominator @@ -645,9 +639,38 @@ protected: friend void Calculate(DominatorTreeBase::NodeType> &DT, FuncT &F); + + DomTreeNodeBase *getNodeForBlock(NodeT *BB) { + if (DomTreeNodeBase *Node = getNode(BB)) + return Node; + + // Haven't calculated this node yet? Get or calculate the node for the + // immediate dominator. + NodeT *IDom = getIDom(BB); + + assert(IDom || this->DomTreeNodes[nullptr]); + DomTreeNodeBase *IDomNode = getNodeForBlock(IDom); + + // Add a new tree node for this NodeT, and link it as a child of + // IDomNode + return (this->DomTreeNodes[BB] = IDomNode->addChild( + llvm::make_unique>(BB, IDomNode))).get(); + } + + NodeT *getIDom(NodeT *BB) const { return IDoms.lookup(BB); } + + void addRoot(NodeT *BB) { this->Roots.push_back(BB); } + +public: /// updateDFSNumbers - Assign In and Out numbers to the nodes while walking /// dominator tree in dfs order. void updateDFSNumbers() const { + + if (DFSInfoValid) { + SlowQueries = 0; + return; + } + unsigned DFSNum = 0; SmallVector *, @@ -690,28 +713,6 @@ protected: DFSInfoValid = true; } - DomTreeNodeBase *getNodeForBlock(NodeT *BB) { - if (DomTreeNodeBase *Node = getNode(BB)) - return Node; - - // Haven't calculated this node yet? Get or calculate the node for the - // immediate dominator. - NodeT *IDom = getIDom(BB); - - assert(IDom || this->DomTreeNodes[nullptr]); - DomTreeNodeBase *IDomNode = getNodeForBlock(IDom); - - // Add a new tree node for this NodeT, and link it as a child of - // IDomNode - DomTreeNodeBase *C = new DomTreeNodeBase(BB, IDomNode); - return this->DomTreeNodes[BB] = IDomNode->addChild(C); - } - - NodeT *getIDom(NodeT *BB) const { return IDoms.lookup(BB); } - - void addRoot(NodeT *BB) { this->Roots.push_back(BB); } - -public: /// recalculate - compute a dominator tree for the given function template void recalculate(FT &F) { typedef GraphTraits TraitsTy; -- cgit v1.2.3