[llvm] 4abdb85 - [SSAUpdater] Avoid un-necessary SmallVector stores (#97820)

via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 16 04:28:40 PDT 2024


Author: Jeremy Morse
Date: 2024-07-16T12:28:37+01:00
New Revision: 4abdb85ef2b659a0ee919a4509dd6a82901351b5

URL: https://github.com/llvm/llvm-project/commit/4abdb85ef2b659a0ee919a4509dd6a82901351b5
DIFF: https://github.com/llvm/llvm-project/commit/4abdb85ef2b659a0ee919a4509dd6a82901351b5.diff

LOG: [SSAUpdater] Avoid un-necessary SmallVector stores (#97820)

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.

Added: 
    

Modified: 
    llvm/include/llvm/Support/GenericIteratedDominanceFrontier.h

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/Support/GenericIteratedDominanceFrontier.h b/llvm/include/llvm/Support/GenericIteratedDominanceFrontier.h
index 0dc58e37c821d..cb18d5b0c265a 100644
--- a/llvm/include/llvm/Support/GenericIteratedDominanceFrontier.h
+++ b/llvm/include/llvm/Support/GenericIteratedDominanceFrontier.h
@@ -25,6 +25,7 @@
 
 #include "llvm/ADT/SmallPtrSet.h"
 #include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/iterator_range.h"
 #include "llvm/Support/GenericDomTree.h"
 #include <queue>
 
@@ -37,9 +38,10 @@ namespace IDFCalculatorDetail {
 /// successors.
 template <class NodeTy, bool IsPostDom> struct ChildrenGetterTy {
   using NodeRef = typename GraphTraits<NodeTy *>::NodeRef;
-  using ChildrenTy = SmallVector<NodeRef, 8>;
+  using ChildIteratorType = typename GraphTraits<NodeTy *>::ChildIteratorType;
+  using range = iterator_range<ChildIteratorType>;
 
-  ChildrenTy get(const NodeRef &N);
+  range get(const NodeRef &N);
 };
 
 } // end of namespace IDFCalculatorDetail
@@ -115,13 +117,12 @@ template <class NodeTy, bool IsPostDom> class IDFCalculatorBase {
 namespace IDFCalculatorDetail {
 
 template <class NodeTy, bool IsPostDom>
-typename ChildrenGetterTy<NodeTy, IsPostDom>::ChildrenTy
+typename ChildrenGetterTy<NodeTy, IsPostDom>::range
 ChildrenGetterTy<NodeTy, IsPostDom>::get(const NodeRef &N) {
   using OrderedNodeTy =
       typename IDFCalculatorBase<NodeTy, IsPostDom>::OrderedNodeTy;
 
-  auto Children = children<OrderedNodeTy>(N);
-  return {Children.begin(), Children.end()};
+  return children<OrderedNodeTy>(N);
 }
 
 } // end of namespace IDFCalculatorDetail


        


More information about the llvm-commits mailing list