@@ -47,6 +47,7 @@ class AvailabilityDomain final {
47
47
48
48
private:
49
49
friend struct llvm ::PointerLikeTypeTraits<AvailabilityDomain>;
50
+ friend struct llvm ::DenseMapInfo<AvailabilityDomain>;
50
51
51
52
// / For a subset of domain kinds, all the information needed to represent the
52
53
// / domain can be encapsulated inline in this class.
@@ -57,7 +58,8 @@ class AvailabilityDomain final {
57
58
public:
58
59
using IntReprType = uint32_t ;
59
60
enum : uintptr_t {
60
- ReprBits = sizeof (IntReprType) * CHAR_BIT - 8 ,
61
+ SpareBits = 8 ,
62
+ ReprBits = sizeof (IntReprType) * CHAR_BIT - SpareBits,
61
63
KindShift = ReprBits - sizeof (Kind) * CHAR_BIT,
62
64
PlatformShift = KindShift - sizeof (PlatformKind) * CHAR_BIT,
63
65
};
@@ -83,7 +85,8 @@ class AvailabilityDomain final {
83
85
// / defined availability domains.
84
86
using ExternalDomain = void ;
85
87
86
- using InlineDomainPtr = llvm::PointerEmbeddedInt<uint32_t , InlineDomain::ReprBits>;
88
+ using InlineDomainPtr =
89
+ llvm::PointerEmbeddedInt<uint32_t , InlineDomain::ReprBits>;
87
90
using Storage = llvm::PointerUnion<ExternalDomain *, InlineDomainPtr>;
88
91
Storage storage;
89
92
@@ -95,8 +98,11 @@ class AvailabilityDomain final {
95
98
AvailabilityDomain (PlatformKind platform)
96
99
: storage(InlineDomain(Kind::Platform, platform).asInteger()) {};
97
100
98
- AvailabilityDomain (void *opaque)
99
- : storage(Storage::getFromOpaqueValue(opaque)) {};
101
+ AvailabilityDomain (Storage storage) : storage(storage) {};
102
+
103
+ static AvailabilityDomain fromOpaque (void *opaque) {
104
+ return AvailabilityDomain (Storage::getFromOpaqueValue (opaque));
105
+ }
100
106
101
107
void *getOpaqueValue () const { return storage.getOpaqueValue (); }
102
108
@@ -163,18 +169,7 @@ class AvailabilityDomain final {
163
169
llvm::StringRef getNameForAttributePrinting () const ;
164
170
165
171
bool operator ==(const AvailabilityDomain &other) const {
166
- if (getKind () != other.getKind ())
167
- return false ;
168
-
169
- switch (getKind ()) {
170
- case Kind::Universal:
171
- case Kind::SwiftLanguage:
172
- case Kind::PackageDescription:
173
- // These availability domains are singletons.
174
- return true ;
175
- case Kind::Platform:
176
- return getPlatformKind () == other.getPlatformKind ();
177
- }
172
+ return storage.getOpaqueValue () == other.storage .getOpaqueValue ();
178
173
}
179
174
180
175
bool operator !=(const AvailabilityDomain &other) const {
@@ -200,24 +195,40 @@ class AvailabilityDomain final {
200
195
} // end namespace swift
201
196
202
197
namespace llvm {
198
+ using swift::AvailabilityDomain;
199
+
203
200
// An AvailabilityDomain is "pointer like".
204
201
template <typename T>
205
202
struct PointerLikeTypeTraits ;
206
203
template <>
207
204
struct PointerLikeTypeTraits <swift::AvailabilityDomain> {
208
205
public:
209
- static inline void *getAsVoidPointer (swift:: AvailabilityDomain domain) {
206
+ static inline void *getAsVoidPointer (AvailabilityDomain domain) {
210
207
return domain.storage .getOpaqueValue ();
211
208
}
212
209
static inline swift::AvailabilityDomain getFromVoidPointer (void *P) {
213
- return swift::AvailabilityDomain (P);
210
+ return AvailabilityDomain::fromOpaque (P);
214
211
}
215
212
enum {
216
- NumLowBitsAvailable = PointerLikeTypeTraits<
217
- swift:: AvailabilityDomain::Storage>::NumLowBitsAvailable
213
+ NumLowBitsAvailable =
214
+ PointerLikeTypeTraits< AvailabilityDomain::Storage>::NumLowBitsAvailable
218
215
};
219
216
};
220
217
218
+ template <>
219
+ struct DenseMapInfo <AvailabilityDomain> {
220
+ static inline AvailabilityDomain getEmptyKey () {
221
+ return DenseMapInfo<AvailabilityDomain::Storage>::getEmptyKey ();
222
+ }
223
+ static inline AvailabilityDomain getTombstoneKey () {
224
+ return DenseMapInfo<AvailabilityDomain::Storage>::getTombstoneKey ();
225
+ }
226
+ static bool isEqual (const AvailabilityDomain LHS,
227
+ const AvailabilityDomain RHS) {
228
+ return LHS == RHS;
229
+ }
230
+ };
231
+
221
232
} // end namespace llvm
222
233
223
234
#endif
0 commit comments