From 35fca341326a0ae09d961876c3201412e9299721 Mon Sep 17 00:00:00 2001 From: Jakub Kuderski Date: Thu, 29 Jun 2017 17:50:19 +0000 Subject: [PATCH] [Dominators] Remove DominatorBase class Summary: DominatorBase class was only used by DominatorTreeBase. It didn't provide any useful abstractions, nor simplified anything, so I see no point keeping it. This commit removes the DominatorBase class and moves its content into DominatorTreeBase. This is the first patch in a series that tries to make all DomTrees have a single virtual root, which will allow to further simplify code (especially when it comes to incremental updates). Reviewers: dberlin, sanjoy, chandlerc Reviewed By: dberlin Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D34493 llvm-svn: 306713 --- llvm/include/llvm/Support/GenericDomTree.h | 61 +++++++--------------- 1 file changed, 19 insertions(+), 42 deletions(-) diff --git a/llvm/include/llvm/Support/GenericDomTree.h b/llvm/include/llvm/Support/GenericDomTree.h index e8f87fc142ec..664788086833 100644 --- a/llvm/include/llvm/Support/GenericDomTree.h +++ b/llvm/include/llvm/Support/GenericDomTree.h @@ -58,40 +58,6 @@ template using DominatorTreeBaseByGraphTraits = typename detail::DominatorTreeBaseTraits::type; -/// \brief Base class that other, more interesting dominator analyses -/// inherit from. -template class DominatorBase { -protected: - std::vector Roots; - bool IsPostDominators; - - explicit DominatorBase(bool isPostDom) - : Roots(), IsPostDominators(isPostDom) {} - - DominatorBase(DominatorBase &&Arg) - : Roots(std::move(Arg.Roots)), IsPostDominators(Arg.IsPostDominators) { - Arg.Roots.clear(); - } - - DominatorBase &operator=(DominatorBase &&RHS) { - Roots = std::move(RHS.Roots); - IsPostDominators = RHS.IsPostDominators; - RHS.Roots.clear(); - return *this; - } - -public: - /// getRoots - Return the root blocks of the current CFG. This may include - /// multiple blocks if we are computing post dominators. For forward - /// dominators, this will always be a single block (the entry node). - /// - const std::vector &getRoots() const { return Roots; } - - /// isPostDominator - Returns true if analysis based of postdoms - /// - bool isPostDominator() const { return IsPostDominators; } -}; - /// \brief Base class for the actual dominator tree node. template class DomTreeNodeBase { friend struct PostDominatorTree; @@ -218,7 +184,7 @@ bool Verify(const DominatorTreeBaseByGraphTraits> &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 { +template class DominatorTreeBase { bool dominatedBySlowTreeWalk(const DomTreeNodeBase *A, const DomTreeNodeBase *B) const { assert(A != B); @@ -241,6 +207,9 @@ template class DominatorTreeBase : public DominatorBase { } protected: + std::vector Roots; + bool IsPostDominators; + using DomTreeNodeMapType = DenseMap>>; DomTreeNodeMapType DomTreeNodes; @@ -316,12 +285,11 @@ protected: } public: - explicit DominatorTreeBase(bool isPostDom) - : DominatorBase(isPostDom) {} + explicit DominatorTreeBase(bool isPostDom) : IsPostDominators(isPostDom) {} DominatorTreeBase(DominatorTreeBase &&Arg) - : DominatorBase( - std::move(static_cast &>(Arg))), + : Roots(std::move(Arg.Roots)), + IsPostDominators(Arg.IsPostDominators), DomTreeNodes(std::move(Arg.DomTreeNodes)), RootNode(std::move(Arg.RootNode)), DFSInfoValid(std::move(Arg.DFSInfoValid)), @@ -330,8 +298,8 @@ public: } DominatorTreeBase &operator=(DominatorTreeBase &&RHS) { - DominatorBase::operator=( - std::move(static_cast &>(RHS))); + Roots = std::move(RHS.Roots); + IsPostDominators = RHS.IsPostDominators; DomTreeNodes = std::move(RHS.DomTreeNodes); RootNode = std::move(RHS.RootNode); DFSInfoValid = std::move(RHS.DFSInfoValid); @@ -343,6 +311,16 @@ public: DominatorTreeBase(const DominatorTreeBase &) = delete; DominatorTreeBase &operator=(const DominatorTreeBase &) = delete; + /// getRoots - Return the root blocks of the current CFG. This may include + /// multiple blocks if we are computing post dominators. For forward + /// dominators, this will always be a single block (the entry node). + /// + const std::vector &getRoots() const { return Roots; } + + /// isPostDominator - Returns true if analysis based of postdoms + /// + bool isPostDominator() const { return IsPostDominators; } + /// compare - Return false if the other dominator tree base matches this /// dominator tree base. Otherwise return true. bool compare(const DominatorTreeBase &Other) const { @@ -580,7 +558,6 @@ public: assert(!this->isPostDominator() && "Cannot change root of post-dominator tree"); DFSInfoValid = false; - auto &Roots = DominatorBase::Roots; DomTreeNodeBase *NewNode = (DomTreeNodes[BB] = llvm::make_unique>(BB, nullptr)).get(); if (Roots.empty()) {