From 40f59b8596cf168759948b15a1c0701531087a32 Mon Sep 17 00:00:00 2001 From: Jakub Kuderski Date: Wed, 26 Jul 2017 18:27:39 +0000 Subject: [PATCH] [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 llvm-svn: 309148 --- llvm/include/llvm/Analysis/DominanceFrontier.h | 11 +++++------ llvm/include/llvm/CodeGen/MachineDominanceFrontier.h | 2 +- llvm/include/llvm/CodeGen/MachineDominators.h | 2 +- llvm/include/llvm/CodeGen/MachinePostDominators.h | 2 +- llvm/include/llvm/Support/GenericDomTree.h | 5 +++-- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/llvm/include/llvm/Analysis/DominanceFrontier.h b/llvm/include/llvm/Analysis/DominanceFrontier.h index 4f29743..a304dff 100644 --- a/llvm/include/llvm/Analysis/DominanceFrontier.h +++ b/llvm/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/llvm/include/llvm/CodeGen/MachineDominanceFrontier.h b/llvm/include/llvm/CodeGen/MachineDominanceFrontier.h index 6efeefd..ffbcc62 100644 --- a/llvm/include/llvm/CodeGen/MachineDominanceFrontier.h +++ b/llvm/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/llvm/include/llvm/CodeGen/MachineDominators.h b/llvm/include/llvm/CodeGen/MachineDominators.h index 8bf98f6..98fdb51 100644 --- a/llvm/include/llvm/CodeGen/MachineDominators.h +++ b/llvm/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/llvm/include/llvm/CodeGen/MachinePostDominators.h b/llvm/include/llvm/CodeGen/MachinePostDominators.h index d29d2d8..c6a4159 100644 --- a/llvm/include/llvm/CodeGen/MachinePostDominators.h +++ b/llvm/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/llvm/include/llvm/Support/GenericDomTree.h b/llvm/include/llvm/Support/GenericDomTree.h index b94310f..ae16354 100644 --- a/llvm/include/llvm/Support/GenericDomTree.h +++ b/llvm/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 /// -- 2.7.4