From 3a61bfb027a623807a30adb496ab62203c9b4ba5 Mon Sep 17 00:00:00 2001 From: Florian Hahn Date: Wed, 9 Sep 2020 10:24:49 +0100 Subject: [PATCH] [DomTree] Use SmallVector instead of std::vector. Currentl DomTreeNodeBase is using std::vectot to store it's children. Using SmallVector should be more efficient in terms of compile-time. A size of 4 seems to be the sweet-spot in terms of compile-time, according to http://llvm-compile-time-tracker.com/compare.php?from=9933188c90615c9c264ebb69117f09726e909a25&to=d7a801d027648877b20f0e00e822a7a64c58d976&stat=instructions This results in the following geomean improvements ``` geomean insts max rss O3 -0.31 % +0.02 % ReleaseThinLTO -0.35 % -0.12 % ReleaseLTO -0.28 % -0.12 % O0 -0.06 % -0.02 % NewPM O3 -0.36 % +0.05 % ReleaseThinLTO (link only) -0.44 % -0.10 % ReleaseLTO-g (link only): -0.32 % -0.03 % ``` I am not sure if there's any other benefits of using std::vector over SmallVector. Reviewed By: kuhar, asbirlea Differential Revision: https://reviews.llvm.org/D87319 --- llvm/include/llvm/Support/GenericDomTree.h | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/llvm/include/llvm/Support/GenericDomTree.h b/llvm/include/llvm/Support/GenericDomTree.h index 76973f521042c..c77168432058a 100644 --- a/llvm/include/llvm/Support/GenericDomTree.h +++ b/llvm/include/llvm/Support/GenericDomTree.h @@ -38,7 +38,6 @@ #include #include #include -#include namespace llvm { @@ -61,7 +60,7 @@ template class DomTreeNodeBase { NodeT *TheBB; DomTreeNodeBase *IDom; unsigned Level; - std::vector Children; + SmallVector Children; mutable unsigned DFSNumIn = ~0; mutable unsigned DFSNumOut = ~0; @@ -69,9 +68,9 @@ template class DomTreeNodeBase { DomTreeNodeBase(NodeT *BB, DomTreeNodeBase *iDom) : TheBB(BB), IDom(iDom), Level(IDom ? IDom->Level + 1 : 0) {} - using iterator = typename std::vector::iterator; + using iterator = typename SmallVector::iterator; using const_iterator = - typename std::vector::const_iterator; + typename SmallVector::const_iterator; iterator begin() { return Children.begin(); } iterator end() { return Children.end(); } @@ -837,7 +836,7 @@ class DominatorTreeBase { "NewBB should have a single successor!"); NodeRef NewBBSucc = *GraphT::child_begin(NewBB); - std::vector PredBlocks; + SmallVector PredBlocks; for (auto Pred : children>(NewBB)) PredBlocks.push_back(Pred);