Add a DenseMapInfo class for the AttributeSet.

We are going to place the AttributeSet into a DenseMap during assembly writing.

llvm-svn: 174812
This commit is contained in:
Bill Wendling 2013-02-09 15:42:51 +00:00
parent f340008eab
commit 33ab8a2187
1 changed files with 35 additions and 13 deletions

View File

@ -183,6 +183,26 @@ public:
} }
}; };
//===----------------------------------------------------------------------===//
/// \class
/// \brief Provide DenseMapInfo for Attribute::AttrKinds. This is used by
/// AttrBuilder.
template<> struct DenseMapInfo<Attribute::AttrKind> {
static inline Attribute::AttrKind getEmptyKey() {
return Attribute::AttrKindEmptyKey;
}
static inline Attribute::AttrKind getTombstoneKey() {
return Attribute::AttrKindTombstoneKey;
}
static unsigned getHashValue(const Attribute::AttrKind &Val) {
return Val * 37U;
}
static bool isEqual(const Attribute::AttrKind &LHS,
const Attribute::AttrKind &RHS) {
return LHS == RHS;
}
};
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
/// \class /// \class
/// \brief This class holds the attributes for a function, its return value, and /// \brief This class holds the attributes for a function, its return value, and
@ -200,6 +220,7 @@ public:
private: private:
friend class AttrBuilder; friend class AttrBuilder;
friend class AttributeSetImpl; friend class AttributeSetImpl;
template <typename Ty> friend struct DenseMapInfo;
/// \brief The attributes that we are managing. This can be null to represent /// \brief The attributes that we are managing. This can be null to represent
/// the empty attributes list. /// the empty attributes list.
@ -339,22 +360,23 @@ public:
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
/// \class /// \class
/// \brief Provide DenseMapInfo for Attribute::AttrKinds. This is used by /// \brief Provide DenseMapInfo for AttributeSet.
/// AttrBuilder. template<> struct DenseMapInfo<AttributeSet> {
template<> struct DenseMapInfo<Attribute::AttrKind> { static inline AttributeSet getEmptyKey() {
static inline Attribute::AttrKind getEmptyKey() { uintptr_t Val = static_cast<uintptr_t>(-1);
return Attribute::AttrKindEmptyKey; Val <<= PointerLikeTypeTraits<void*>::NumLowBitsAvailable;
return AttributeSet(reinterpret_cast<AttributeSetImpl*>(Val));
} }
static inline Attribute::AttrKind getTombstoneKey() { static inline AttributeSet getTombstoneKey() {
return Attribute::AttrKindTombstoneKey; uintptr_t Val = static_cast<uintptr_t>(-2);
Val <<= PointerLikeTypeTraits<void*>::NumLowBitsAvailable;
return AttributeSet(reinterpret_cast<AttributeSetImpl*>(Val));
} }
static unsigned getHashValue(const Attribute::AttrKind &Val) { static unsigned getHashValue(AttributeSet AS) {
return Val * 37U; return (unsigned((uintptr_t)AS.pImpl) >> 4) ^
} (unsigned((uintptr_t)AS.pImpl) >> 9);
static bool isEqual(const Attribute::AttrKind &LHS,
const Attribute::AttrKind &RHS) {
return LHS == RHS;
} }
static bool isEqual(AttributeSet LHS, AttributeSet RHS) { return LHS == RHS; }
}; };
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//