llvm.org GIT mirror llvm / 4bbf4ee
Remove isPod() from DenseMapInfo, splitting it out to its own isPodLike type trait. This is a generally useful type trait for more than just DenseMap, and we really care about whether something acts like a pod, not whether it really is a pod. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@91421 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 10 years ago
21 changed file(s) with 118 addition(s) and 82 deletion(s). Raw diff Collapse all Expand all
216216
217217 private:
218218 void CopyFrom(const DenseMap& other) {
219 if (NumBuckets != 0 && (!KeyInfoT::isPod() || !ValueInfoT::isPod())) {
219 if (NumBuckets != 0 &&
220 (!isPodLike::value || !isPodLike::value)) {
220221 const KeyT EmptyKey = getEmptyKey(), TombstoneKey = getTombstoneKey();
221222 for (BucketT *P = Buckets, *E = Buckets+NumBuckets; P != E; ++P) {
222223 if (!KeyInfoT::isEqual(P->first, EmptyKey) &&
238239 Buckets = static_cast(operator new(sizeof(BucketT) *
239240 other.NumBuckets));
240241
241 if (KeyInfoT::isPod() && ValueInfoT::isPod())
242 if (isPodLike::value && isPodLike::value)
242243 memcpy(Buckets, other.Buckets, other.NumBuckets * sizeof(BucketT));
243244 else
244245 for (size_t i = 0; i < other.NumBuckets; ++i) {
1414 #define LLVM_ADT_DENSEMAPINFO_H
1515
1616 #include "llvm/Support/PointerLikeTypeTraits.h"
17 #include
17 #include "llvm/Support/type_traits.h"
1818
1919 namespace llvm {
2020
2424 //static inline T getTombstoneKey();
2525 //static unsigned getHashValue(const T &Val);
2626 //static bool isEqual(const T &LHS, const T &RHS);
27 //static bool isPod()
2827 };
2928
3029 // Provide DenseMapInfo for all pointers.
4544 (unsigned((uintptr_t)PtrVal) >> 9);
4645 }
4746 static bool isEqual(const T *LHS, const T *RHS) { return LHS == RHS; }
48 static bool isPod() { return true; }
4947 };
5048
5149 // Provide DenseMapInfo for chars.
5351 static inline char getEmptyKey() { return ~0; }
5452 static inline char getTombstoneKey() { return ~0 - 1; }
5553 static unsigned getHashValue(const char& Val) { return Val * 37; }
56 static bool isPod() { return true; }
5754 static bool isEqual(const char &LHS, const char &RHS) {
5855 return LHS == RHS;
5956 }
6461 static inline unsigned getEmptyKey() { return ~0; }
6562 static inline unsigned getTombstoneKey() { return ~0U - 1; }
6663 static unsigned getHashValue(const unsigned& Val) { return Val * 37; }
67 static bool isPod() { return true; }
6864 static bool isEqual(const unsigned& LHS, const unsigned& RHS) {
6965 return LHS == RHS;
7066 }
7773 static unsigned getHashValue(const unsigned long& Val) {
7874 return (unsigned)(Val * 37UL);
7975 }
80 static bool isPod() { return true; }
8176 static bool isEqual(const unsigned long& LHS, const unsigned long& RHS) {
8277 return LHS == RHS;
8378 }
9085 static unsigned getHashValue(const unsigned long long& Val) {
9186 return (unsigned)(Val * 37ULL);
9287 }
93 static bool isPod() { return true; }
9488 static bool isEqual(const unsigned long long& LHS,
9589 const unsigned long long& RHS) {
9690 return LHS == RHS;
126120 return (unsigned)key;
127121 }
128122 static bool isEqual(const Pair& LHS, const Pair& RHS) { return LHS == RHS; }
129 static bool isPod() { return FirstInfo::isPod() && SecondInfo::isPod(); }
130123 };
131124
132125 } // end namespace llvm
210210 static bool isEqual(ImmutableList X1, ImmutableList X2) {
211211 return X1 == X2;
212212 }
213 static bool isPod() { return true; }
214 };
213 };
214
215 template struct isPodLike;
216 template
217 struct isPodLike > { static const bool value = true; };
215218
216219 } // end llvm namespace
217220
105105 bool operator>=(const PointerIntPair &RHS) const {return Value >= RHS.Value;}
106106 };
107107
108 template struct isPodLike;
109 template
110 struct isPodLike > {
111 static const bool value = true;
112 };
113
108114 // Provide specialization of DenseMapInfo for PointerIntPair.
109115 template
110116 struct DenseMapInfo > {
124130 return unsigned(IV) ^ unsigned(IV >> 9);
125131 }
126132 static bool isEqual(const Ty &LHS, const Ty &RHS) { return LHS == RHS; }
127 static bool isPod() { return true; }
128133 };
129134
130135 // Teach SmallPtrSet that PointerIntPair is "basically a pointer".
249249 }
250250 };
251251
252
253 template
254 struct isPodLike > {
255 static const bool value = true;
256 };
257
252258 template
253259 struct DenseMapInfo > {
254260 typedef ValueMapCallbackVH VH;
266272 static bool isEqual(const VH &LHS, const VH &RHS) {
267273 return LHS == RHS;
268274 }
269 static bool isPod() { return false; }
270275 };
271276
272277
258258 ASTCallbackVH(Value *V, AliasSetTracker *AST = 0);
259259 ASTCallbackVH &operator=(Value *V);
260260 };
261 /// ASTCallbackVHDenseMapInfo - Traits to tell DenseMap that ASTCallbackVH
262 /// is not a POD (it needs its destructor called).
263 struct ASTCallbackVHDenseMapInfo : public DenseMapInfo {
264 static bool isPod() { return false; }
265 };
261 /// ASTCallbackVHDenseMapInfo - Traits to tell DenseMap that tell us how to
262 /// compare and hash the value handle.
263 struct ASTCallbackVHDenseMapInfo : public DenseMapInfo {};
266264
267265 AliasAnalysis &AA;
268266 ilist AliasSets;
2424
2525 namespace llvm {
2626
27 struct BPNode {
28 BPNode* Next;
29 uintptr_t& PtrRef;
30
31 BPNode(BPNode* n, uintptr_t& pref)
32 : Next(n), PtrRef(pref) {
33 PtrRef = 0;
34 }
35 };
36
37 struct BPEntry {
38 union { BPNode* Head; void* Ptr; };
39 BPEntry() : Head(NULL) {}
40 void SetPtr(BPNode*& FreeList, void* P);
41 };
42
43 class BPKey {
44 unsigned Raw;
45 public:
46 BPKey(SerializedPtrID PtrId) : Raw(PtrId << 1) { assert (PtrId > 0); }
47 BPKey(unsigned code, unsigned) : Raw(code) {}
48
49 void MarkFinal() { Raw |= 0x1; }
50 bool hasFinalPtr() const { return Raw & 0x1 ? true : false; }
51 SerializedPtrID getID() const { return Raw >> 1; }
52
53 static inline BPKey getEmptyKey() { return BPKey(0,0); }
54 static inline BPKey getTombstoneKey() { return BPKey(1,0); }
55 static inline unsigned getHashValue(const BPKey& K) { return K.Raw & ~0x1; }
56
57 static bool isEqual(const BPKey& K1, const BPKey& K2) {
58 return (K1.Raw ^ K2.Raw) & ~0x1 ? false : true;
59 }
60 };
61
62 template <>
63 struct isPodLike { static const bool value = true; };
64 template <>
65 struct isPodLike { static const bool value = true; };
66
2767 class Deserializer {
2868
2969 //===----------------------------------------------------------===//
3070 // Internal type definitions.
3171 //===----------------------------------------------------------===//
3272
33 struct BPNode {
34 BPNode* Next;
35 uintptr_t& PtrRef;
36
37 BPNode(BPNode* n, uintptr_t& pref)
38 : Next(n), PtrRef(pref) {
39 PtrRef = 0;
40 }
41 };
42
43 struct BPEntry {
44 union { BPNode* Head; void* Ptr; };
45
46 BPEntry() : Head(NULL) {}
47
48 static inline bool isPod() { return true; }
49
50 void SetPtr(BPNode*& FreeList, void* P);
51 };
52
53 class BPKey {
54 unsigned Raw;
55
56 public:
57 BPKey(SerializedPtrID PtrId) : Raw(PtrId << 1) { assert (PtrId > 0); }
58 BPKey(unsigned code, unsigned) : Raw(code) {}
59
60 void MarkFinal() { Raw |= 0x1; }
61 bool hasFinalPtr() const { return Raw & 0x1 ? true : false; }
62 SerializedPtrID getID() const { return Raw >> 1; }
63
64 static inline BPKey getEmptyKey() { return BPKey(0,0); }
65 static inline BPKey getTombstoneKey() { return BPKey(1,0); }
66 static inline unsigned getHashValue(const BPKey& K) { return K.Raw & ~0x1; }
67
68 static bool isEqual(const BPKey& K1, const BPKey& K2) {
69 return (K1.Raw ^ K2.Raw) & ~0x1 ? false : true;
70 }
71
72 static bool isPod() { return true; }
73 };
7473
7574 typedef llvm::DenseMap MapTy;
7675
890890 static bool isEqual(const SDValue &LHS, const SDValue &RHS) {
891891 return LHS == RHS;
892892 }
893 static bool isPod() { return true; }
894 };
893 };
894 template <> struct isPodLike { static const bool value = true; };
895
895896
896897 /// simplify_type specializations - Allow casting operators to work directly on
897898 /// SDValues as if they were SDNode*'s.
328328 };
329329
330330 /// DenseMapInfo specialization for SlotIndex.
331 /// TODO: Not a POD?
331332 template <>
332333 struct DenseMapInfo {
333334 static inline SlotIndex getEmptyKey() {
342343 static inline bool isEqual(const SlotIndex &LHS, const SlotIndex &RHS) {
343344 return (LHS == RHS);
344345 }
345 static inline bool isPod() { return false; }
346346 };
347347
348348 inline raw_ostream& operator<<(raw_ostream &os, SlotIndex li) {
6565 };
6666
6767 // Specialize DenseMapInfo for DebugLocTuple.
68 template<> struct DenseMapInfo {
68 template<> struct DenseMapInfo {
6969 static inline DebugLocTuple getEmptyKey() {
7070 return DebugLocTuple(0, 0, ~0U, ~0U);
7171 }
8484 LHS.Line == RHS.Line &&
8585 LHS.Col == RHS.Col;
8686 }
87 };
88 template <> struct isPodLike {static const bool value = true;};
8789
88 static bool isPod() { return true; }
89 };
9090
9191 /// DebugLocTracker - This class tracks debug location information.
9292 ///
253253 static bool isEqual(const AssertingVH &LHS, const AssertingVH &RHS) {
254254 return LHS == RHS;
255255 }
256 static bool isPod() {
256 };
257
258 template
259 struct isPodLike > {
257260 #ifdef NDEBUG
258 return true;
261 static const bool value = true;
259262 #else
260 return false;
263 static const bool value = false;
261264 #endif
262 }
263 };
265 };
266
264267
265268 /// TrackingVH - This is a value handle that tracks a Value (or Value subclass),
266269 /// even across RAUW operations.
1616 #ifndef LLVM_SUPPORT_TYPE_TRAITS_H
1717 #define LLVM_SUPPORT_TYPE_TRAITS_H
1818
19 #include
20
1921 // This is actually the conforming implementation which works with abstract
2022 // classes. However, enough compilers have trouble with it that most will use
2123 // the one in boost/type_traits/object_traits.hpp. This implementation actually
2325
2426 namespace llvm {
2527
28 /// isPodLike - This is a type trait that is used to determine whether a given
29 /// type can be copied around with memcpy instead of running ctors etc.
30 template
31 struct isPodLike {
32 static const bool value = false;
33 };
34
35 // pointers are all pod-like.
36 template
37 struct isPodLike { static const bool value = true; };
38
39 // builtin types are pod-like as well.
40 // There is probably a much better way to do this.
41 template <> struct isPodLike { static const bool value = true; };
42 template <> struct isPodLike { static const bool value = true; };
43 template <> struct isPodLike { static const bool value = true; };
44 template <> struct isPodLike {
45 static const bool value = true;
46 };
47
48
49 // pairs are pod-like if their elements are.
50 template
51 struct isPodLike > {
52 static const bool value = isPodLike::value & isPodLike::value;
53 };
54
2655 namespace dont_use
2756 {
2857 // These two functions should never be used. They are helpers to
120120
121121 return *LHS == *RHS;
122122 }
123
124 static bool isPod() { return true; }
125123 };
126124
127125 class Andersens : public ModulePass, public AliasAnalysis,
412412 return GetFinalPtr(E);
413413 }
414414
415 void Deserializer::BPEntry::SetPtr(BPNode*& FreeList, void* P) {
415 void BPEntry::SetPtr(BPNode*& FreeList, void* P) {
416416 BPNode* Last = NULL;
417417
418418 for (BPNode* N = Head; N != NULL; N=N->Next) {
118118 static inline unsigned getTombstoneKey() { return -2U; }
119119 static unsigned getHashValue(const unsigned &Key) { return Key; }
120120 static bool isEqual(unsigned LHS, unsigned RHS) { return LHS == RHS; }
121 static bool isPod() { return true; }
122121 };
123122
124123 /// PadRange - Structure holding a try-range and the associated landing pad.
174174 static inline unsigned getTombstoneKey() { return -2U; }
175175 static unsigned getHashValue(const unsigned &Key) { return Key; }
176176 static bool isEqual(unsigned LHS, unsigned RHS) { return LHS == RHS; }
177 static bool isPod() { return true; }
178177 };
179178
180179 /// ActionEntry - Structure describing an entry in the actions table.
189189 static bool isEqual(const Expression &LHS, const Expression &RHS) {
190190 return LHS == RHS;
191191 }
192 static bool isPod() { return true; }
193192 };
193
194 template <>
195 struct isPodLike { static const bool value = true; };
196
194197 }
195198
196199 //===----------------------------------------------------------------------===//
1119911199 return LHS.PN == RHS.PN && LHS.Shift == RHS.Shift &&
1120011200 LHS.Width == RHS.Width;
1120111201 }
11202 static bool isPod() { return true; }
1120311202 };
11203 template <>
11204 struct isPodLike { static const bool value = true; };
1120411205 }
1120511206
1120611207
153153 static bool isEqual(const Expression &LHS, const Expression &RHS) {
154154 return LHS == RHS;
155155 }
156 static bool isPod() { return true; }
157156 };
157 template <>
158 struct isPodLike { static const bool value = true; };
159
158160 }
159161
160162 //===----------------------------------------------------------------------===//
5454 static bool isEqual(const EltTy &LHS, const EltTy &RHS) {
5555 return LHS == RHS;
5656 }
57 static bool isPod() { return true; }
5857 };
5958 }
6059
6161 static bool isEqual(const KeyTy &LHS, const KeyTy &RHS) {
6262 return LHS == RHS;
6363 }
64 static bool isPod() { return false; }
6564 };
6665
6766 struct DenseMapAPFloatKeyInfo {
8887 static bool isEqual(const KeyTy &LHS, const KeyTy &RHS) {
8988 return LHS == RHS;
9089 }
91 static bool isPod() { return false; }
9290 };
9391
9492 class LLVMContextImpl {