diff --git a/llvm/include/llvm/Support/GenericDomTree.h b/llvm/include/llvm/Support/GenericDomTree.h --- a/llvm/include/llvm/Support/GenericDomTree.h +++ b/llvm/include/llvm/Support/GenericDomTree.h @@ -337,6 +337,7 @@ using NodeType = NodeT; using NodePtr = NodeT *; using ParentPtr = decltype(std::declval()->getParent()); + using TreeNode = DomTreeNodeBase; static_assert(std::is_pointer::value, "Currently NodeT's parent must be a pointer type"); using ParentType = std::remove_pointer_t; @@ -403,16 +404,13 @@ /// block. This is the same as using operator[] on this class. The result /// may (but is not required to) be null for a forward (backwards) /// statically unreachable block. - DomTreeNodeBase *getNode(const NodeT *BB) const { - return static_cast *>( - GenericDominatorTreeBase::getNode( - CfgTraits::toGeneric(const_cast(BB)))); + TreeNode *getNode(const NodeT *BB) const { + return static_cast(GenericDominatorTreeBase::getNode( + CfgTraits::toGeneric(const_cast(BB)))); } /// See getNode. - DomTreeNodeBase *operator[](const NodeT *BB) const { - return getNode(BB); - } + TreeNode *operator[](const NodeT *BB) const { return getNode(BB); } /// getRootNode - This returns the entry node for the CFG of the function. If /// this tree represents the post-dominance relations for a function, however, @@ -421,31 +419,28 @@ /// post-dominance information must be capable of dealing with this /// possibility. /// - DomTreeNodeBase *getRootNode() { - return static_cast *>(RootNode); - } - const DomTreeNodeBase *getRootNode() const { - return static_cast *>(RootNode); + TreeNode *getRootNode() { return static_cast(RootNode); } + const TreeNode *getRootNode() const { + return static_cast(RootNode); } /// Get all nodes dominated by R, including R itself. void getDescendants(NodeT *R, SmallVectorImpl &Result) const { Result.clear(); - const DomTreeNodeBase *RN = getNode(R); + const TreeNode *RN = getNode(R); if (!RN) return; // If R is unreachable, it will not be present in the DOM tree. - SmallVector *, 8> WL; + SmallVector WL; WL.push_back(RN); while (!WL.empty()) { - const DomTreeNodeBase *N = WL.pop_back_val(); + const TreeNode *N = WL.pop_back_val(); Result.push_back(N->getBlock()); WL.append(N->begin(), N->end()); } } - bool properlyDominates(const DomTreeNodeBase *A, - const DomTreeNodeBase *B) const { + bool properlyDominates(const TreeNode *A, const TreeNode *B) const { return GenericDominatorTreeBase::properlyDominates(A, B); } bool properlyDominates(const NodeT *A, const NodeT *B) const { @@ -461,12 +456,9 @@ "This is not implemented for post dominators"); return getNode(const_cast(A)) != nullptr; } - bool isReachableFromEntry(const DomTreeNodeBase *A) const { - return A != nullptr; - } + bool isReachableFromEntry(const TreeNode *A) const { return A != nullptr; } - bool dominates(const DomTreeNodeBase *A, - const DomTreeNodeBase *B) const { + bool dominates(const TreeNode *A, const TreeNode *B) const { return GenericDominatorTreeBase::dominates(A, B); } bool dominates(const NodeT *A, const NodeT *B) const { @@ -480,31 +472,28 @@ return this->Roots[0]; } - bool isVirtualRoot(const DomTreeNodeBase *A) const { + bool isVirtualRoot(const TreeNode *A) const { return isPostDominator() && !A->getBlock(); } - const DomTreeNodeBase * - findNearestCommonDominator(const DomTreeNodeBase *A, - const DomTreeNodeBase *B) const { - return static_cast *>( + const TreeNode *findNearestCommonDominator(const TreeNode *A, + const TreeNode *B) const { + return static_cast( GenericDominatorTreeBase::findNearestCommonDominator(A, B)); } const NodeT *findNearestCommonDominator(const NodeT *A, const NodeT *B) const { assert(A && B && "Pointers are not valid"); - const DomTreeNodeBase *dom = - static_cast *>( - GenericDominatorTreeBase::findNearestCommonDominator(getNode(A), - getNode(B))); + const TreeNode *dom = static_cast( + GenericDominatorTreeBase::findNearestCommonDominator(getNode(A), + getNode(B))); return dom->getBlock(); } NodeT *findNearestCommonDominator(NodeT *A, NodeT *B) const { assert(A && B && "Pointers are not valid"); - const DomTreeNodeBase *dom = - static_cast *>( - GenericDominatorTreeBase::findNearestCommonDominator(getNode(A), - getNode(B))); + const TreeNode *dom = static_cast( + GenericDominatorTreeBase::findNearestCommonDominator(getNode(A), + getNode(B))); return dom->getBlock(); } @@ -590,9 +579,9 @@ /// \param DomBB CFG node that is dominator for BB. /// \returns New dominator tree node that represents new CFG node. /// - DomTreeNodeBase *addNewBlock(NodeT *BB, NodeT *DomBB) { + TreeNode *addNewBlock(NodeT *BB, NodeT *DomBB) { assert(getNode(BB) == nullptr && "Block already in dominator tree!"); - DomTreeNodeBase *IDomNode = getNode(DomBB); + TreeNode *IDomNode = getNode(DomBB); assert(IDomNode && "Not immediate dominator specified for block!"); DFSInfoValid = false; return createChild(BB, IDomNode); @@ -603,7 +592,7 @@ /// \param BB New node in CFG. /// \returns New dominator tree node that represents new CFG node. /// - DomTreeNodeBase *setNewRoot(NodeT *BB) { + TreeNode *setNewRoot(NodeT *BB) { assert(getNode(BB) == nullptr && "Block already in dominator tree!"); assert(!this->isPostDominator() && "Cannot change root of post-dominator tree"); @@ -621,14 +610,13 @@ Roots[0] = BB; } RootNode = NewNode; - return static_cast *>(RootNode); + return static_cast(RootNode); } /// changeImmediateDominator - This method is used to update the dominator /// tree information when a node's immediate dominator changes. /// - void changeImmediateDominator(DomTreeNodeBase *N, - DomTreeNodeBase *NewIDom) { + void changeImmediateDominator(TreeNode *N, TreeNode *NewIDom) { assert(N && NewIDom && "Cannot change null node pointers!"); DFSInfoValid = false; N->setIDom(NewIDom); @@ -642,14 +630,14 @@ /// dominate any other blocks. Removes node from its immediate dominator's /// children list. Deletes dominator node associated with basic block BB. void eraseNode(NodeT *BB) { - DomTreeNodeBase *Node = getNode(BB); + TreeNode *Node = getNode(BB); assert(Node && "Removing node that isn't in dominator tree."); assert(Node->isLeaf() && "Node is not a leaf node."); DFSInfoValid = false; // Remove node from immediate dominator's children list. - DomTreeNodeBase *IDom = Node->getIDom(); + TreeNode *IDom = Node->getIDom(); if (IDom) { const auto I = find(IDom->Children, Node); assert(I != IDom->Children.end() && @@ -740,17 +728,17 @@ protected: void addRoot(NodeT *BB) { this->Roots.push_back(BB); } - DomTreeNodeBase *createChild(NodeT *BB, DomTreeNodeBase *IDom) { + TreeNode *createChild(NodeT *BB, TreeNode *IDom) { CfgBlockRef bbRef = CfgTraits::toGeneric(BB); - return static_cast *>( + return static_cast( (DomTreeNodes[bbRef] = IDom->addChild( std::make_unique(bbRef, IDom))) .get()); } - DomTreeNodeBase *createNode(NodeT *BB) { + TreeNode *createNode(NodeT *BB) { CfgBlockRef bbRef = CfgTraits::toGeneric(BB); - return static_cast *>( + return static_cast( (DomTreeNodes[bbRef] = std::make_unique(bbRef, nullptr)) .get()); @@ -803,12 +791,12 @@ } // Create the new dominator tree node... and set the idom of NewBB. - DomTreeNodeBase *NewBBNode = addNewBlock(NewBB, NewBBIDom); + TreeNode *NewBBNode = addNewBlock(NewBB, NewBBIDom); // If NewBB strictly dominates other blocks, then it is now the immediate // dominator of NewBBSucc. Update the dominator tree as appropriate. if (NewBBDominatesNewBBSucc) { - DomTreeNodeBase *NewBBSuccNode = getNode(NewBBSucc); + TreeNode *NewBBSuccNode = getNode(NewBBSucc); changeImmediateDominator(NewBBSuccNode, NewBBNode); } } diff --git a/llvm/include/llvm/Support/GenericDomTreeConstruction.h b/llvm/include/llvm/Support/GenericDomTreeConstruction.h --- a/llvm/include/llvm/Support/GenericDomTreeConstruction.h +++ b/llvm/include/llvm/Support/GenericDomTreeConstruction.h @@ -56,7 +56,7 @@ using CfgTraits = typename DomTreeT::CfgTraits; using NodePtr = typename DomTreeT::NodePtr; using NodeT = typename DomTreeT::NodeType; - using TreeNodePtr = DomTreeNodeBase *; + using TreeNodePtr = typename DomTreeT::TreeNode *; using RootsT = decltype(DomTreeT::Roots); static constexpr bool IsPostDom = DomTreeT::IsPostDominator;