LLVM: include/llvm/ADT/UniqueVector.h Source File (original) (raw)
1
2
3
4
5
6
7
8
9#ifndef LLVM_ADT_UNIQUEVECTOR_H
10#define LLVM_ADT_UNIQUEVECTOR_H
11
12#include
13#include
14#include
15#include
16
17namespace llvm {
18
19
20
21
22
23
25public:
27 using iterator = typename VectorType::iterator;
29
30private:
31
32 std::map<T, unsigned> Map;
33
34
36
37public:
38
39
41
42 unsigned &Val = Map[Entry];
43
44
45 if (Val) return Val;
46
47
48 Val = static_cast<unsigned>(Vector.size()) + 1;
49
50
51 Vector.push_back(Entry);
52 return Val;
53 }
54
55
56
57 unsigned idFor(const T &Entry) const {
58
59 typename std::map<T, unsigned>::const_iterator MI = Map.find(Entry);
60
61
62 if (MI != Map.end()) return MI->second;
63
64
65 return 0;
66 }
67
68
70 assert(ID-1 < size() && "ID is 0 or out of range!");
71 return Vector[ID - 1];
72 }
73
74
76
77
79
80
82
83
85
86
87 size_t size() const { return Vector.size(); }
88
89
90 bool empty() const { return Vector.empty(); }
91
92
94 Map.clear();
95 Vector.resize(0, 0);
96 }
97};
98
99}
100
101#endif
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
UniqueVector - This class produces a sequential ID number (base 1) for each unique entry that is adde...
Definition UniqueVector.h:24
typename VectorType::const_iterator const_iterator
Definition UniqueVector.h:28
unsigned insert(const T &Entry)
insert - Append entry to the vector if it doesn't already exist.
Definition UniqueVector.h:40
const_iterator begin() const
Return an iterator to the start of the vector.
Definition UniqueVector.h:78
const T & operator[](unsigned ID) const
operator[] - Returns a reference to the entry with the specified ID.
Definition UniqueVector.h:69
typename std::vector< T > VectorType
Definition UniqueVector.h:26
size_t size() const
size - Returns the number of entries in the vector.
Definition UniqueVector.h:87
iterator end()
Return an iterator to the end of the vector.
Definition UniqueVector.h:81
typename VectorType::iterator iterator
Definition UniqueVector.h:27
bool empty() const
empty - Returns true if the vector is empty.
Definition UniqueVector.h:90
unsigned idFor(const T &Entry) const
idFor - return the ID for an existing entry.
Definition UniqueVector.h:57
void reset()
reset - Clears all the entries.
Definition UniqueVector.h:93
iterator begin()
Return an iterator to the start of the vector.
Definition UniqueVector.h:75
const_iterator end() const
Return an iterator to the end of the vector.
Definition UniqueVector.h:84
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
This is an optimization pass for GlobalISel generic memory operations.