Skip to content

Commit 071acd9

Browse files
jmorseyuxuanchen1997
authored andcommitted
[SSAUpdater] Avoid un-necessary SmallVector stores (#97820)
Summary: The default template for the generic IDF calculator fetching block-children will, by default: * Fetch the children range from the relevant `GraphTraits`, * Store all child nodes in a `SmallVector`, * Return that `SmallVector` into the IDF calculator. The only place this `SmallVector` is used is in a for-range loop... thus there's no reason why we can't just iterate over the child range from `GraphTraits`, instead of storing all the nodes locally then iterating over the local copy. (If the children of a node change during IDF calculation, everything is broken anyway). This yields a 0.14% debug-info build performance improvement on the compile time tracker, as InstrRefBasedLDV uses the SSA updater intensively on all functions. Test Plan: Reviewers: Subscribers: Tasks: Tags: Differential Revision: https://phabricator.intern.facebook.com/D60251734
1 parent cbd3a30 commit 071acd9

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

llvm/include/llvm/Support/GenericIteratedDominanceFrontier.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
#include "llvm/ADT/SmallPtrSet.h"
2727
#include "llvm/ADT/SmallVector.h"
28+
#include "llvm/ADT/iterator_range.h"
2829
#include "llvm/Support/GenericDomTree.h"
2930
#include <queue>
3031

@@ -37,9 +38,10 @@ namespace IDFCalculatorDetail {
3738
/// successors.
3839
template <class NodeTy, bool IsPostDom> struct ChildrenGetterTy {
3940
using NodeRef = typename GraphTraits<NodeTy *>::NodeRef;
40-
using ChildrenTy = SmallVector<NodeRef, 8>;
41+
using ChildIteratorType = typename GraphTraits<NodeTy *>::ChildIteratorType;
42+
using range = iterator_range<ChildIteratorType>;
4143

42-
ChildrenTy get(const NodeRef &N);
44+
range get(const NodeRef &N);
4345
};
4446

4547
} // end of namespace IDFCalculatorDetail
@@ -115,13 +117,12 @@ template <class NodeTy, bool IsPostDom> class IDFCalculatorBase {
115117
namespace IDFCalculatorDetail {
116118

117119
template <class NodeTy, bool IsPostDom>
118-
typename ChildrenGetterTy<NodeTy, IsPostDom>::ChildrenTy
120+
typename ChildrenGetterTy<NodeTy, IsPostDom>::range
119121
ChildrenGetterTy<NodeTy, IsPostDom>::get(const NodeRef &N) {
120122
using OrderedNodeTy =
121123
typename IDFCalculatorBase<NodeTy, IsPostDom>::OrderedNodeTy;
122124

123-
auto Children = children<OrderedNodeTy>(N);
124-
return {Children.begin(), Children.end()};
125+
return children<OrderedNodeTy>(N);
125126
}
126127

127128
} // end of namespace IDFCalculatorDetail

0 commit comments

Comments
 (0)