[PATCH] D35636: [Dominators] Change Roots type to SmallVector

Jakub Kuderski via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 19 10:50:23 PDT 2017


kuhar created this revision.

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`.


https://reviews.llvm.org/D35636

Files:
  include/llvm/Analysis/DominanceFrontier.h
  include/llvm/CodeGen/MachineDominanceFrontier.h
  include/llvm/CodeGen/MachineDominators.h
  include/llvm/CodeGen/MachinePostDominators.h
  include/llvm/Support/GenericDomTree.h


Index: include/llvm/Support/GenericDomTree.h
===================================================================
--- include/llvm/Support/GenericDomTree.h
+++ include/llvm/Support/GenericDomTree.h
@@ -220,7 +220,8 @@
   static constexpr bool IsPostDominator = IsPostDom;
 
  protected:
-  std::vector<NodeT *> Roots;
+  // Dominators always have a single root, postdominators can have more.
+  SmallVector<NodeT *, IsPostDom ? 4 : 1> Roots;
 
   using DomTreeNodeMapType =
      DenseMap<NodeT *, std::unique_ptr<DomTreeNodeBase<NodeT>>>;
@@ -264,7 +265,7 @@
   /// multiple blocks if we are computing post dominators.  For forward
   /// dominators, this will always be a single block (the entry node).
   ///
-  const std::vector<NodeT *> &getRoots() const { return Roots; }
+  const SmallVectorImpl<NodeT *> &getRoots() const { return Roots; }
 
   /// isPostDominator - Returns true if analysis based of postdoms
   ///
Index: include/llvm/CodeGen/MachinePostDominators.h
===================================================================
--- include/llvm/CodeGen/MachinePostDominators.h
+++ include/llvm/CodeGen/MachinePostDominators.h
@@ -37,7 +37,7 @@
 
   FunctionPass *createMachinePostDominatorTreePass();
 
-  const std::vector<MachineBasicBlock *> &getRoots() const {
+  const SmallVectorImpl<MachineBasicBlock *> &getRoots() const {
     return DT->getRoots();
   }
 
Index: include/llvm/CodeGen/MachineDominators.h
===================================================================
--- include/llvm/CodeGen/MachineDominators.h
+++ include/llvm/CodeGen/MachineDominators.h
@@ -93,7 +93,7 @@
   /// 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<MachineBasicBlock*> &getRoots() const {
+  inline const SmallVectorImpl<MachineBasicBlock*> &getRoots() const {
     applySplitCriticalEdges();
     return DT->getRoots();
   }
Index: include/llvm/CodeGen/MachineDominanceFrontier.h
===================================================================
--- include/llvm/CodeGen/MachineDominanceFrontier.h
+++ include/llvm/CodeGen/MachineDominanceFrontier.h
@@ -39,7 +39,7 @@
 
  DominanceFrontierBase<MachineBasicBlock, false> &getBase() { return Base; }
 
- inline const std::vector<MachineBasicBlock *> &getRoots() const {
+  const SmallVectorImpl<MachineBasicBlock *> &getRoots() const {
    return Base.getRoots();
   }
 
Index: include/llvm/Analysis/DominanceFrontier.h
===================================================================
--- include/llvm/Analysis/DominanceFrontier.h
+++ include/llvm/Analysis/DominanceFrontier.h
@@ -39,7 +39,8 @@
   typedef GraphTraits<BlockT *> BlockTraits;
 
   DomSetMapType Frontiers;
-  std::vector<BlockT *> Roots;
+  // Postdominators can have multiple roots.
+  SmallVector<BlockT *, IsPostDom ? 4 : 1> Roots;
   static constexpr bool IsPostDominators = IsPostDom;
 
  public:
@@ -49,9 +50,7 @@
   /// 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<BlockT *> &getRoots() const {
-    return Roots;
-  }
+  const SmallVectorImpl<BlockT *> &getRoots() const { return Roots; }
 
   BlockT *getRoot() const {
     assert(Roots.size() == 1 && "Should always have entry node!");
@@ -124,9 +123,9 @@
  typedef typename DominanceFrontierBase<BlockT, false>::DomSetType 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]]);
   }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D35636.107344.patch
Type: text/x-patch
Size: 3763 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170719/7e65b990/attachment-0001.bin>


More information about the llvm-commits mailing list