[llvm] [SSAUpdater] Avoid un-necessary SmallVector stores (PR #97820)
Jeremy Morse via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 5 05:13:14 PDT 2024
https://github.com/jmorse created https://github.com/llvm/llvm-project/pull/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.
http://llvm-compile-time-tracker.com/compare.php?from=a9f1d377013b1d208ac58f6f75548f1f24d174d2&to=e73fd09de063a113a387c09b561cb3ccfc50e35b&stat=instructions:u
>From 3d5f9ee7c95a4fb1323cba16b50b24e5117831ce Mon Sep 17 00:00:00 2001
From: Jeremy Morse <jeremy.morse at sony.com>
Date: Thu, 4 Jul 2024 15:02:19 +0000
Subject: [PATCH] [SSAUpdater] Avoid un-necessary SmallVector stores
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.15% debug-info build performance improvement on the compile
time tracker, as InstrRefBasedLDV uses the SSA updater intensively on all
functions.
---
.../llvm/Support/GenericIteratedDominanceFrontier.h | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/llvm/include/llvm/Support/GenericIteratedDominanceFrontier.h b/llvm/include/llvm/Support/GenericIteratedDominanceFrontier.h
index 0dc58e37c821d..a7a8b2cecaecc 100644
--- a/llvm/include/llvm/Support/GenericIteratedDominanceFrontier.h
+++ b/llvm/include/llvm/Support/GenericIteratedDominanceFrontier.h
@@ -23,6 +23,7 @@
#ifndef LLVM_SUPPORT_GENERICITERATEDDOMINANCEFRONTIER_H
#define LLVM_SUPPORT_GENERICITERATEDDOMINANCEFRONTIER_H
+#include "llvm/ADT/iterator_range.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/Support/GenericDomTree.h"
@@ -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