Skip to content

Commit 4098e26

Browse files
[ADT] Modernize SparseSet to use llvm::identity_cxx20 (NFC) (llvm#164362)
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::SparseSet 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 SparseSet are updated for the new template signature. Most use sites are of the form SparseSet<T>, requiring no update.
1 parent 58abcf6 commit 4098e26

File tree

5 files changed

+8
-8
lines changed

5 files changed

+8
-8
lines changed

llvm/include/llvm/ADT/SparseSet.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
#ifndef LLVM_ADT_SPARSESET_H
2121
#define LLVM_ADT_SPARSESET_H
2222

23+
#include "llvm/ADT/STLForwardCompat.h"
2324
#include "llvm/ADT/SmallVector.h"
24-
#include "llvm/ADT/identity.h"
2525
#include "llvm/Support/AllocatorBase.h"
2626
#include <cassert>
2727
#include <cstdint>
@@ -112,16 +112,16 @@ struct SparseSetValFunctor<KeyT, KeyT, KeyFunctorT> {
112112
/// uint16_t or uint32_t.
113113
///
114114
/// @tparam ValueT The type of objects in the set.
115+
/// @tparam KeyT The type of the key, which is passed to the key functor.
115116
/// @tparam KeyFunctorT A functor that computes an unsigned index from KeyT.
116117
/// @tparam SparseT An unsigned integer type. See above.
117118
///
118-
template <typename ValueT, typename KeyFunctorT = identity<unsigned>,
119-
typename SparseT = uint8_t>
119+
template <typename ValueT, typename KeyT = unsigned,
120+
typename KeyFunctorT = identity_cxx20, typename SparseT = uint8_t>
120121
class SparseSet {
121122
static_assert(std::is_unsigned_v<SparseT>,
122123
"SparseT must be an unsigned integer type");
123124

124-
using KeyT = typename KeyFunctorT::argument_type;
125125
using DenseT = SmallVector<ValueT, 8>;
126126
using size_type = unsigned;
127127
DenseT Dense;

llvm/include/llvm/CodeGen/LivePhysRegs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class raw_ostream;
5151
/// when walking backward/forward through a basic block.
5252
class LivePhysRegs {
5353
const TargetRegisterInfo *TRI = nullptr;
54-
using RegisterSet = SparseSet<MCPhysReg, identity<MCPhysReg>>;
54+
using RegisterSet = SparseSet<MCPhysReg, MCPhysReg>;
5555
RegisterSet LiveRegs;
5656

5757
public:

llvm/include/llvm/CodeGen/RegisterPressure.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ class RegPressureTracker {
393393
LiveRegSet LiveRegs;
394394

395395
/// Set of vreg defs that start a live range.
396-
SparseSet<Register, VirtReg2IndexFunctor> UntiedDefs;
396+
SparseSet<Register, Register, VirtReg2IndexFunctor> UntiedDefs;
397397
/// Live-through pressure.
398398
std::vector<unsigned> LiveThruPressure;
399399

llvm/lib/CodeGen/IfConversion.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1498,7 +1498,7 @@ static void UpdatePredRedefs(MachineInstr &MI, LivePhysRegs &Redefs) {
14981498
// Before stepping forward past MI, remember which regs were live
14991499
// before MI. This is needed to set the Undef flag only when reg is
15001500
// dead.
1501-
SparseSet<MCPhysReg, identity<MCPhysReg>> LiveBeforeMI;
1501+
SparseSet<MCPhysReg, MCPhysReg> LiveBeforeMI;
15021502
LiveBeforeMI.setUniverse(TRI->getNumRegs());
15031503
for (unsigned Reg : Redefs)
15041504
LiveBeforeMI.insert(Reg);

llvm/lib/CodeGen/RegAllocFast.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ class RegAllocFastImpl {
211211
unsigned getSparseSetIndex() const { return VirtReg.virtRegIndex(); }
212212
};
213213

214-
using LiveRegMap = SparseSet<LiveReg, identity<unsigned>, uint16_t>;
214+
using LiveRegMap = SparseSet<LiveReg, unsigned, identity_cxx20, uint16_t>;
215215
/// This map contains entries for each virtual register that is currently
216216
/// available in a physical register.
217217
LiveRegMap LiveVirtRegs;

0 commit comments

Comments
 (0)