[llvm] r309148 - [Dominators] Change Roots type to SmallVector
Jakub Kuderski via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 26 11:27:39 PDT 2017
Author: kuhar
Date: Wed Jul 26 11:27:39 2017
New Revision: 309148
URL: http://llvm.org/viewvc/llvm-project?rev=309148&view=rev
Log:
[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
Modified:
llvm/trunk/include/llvm/Analysis/DominanceFrontier.h
llvm/trunk/include/llvm/CodeGen/MachineDominanceFrontier.h
llvm/trunk/include/llvm/CodeGen/MachineDominators.h
llvm/trunk/include/llvm/CodeGen/MachinePostDominators.h
llvm/trunk/include/llvm/Support/GenericDomTree.h
Modified: llvm/trunk/include/llvm/Analysis/DominanceFrontier.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/DominanceFrontier.h?rev=309148&r1=309147&r2=309148&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Analysis/DominanceFrontier.h (original)
+++ llvm/trunk/include/llvm/Analysis/DominanceFrontier.h Wed Jul 26 11:27:39 2017
@@ -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]]);
}
Modified: llvm/trunk/include/llvm/CodeGen/MachineDominanceFrontier.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/MachineDominanceFrontier.h?rev=309148&r1=309147&r2=309148&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/MachineDominanceFrontier.h (original)
+++ llvm/trunk/include/llvm/CodeGen/MachineDominanceFrontier.h Wed Jul 26 11:27:39 2017
@@ -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();
}
Modified: llvm/trunk/include/llvm/CodeGen/MachineDominators.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/MachineDominators.h?rev=309148&r1=309147&r2=309148&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/MachineDominators.h (original)
+++ llvm/trunk/include/llvm/CodeGen/MachineDominators.h Wed Jul 26 11:27:39 2017
@@ -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();
}
Modified: llvm/trunk/include/llvm/CodeGen/MachinePostDominators.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/MachinePostDominators.h?rev=309148&r1=309147&r2=309148&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/MachinePostDominators.h (original)
+++ llvm/trunk/include/llvm/CodeGen/MachinePostDominators.h Wed Jul 26 11:27:39 2017
@@ -37,7 +37,7 @@ public:
FunctionPass *createMachinePostDominatorTreePass();
- const std::vector<MachineBasicBlock *> &getRoots() const {
+ const SmallVectorImpl<MachineBasicBlock *> &getRoots() const {
return DT->getRoots();
}
Modified: llvm/trunk/include/llvm/Support/GenericDomTree.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/GenericDomTree.h?rev=309148&r1=309147&r2=309148&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/GenericDomTree.h (original)
+++ llvm/trunk/include/llvm/Support/GenericDomTree.h Wed Jul 26 11:27:39 2017
@@ -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
///
More information about the llvm-commits
mailing list