Skip to content

Commit 58abcf6

Browse files
[ADT] Modernize SparseMultiSet to use llvm::identity_cxx20 (NFC) (llvm#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.
1 parent 683e2bf commit 58abcf6

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

llvm/include/llvm/ADT/SparseMultiSet.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
#ifndef LLVM_ADT_SPARSEMULTISET_H
2222
#define LLVM_ADT_SPARSEMULTISET_H
2323

24+
#include "llvm/ADT/STLForwardCompat.h"
2425
#include "llvm/ADT/SmallVector.h"
2526
#include "llvm/ADT/SparseSet.h"
26-
#include "llvm/ADT/identity.h"
2727
#include <cassert>
2828
#include <cstdint>
2929
#include <cstdlib>
@@ -77,11 +77,12 @@ namespace llvm {
7777
/// intuitive and fast removal.
7878
///
7979
/// @tparam ValueT The type of objects in the set.
80+
/// @tparam KeyT The type of the key that identifies objects in the set.
8081
/// @tparam KeyFunctorT A functor that computes an unsigned index from KeyT.
8182
/// @tparam SparseT An unsigned integer type. See above.
8283
///
83-
template <typename ValueT, typename KeyFunctorT = identity<unsigned>,
84-
typename SparseT = uint8_t>
84+
template <typename ValueT, typename KeyT = unsigned,
85+
typename KeyFunctorT = identity_cxx20, typename SparseT = uint8_t>
8586
class SparseMultiSet {
8687
static_assert(std::is_unsigned_v<SparseT>,
8788
"SparseT must be an unsigned integer type");
@@ -112,7 +113,6 @@ class SparseMultiSet {
112113
bool isValid() const { return Prev != INVALID; }
113114
};
114115

115-
using KeyT = typename KeyFunctorT::argument_type;
116116
using DenseT = SmallVector<SMSNode, 8>;
117117
DenseT Dense;
118118
SparseT *Sparse = nullptr;

llvm/include/llvm/CodeGen/ScheduleDAGInstrs.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,16 @@ namespace llvm {
9090
/// allocated once for the pass. It can be cleared in constant time and reused
9191
/// without any frees.
9292
using RegUnit2SUnitsMap =
93-
SparseMultiSet<PhysRegSUOper, identity<unsigned>, uint16_t>;
93+
SparseMultiSet<PhysRegSUOper, unsigned, identity_cxx20, uint16_t>;
9494

9595
/// Track local uses of virtual registers. These uses are gathered by the DAG
9696
/// builder and may be consulted by the scheduler to avoid iterating an entire
9797
/// vreg use list.
98-
using VReg2SUnitMultiMap = SparseMultiSet<VReg2SUnit, VirtReg2IndexFunctor>;
98+
using VReg2SUnitMultiMap =
99+
SparseMultiSet<VReg2SUnit, Register, VirtReg2IndexFunctor>;
99100

100101
using VReg2SUnitOperIdxMultiMap =
101-
SparseMultiSet<VReg2SUnitOperIdx, VirtReg2IndexFunctor>;
102+
SparseMultiSet<VReg2SUnitOperIdx, Register, VirtReg2IndexFunctor>;
102103

103104
using ValueType = PointerUnion<const Value *, const PseudoSourceValue *>;
104105

0 commit comments

Comments
 (0)