[llvm] [SSAUpdater] Avoid un-necessary SmallVector stores (PR #97820)
Jeremy Morse via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 16 04:16:03 PDT 2024
https://github.com/jmorse updated https://github.com/llvm/llvm-project/pull/97820
>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 1/2] [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
>From 7e5b55574c8ff89c05dd5c4fd1a7fd1e47ac43ce Mon Sep 17 00:00:00 2001
From: Jeremy Morse <jeremy.morse at sony.com>
Date: Tue, 16 Jul 2024 12:15:07 +0100
Subject: [PATCH 2/2] clang-format
---
llvm/include/llvm/Support/GenericIteratedDominanceFrontier.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/llvm/include/llvm/Support/GenericIteratedDominanceFrontier.h b/llvm/include/llvm/Support/GenericIteratedDominanceFrontier.h
index a7a8b2cecaecc..cb18d5b0c265a 100644
--- a/llvm/include/llvm/Support/GenericIteratedDominanceFrontier.h
+++ b/llvm/include/llvm/Support/GenericIteratedDominanceFrontier.h
@@ -23,9 +23,9 @@
#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/ADT/iterator_range.h"
#include "llvm/Support/GenericDomTree.h"
#include <queue>
More information about the llvm-commits
mailing list