Skip to content

Commit 20e3379

Browse files
[ADT] Move llvm::identity into IndexedMap (NFC)
This patch moves llvm::identity to IndexedMap for two reasons: - llvm::identity is used only IndexedMap. - llvm::identity is not suitable for general use as it is not quite the same as std::identity despite the comments in identity.h. Also, this patch renames the class to IdentityIndex and places it in the "detail" namespace.
1 parent 8869a6e commit 20e3379

File tree

3 files changed

+20
-47
lines changed

3 files changed

+20
-47
lines changed

llvm/include/llvm/ADT/IndexedMap.h

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,25 @@
2020
#ifndef LLVM_ADT_INDEXEDMAP_H
2121
#define LLVM_ADT_INDEXEDMAP_H
2222

23-
#include "llvm/ADT/STLForwardCompat.h"
23+
#include "llvm/ADT/STLExtras.h"
2424
#include "llvm/ADT/SmallVector.h"
2525
#include <cassert>
2626

2727
namespace llvm {
2828

29-
template <typename T, typename ToIndexT = llvm::identity_cxx20>
29+
namespace detail {
30+
template <class Ty> struct IdentityIndex {
31+
using is_transparent = void;
32+
using argument_type = Ty;
33+
34+
Ty &operator()(Ty &self) const { return self; }
35+
const Ty &operator()(const Ty &self) const { return self; }
36+
};
37+
} // namespace detail
38+
39+
template <typename T, typename ToIndexT = detail::IdentityIndex<unsigned>>
3040
class IndexedMap {
41+
using IndexT = typename ToIndexT::argument_type;
3142
// Prefer SmallVector with zero inline storage over std::vector. IndexedMaps
3243
// can grow very large and SmallVector grows more efficiently as long as T
3344
// is trivially copyable.
@@ -42,17 +53,14 @@ class IndexedMap {
4253

4354
explicit IndexedMap(const T &val) : nullVal_(val) {}
4455

45-
template <typename IndexT> typename StorageT::reference operator[](IndexT n) {
46-
unsigned Index = toIndex_(n);
47-
assert(Index < storage_.size() && "index out of bounds!");
48-
return storage_[Index];
56+
typename StorageT::reference operator[](IndexT n) {
57+
assert(toIndex_(n) < storage_.size() && "index out of bounds!");
58+
return storage_[toIndex_(n)];
4959
}
5060

51-
template <typename IndexT>
5261
typename StorageT::const_reference operator[](IndexT n) const {
53-
unsigned Index = toIndex_(n);
54-
assert(Index < storage_.size() && "index out of bounds!");
55-
return storage_[Index];
62+
assert(toIndex_(n) < storage_.size() && "index out of bounds!");
63+
return storage_[toIndex_(n)];
5664
}
5765

5866
void reserve(typename StorageT::size_type s) { storage_.reserve(s); }
@@ -61,16 +69,13 @@ class IndexedMap {
6169

6270
void clear() { storage_.clear(); }
6371

64-
template <typename IndexT> void grow(IndexT n) {
72+
void grow(IndexT n) {
6573
unsigned NewSize = toIndex_(n) + 1;
6674
if (NewSize > storage_.size())
6775
resize(NewSize);
6876
}
6977

70-
template <typename IndexT> bool inBounds(IndexT n) const {
71-
unsigned Index = toIndex_(n);
72-
return Index < storage_.size();
73-
}
78+
bool inBounds(IndexT n) const { return toIndex_(n) < storage_.size(); }
7479

7580
typename StorageT::size_type size() const { return storage_.size(); }
7681
};

llvm/include/llvm/ADT/identity.h

Lines changed: 0 additions & 31 deletions
This file was deleted.

llvm/include/llvm/CodeGen/ScheduleDAGInstrs.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#include "llvm/ADT/PointerIntPair.h"
1919
#include "llvm/ADT/SmallVector.h"
2020
#include "llvm/ADT/SparseMultiSet.h"
21-
#include "llvm/ADT/identity.h"
2221
#include "llvm/Analysis/AliasAnalysis.h"
2322
#include "llvm/CodeGen/LiveRegUnits.h"
2423
#include "llvm/CodeGen/MachineBasicBlock.h"

0 commit comments

Comments
 (0)