From: Jakub Kuderski Date: Wed, 26 Jul 2017 18:27:39 +0000 (+0000) Subject: [Dominators] Change Roots type to SmallVector X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a65cddf557403bd39853a1a1fa6c212c703e9658;p=llvm [Dominators] Change Roots type to SmallVector Summary: We can use the template parameter `IsPostDom` to pick an appropriate SmallVector size to store DomTree roots for dominators and postdominators. Before, the code would always allocate memory with `std::vector`. Reviewers: dberlin, davide, sanjoy, grosser Reviewed By: grosser Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D35636 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@309148 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/Analysis/DominanceFrontier.h b/include/llvm/Analysis/DominanceFrontier.h index 4f29743636f..a304dff18c7 100644 --- a/include/llvm/Analysis/DominanceFrontier.h +++ b/include/llvm/Analysis/DominanceFrontier.h @@ -47,7 +47,8 @@ protected: using BlockTraits = GraphTraits; DomSetMapType Frontiers; - std::vector Roots; + // Postdominators can have multiple roots. + SmallVector Roots; static constexpr bool IsPostDominators = IsPostDom; public: @@ -56,9 +57,7 @@ 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). - inline const std::vector &getRoots() const { - return Roots; - } + const SmallVectorImpl &getRoots() const { return Roots; } BlockT *getRoot() const { assert(Roots.size() == 1 && "Should always have entry node!"); @@ -131,9 +130,9 @@ public: using DomSetType = typename DominanceFrontierBase::DomSetType; void analyze(DomTreeT &DT) { - this->Roots = DT.getRoots(); - assert(this->Roots.size() == 1 && + assert(DT.getRoots().size() == 1 && "Only one entry block for forward domfronts!"); + this->Roots = {DT.getRoot()}; calculate(DT, DT[this->Roots[0]]); } diff --git a/include/llvm/CodeGen/MachineDominanceFrontier.h b/include/llvm/CodeGen/MachineDominanceFrontier.h index 6efeefd9a72..ffbcc62bfa3 100644 --- a/include/llvm/CodeGen/MachineDominanceFrontier.h +++ b/include/llvm/CodeGen/MachineDominanceFrontier.h @@ -39,7 +39,7 @@ public: DominanceFrontierBase &getBase() { return Base; } - inline const std::vector &getRoots() const { + const SmallVectorImpl &getRoots() const { return Base.getRoots(); } diff --git a/include/llvm/CodeGen/MachineDominators.h b/include/llvm/CodeGen/MachineDominators.h index 8bf98f60649..98fdb51aae2 100644 --- a/include/llvm/CodeGen/MachineDominators.h +++ b/include/llvm/CodeGen/MachineDominators.h @@ -93,7 +93,7 @@ public: /// multiple blocks if we are computing post dominators. For forward /// dominators, this will always be a single block (the entry node). /// - inline const std::vector &getRoots() const { + inline const SmallVectorImpl &getRoots() const { applySplitCriticalEdges(); return DT->getRoots(); } diff --git a/include/llvm/CodeGen/MachinePostDominators.h b/include/llvm/CodeGen/MachinePostDominators.h index d29d2d85cb0..c6a41598ce3 100644 --- a/include/llvm/CodeGen/MachinePostDominators.h +++ b/include/llvm/CodeGen/MachinePostDominators.h @@ -37,7 +37,7 @@ public: FunctionPass *createMachinePostDominatorTreePass(); - const std::vector &getRoots() const { + const SmallVectorImpl &getRoots() const { return DT->getRoots(); } diff --git a/include/llvm/Support/GenericDomTree.h b/include/llvm/Support/GenericDomTree.h index b94310fd916..ae16354b316 100644 --- a/include/llvm/Support/GenericDomTree.h +++ b/include/llvm/Support/GenericDomTree.h @@ -220,7 +220,8 @@ class DominatorTreeBase { static constexpr bool IsPostDominator = IsPostDom; protected: - std::vector Roots; + // Dominators always have a single root, postdominators can have more. + SmallVector Roots; using DomTreeNodeMapType = DenseMap>>; @@ -264,7 +265,7 @@ class DominatorTreeBase { /// 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; } + const SmallVectorImpl &getRoots() const { return Roots; } /// isPostDominator - Returns true if analysis based of postdoms ///