@@ -56,8 +56,26 @@ class Identifier {
56
56
57
57
const char *Pointer;
58
58
59
+ public:
60
+ enum : size_t {
61
+ NumLowBitsAvailable = 2 ,
62
+ RequiredAlignment = 1 << NumLowBitsAvailable,
63
+ SpareBitMask = ((intptr_t )1 << NumLowBitsAvailable) - 1
64
+ };
65
+
66
+ private:
59
67
// / Constructor, only accessible by ASTContext, which handles the uniquing.
60
- explicit Identifier (const char *Ptr) : Pointer(Ptr) {}
68
+ explicit Identifier (const char *Ptr) : Pointer(Ptr) {
69
+ assert (((uintptr_t )Ptr & SpareBitMask) == 0
70
+ && " Identifier pointer does not use any spare bits" );
71
+ }
72
+
73
+ // / A type with the alignment expected of a valid \c Identifier::Pointer .
74
+ struct alignas (uint32_t ) Aligner {};
75
+
76
+ static_assert (alignof (Aligner) >= RequiredAlignment,
77
+ " Identifier table will provide enough spare bits" );
78
+
61
79
public:
62
80
explicit Identifier () : Pointer(nullptr ) {}
63
81
@@ -153,12 +171,15 @@ class Identifier {
153
171
bool operator <(Identifier RHS) const { return Pointer < RHS.Pointer ; }
154
172
155
173
static Identifier getEmptyKey () {
156
- return Identifier ((const char *)
157
- llvm::DenseMapInfo<const void *>::getEmptyKey ());
174
+ uintptr_t Val = static_cast <uintptr_t >(-1 );
175
+ Val <<= NumLowBitsAvailable;
176
+ return Identifier ((const char *)Val);
158
177
}
178
+
159
179
static Identifier getTombstoneKey () {
160
- return Identifier ((const char *)
161
- llvm::DenseMapInfo<const void *>::getTombstoneKey ());
180
+ uintptr_t Val = static_cast <uintptr_t >(-2 );
181
+ Val <<= NumLowBitsAvailable;
182
+ return Identifier ((const char *)Val);
162
183
}
163
184
164
185
private:
@@ -202,7 +223,7 @@ namespace llvm {
202
223
static inline swift::Identifier getFromVoidPointer (void *P) {
203
224
return swift::Identifier::getFromOpaquePointer (P);
204
225
}
205
- enum { NumLowBitsAvailable = 2 };
226
+ enum { NumLowBitsAvailable = swift::Identifier::NumLowBitsAvailable };
206
227
};
207
228
208
229
} // end namespace llvm
@@ -221,15 +242,15 @@ class DeclBaseName {
221
242
};
222
243
223
244
private:
224
- // / In a special DeclName represenenting a subscript, this opaque pointer
245
+ // / In a special DeclName representing a subscript, this opaque pointer
225
246
// / is used as the data of the base name identifier.
226
247
// / This is an implementation detail that should never leak outside of
227
248
// / DeclName.
228
- static void * SubscriptIdentifierData;
249
+ static const Identifier::Aligner SubscriptIdentifierData;
229
250
// / As above, for special constructor DeclNames.
230
- static void * ConstructorIdentifierData;
251
+ static const Identifier::Aligner ConstructorIdentifierData;
231
252
// / As above, for special destructor DeclNames.
232
- static void * DestructorIdentifierData;
253
+ static const Identifier::Aligner DestructorIdentifierData;
233
254
234
255
Identifier Ident;
235
256
@@ -239,23 +260,23 @@ class DeclBaseName {
239
260
DeclBaseName (Identifier I) : Ident(I) {}
240
261
241
262
static DeclBaseName createSubscript () {
242
- return DeclBaseName (Identifier ((const char *)SubscriptIdentifierData));
263
+ return DeclBaseName (Identifier ((const char *)& SubscriptIdentifierData));
243
264
}
244
265
245
266
static DeclBaseName createConstructor () {
246
- return DeclBaseName (Identifier ((const char *)ConstructorIdentifierData));
267
+ return DeclBaseName (Identifier ((const char *)& ConstructorIdentifierData));
247
268
}
248
269
249
270
static DeclBaseName createDestructor () {
250
- return DeclBaseName (Identifier ((const char *)DestructorIdentifierData));
271
+ return DeclBaseName (Identifier ((const char *)& DestructorIdentifierData));
251
272
}
252
273
253
274
Kind getKind () const {
254
- if (Ident.get () == SubscriptIdentifierData) {
275
+ if (Ident.get () == ( const char *)& SubscriptIdentifierData) {
255
276
return Kind::Subscript;
256
- } else if (Ident.get () == ConstructorIdentifierData) {
277
+ } else if (Ident.get () == ( const char *)& ConstructorIdentifierData) {
257
278
return Kind::Constructor;
258
- } else if (Ident.get () == DestructorIdentifierData) {
279
+ } else if (Ident.get () == ( const char *)& DestructorIdentifierData) {
259
280
return Kind::Destructor;
260
281
} else {
261
282
return Kind::Normal;
@@ -720,7 +741,7 @@ namespace llvm {
720
741
static inline swift::DeclName getFromVoidPointer (void *ptr) {
721
742
return swift::DeclName::getFromOpaqueValue (ptr);
722
743
}
723
- enum { NumLowBitsAvailable = 0 };
744
+ enum { NumLowBitsAvailable = PointerLikeTypeTraits<swift::DeclBaseName>::NumLowBitsAvailable - 2 };
724
745
};
725
746
726
747
// DeclNames hash just like pointers.
0 commit comments