18
18
#define SWIFT_IRGEN_ADDRESS_H
19
19
20
20
#include " IRGen.h"
21
- #include " llvm/IR/Value .h"
21
+ #include " llvm/ADT/ilist .h"
22
22
#include " llvm/IR/Argument.h"
23
+ #include " llvm/IR/DerivedTypes.h"
23
24
#include " llvm/IR/Function.h"
24
25
#include " llvm/IR/Instruction.h"
25
- #include " llvm/ADT/ilist .h"
26
- #include " llvm/IR/DerivedTypes .h"
26
+ #include " llvm/IR/Type .h"
27
+ #include " llvm/IR/Value .h"
27
28
28
29
namespace swift {
29
30
namespace irgen {
@@ -39,6 +40,9 @@ class Address {
39
40
40
41
Address (llvm::Value *addr, llvm::Type *elementType, Alignment align)
41
42
: Addr(addr), ElementType(elementType), Align(align) {
43
+ if (addr == llvm::DenseMapInfo<llvm::Value *>::getEmptyKey () ||
44
+ llvm::DenseMapInfo<llvm::Value *>::getTombstoneKey ())
45
+ return ;
42
46
assert (llvm::cast<llvm::PointerType>(addr->getType ())
43
47
->isOpaqueOrPointeeTypeMatches (elementType) &&
44
48
" Incorrect pointer element type" );
@@ -63,6 +67,12 @@ class Address {
63
67
}
64
68
65
69
llvm::Type *getElementType () const { return ElementType; }
70
+
71
+ bool operator ==(Address RHS) const {
72
+ return Addr == RHS.Addr && ElementType == RHS.ElementType &&
73
+ Align == RHS.Align ;
74
+ }
75
+ bool operator !=(Address RHS) const { return !(*this == RHS); }
66
76
};
67
77
68
78
// / An address in memory together with the (possibly null) heap
@@ -139,9 +149,64 @@ class StackAddress {
139
149
llvm::Value *getExtraInfo () const { return ExtraInfo; }
140
150
141
151
bool isValid () const { return Addr.isValid (); }
152
+
153
+ bool operator ==(StackAddress RHS) const {
154
+ return Addr == RHS.Addr && ExtraInfo == RHS.ExtraInfo ;
155
+ }
156
+ bool operator !=(StackAddress RHS) const { return !(*this == RHS); }
142
157
};
143
158
144
159
} // end namespace irgen
145
160
} // end namespace swift
146
161
162
+ namespace llvm {
163
+ template <>
164
+ struct DenseMapInfo <swift::irgen::Address> {
165
+ static swift::irgen::Address getEmptyKey () {
166
+ return swift::irgen::Address (DenseMapInfo<llvm::Value *>::getEmptyKey (),
167
+ DenseMapInfo<llvm::Type *>::getEmptyKey (),
168
+ swift::irgen::Alignment (8 ));
169
+ }
170
+ static swift::irgen::Address getTombstoneKey () {
171
+ return swift::irgen::Address (DenseMapInfo<llvm::Value *>::getTombstoneKey (),
172
+ DenseMapInfo<llvm::Type *>::getTombstoneKey (),
173
+ swift::irgen::Alignment (8 ));
174
+ }
175
+ static unsigned getHashValue (swift::irgen::Address address) {
176
+ return detail::combineHashValue (
177
+ DenseMapInfo<llvm::Value *>::getHashValue (address.getAddress ()),
178
+ detail::combineHashValue (
179
+ DenseMapInfo<llvm::Type *>::getHashValue (address.getElementType ()),
180
+ DenseMapInfo<swift::irgen::Alignment::int_type>::getHashValue (
181
+ address.getAlignment ().getValue ())));
182
+ }
183
+ static bool isEqual (swift::irgen::Address LHS, swift::irgen::Address RHS) {
184
+ return LHS == RHS;
185
+ }
186
+ };
187
+ template <>
188
+ struct DenseMapInfo <swift::irgen::StackAddress> {
189
+ static swift::irgen::StackAddress getEmptyKey () {
190
+ return swift::irgen::StackAddress (
191
+ DenseMapInfo<swift::irgen::Address>::getEmptyKey (),
192
+ DenseMapInfo<llvm::Value *>::getEmptyKey ());
193
+ }
194
+ static swift::irgen::StackAddress getTombstoneKey () {
195
+ return swift::irgen::StackAddress (
196
+ DenseMapInfo<swift::irgen::Address>::getTombstoneKey (),
197
+ DenseMapInfo<llvm::Value *>::getTombstoneKey ());
198
+ }
199
+ static unsigned getHashValue (swift::irgen::StackAddress address) {
200
+ return detail::combineHashValue (
201
+ DenseMapInfo<swift::irgen::Address>::getHashValue (address.getAddress ()),
202
+ DenseMapInfo<swift::irgen::Alignment::int_type>::getHashValue (
203
+ address.getAlignment ().getValue ()));
204
+ }
205
+ static bool isEqual (swift::irgen::StackAddress LHS,
206
+ swift::irgen::StackAddress RHS) {
207
+ return LHS == RHS;
208
+ }
209
+ };
210
+ } // end namespace llvm
211
+
147
212
#endif
0 commit comments