]> granicus.if.org Git - llvm/commitdiff
[Dominators] Change Roots type to SmallVector
authorJakub Kuderski <kubakuderski@gmail.com>
Wed, 26 Jul 2017 18:27:39 +0000 (18:27 +0000)
committerJakub Kuderski <kubakuderski@gmail.com>
Wed, 26 Jul 2017 18:27:39 +0000 (18:27 +0000)
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

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 4f29743636f38ecf8f90b12f99a764a6bc71d871..a304dff18c79029d771008378f7e74058db687ec 100644 (file)
@@ -47,7 +47,8 @@ protected:
   using BlockTraits = GraphTraits<BlockT *>;
 
   DomSetMapType Frontiers;
-  std::vector<BlockT *> Roots;
+  // Postdominators can have multiple roots.
+  SmallVector<BlockT *, IsPostDom ? 4 : 1> 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<BlockT *> &getRoots() const {
-    return Roots;
-  }
+  const SmallVectorImpl<BlockT *> &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<BlockT, false>::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]]);
   }
 
index 6efeefd9a721724dbd94a1260411f340097198b5..ffbcc62bfa36bedd564985187eead61d16d843e1 100644 (file)
@@ -39,7 +39,7 @@ public:
 
  DominanceFrontierBase<MachineBasicBlock, false> &getBase() { return Base; }
 
inline const std::vector<MachineBasicBlock *> &getRoots() const {
 const SmallVectorImpl<MachineBasicBlock *> &getRoots() const {
    return Base.getRoots();
   }
 
index 8bf98f606495620af95104520dfb35390a39562a..98fdb51aae2fd54f3320d85ec9e051b0fe130e63 100644 (file)
@@ -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<MachineBasicBlock*> &getRoots() const {
+  inline const SmallVectorImpl<MachineBasicBlock*> &getRoots() const {
     applySplitCriticalEdges();
     return DT->getRoots();
   }
index d29d2d85cb0a57fdb559731fe02558539a823cd2..c6a41598ce32c2697085b57d8d7c02d1fa5e103f 100644 (file)
@@ -37,7 +37,7 @@ public:
 
   FunctionPass *createMachinePostDominatorTreePass();
 
-  const std::vector<MachineBasicBlock *> &getRoots() const {
+  const SmallVectorImpl<MachineBasicBlock *> &getRoots() const {
     return DT->getRoots();
   }
 
index b94310fd9162f1b0d1d9d5b0eecf7ba17335f28f..ae16354b316ffeabeb3c8cd6ad34a0b5fc103787 100644 (file)
@@ -220,7 +220,8 @@ class DominatorTreeBase {
   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 @@ 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<NodeT *> &getRoots() const { return Roots; }
+  const SmallVectorImpl<NodeT *> &getRoots() const { return Roots; }
 
   /// isPostDominator - Returns true if analysis based of postdoms
   ///