[llvm] [ADT] Modernize SparseMultiSet to use llvm::identity_cxx20 (NFC) (PR #164361)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 20 22:57:50 PDT 2025
https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/164361
The legacy llvm::identity is not quite the same as std::identity from
C++20. llvm::identity is a template struct with an ::argument_type
member. In contrast, llvm::identity_cxx20 (and std::identity) is a
non-template struct with a templated call operator and no
::argument_type.
This patch modernizes llvm::SparseMultiSet by updating its default
key-extraction functor to llvm::identity_cxx20. A new template
parameter KeyT takes over the role of ::argument_type.
Existing uses of SparseMultiSet are updated for the new template
signature.
>From d8c091ea92b92c24757634de14a60c0016ecc22a Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Mon, 20 Oct 2025 09:14:26 -0700
Subject: [PATCH] [ADT] Modernize SparseMultiSet to use llvm::identity_cxx20
(NFC)
The legacy llvm::identity is not quite the same as std::identity from
C++20. llvm::identity is a template struct with an ::argument_type
member. In contrast, llvm::identity_cxx20 (and std::identity) is a
non-template struct with a templated call operator and no
::argument_type.
This patch modernizes llvm::SparseMultiSet by updating its default
key-extraction functor to llvm::identity_cxx20. A new template
parameter KeyT takes over the role of ::argument_type.
Existing uses of SparseMultiSet are updated for the new template
signature.
---
llvm/include/llvm/ADT/SparseMultiSet.h | 8 ++++----
llvm/include/llvm/CodeGen/ScheduleDAGInstrs.h | 7 ++++---
2 files changed, 8 insertions(+), 7 deletions(-)
diff --git a/llvm/include/llvm/ADT/SparseMultiSet.h b/llvm/include/llvm/ADT/SparseMultiSet.h
index 0aa7edbcea673..5e4e1703373a9 100644
--- a/llvm/include/llvm/ADT/SparseMultiSet.h
+++ b/llvm/include/llvm/ADT/SparseMultiSet.h
@@ -21,9 +21,9 @@
#ifndef LLVM_ADT_SPARSEMULTISET_H
#define LLVM_ADT_SPARSEMULTISET_H
+#include "llvm/ADT/STLForwardCompat.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/SparseSet.h"
-#include "llvm/ADT/identity.h"
#include <cassert>
#include <cstdint>
#include <cstdlib>
@@ -77,11 +77,12 @@ namespace llvm {
/// intuitive and fast removal.
///
/// @tparam ValueT The type of objects in the set.
+/// @tparam KeyT The type of the key that identifies objects in the set.
/// @tparam KeyFunctorT A functor that computes an unsigned index from KeyT.
/// @tparam SparseT An unsigned integer type. See above.
///
-template <typename ValueT, typename KeyFunctorT = identity<unsigned>,
- typename SparseT = uint8_t>
+template <typename ValueT, typename KeyT = unsigned,
+ typename KeyFunctorT = identity_cxx20, typename SparseT = uint8_t>
class SparseMultiSet {
static_assert(std::is_unsigned_v<SparseT>,
"SparseT must be an unsigned integer type");
@@ -112,7 +113,6 @@ class SparseMultiSet {
bool isValid() const { return Prev != INVALID; }
};
- using KeyT = typename KeyFunctorT::argument_type;
using DenseT = SmallVector<SMSNode, 8>;
DenseT Dense;
SparseT *Sparse = nullptr;
diff --git a/llvm/include/llvm/CodeGen/ScheduleDAGInstrs.h b/llvm/include/llvm/CodeGen/ScheduleDAGInstrs.h
index ba5b2da64fd80..4eacbdca163d9 100644
--- a/llvm/include/llvm/CodeGen/ScheduleDAGInstrs.h
+++ b/llvm/include/llvm/CodeGen/ScheduleDAGInstrs.h
@@ -90,15 +90,16 @@ namespace llvm {
/// allocated once for the pass. It can be cleared in constant time and reused
/// without any frees.
using RegUnit2SUnitsMap =
- SparseMultiSet<PhysRegSUOper, identity<unsigned>, uint16_t>;
+ SparseMultiSet<PhysRegSUOper, unsigned, identity_cxx20, uint16_t>;
/// Track local uses of virtual registers. These uses are gathered by the DAG
/// builder and may be consulted by the scheduler to avoid iterating an entire
/// vreg use list.
- using VReg2SUnitMultiMap = SparseMultiSet<VReg2SUnit, VirtReg2IndexFunctor>;
+ using VReg2SUnitMultiMap =
+ SparseMultiSet<VReg2SUnit, Register, VirtReg2IndexFunctor>;
using VReg2SUnitOperIdxMultiMap =
- SparseMultiSet<VReg2SUnitOperIdx, VirtReg2IndexFunctor>;
+ SparseMultiSet<VReg2SUnitOperIdx, Register, VirtReg2IndexFunctor>;
using ValueType = PointerUnion<const Value *, const PseudoSourceValue *>;
More information about the llvm-commits
mailing list