From c835b8c30127d15599de2d614434d39a6cc3ae17 Mon Sep 17 00:00:00 2001 From: Benjamin Kramer Date: Sat, 16 Feb 2013 19:13:18 +0000 Subject: Turn the enum attributes DenseSet in AttrBuilder into a set of bits. Avoids malloc and is a lot denser. We lose iteration over target independent attributes, but that's a strange interface anyways and didn't have any users outside of AttrBuilder. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@175370 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/IR/Attributes.h | 55 ++++++++++++-------------------------------- 1 file changed, 15 insertions(+), 40 deletions(-) (limited to 'include/llvm/IR/Attributes.h') diff --git a/include/llvm/IR/Attributes.h b/include/llvm/IR/Attributes.h index b6ca1ad9f9..d3190ffae4 100644 --- a/include/llvm/IR/Attributes.h +++ b/include/llvm/IR/Attributes.h @@ -17,8 +17,8 @@ #define LLVM_IR_ATTRIBUTES_H #include "llvm/ADT/ArrayRef.h" -#include "llvm/ADT/DenseSet.h" #include "llvm/ADT/FoldingSet.h" +#include "llvm/Support/PointerLikeTypeTraits.h" #include #include #include @@ -30,6 +30,7 @@ class AttributeImpl; class AttributeSetImpl; class AttributeSetNode; class Constant; +template struct DenseMapInfo; class LLVMContext; class Type; @@ -101,9 +102,6 @@ public: ZExt, ///< Zero extended before/after call EndAttrKinds, ///< Sentinal value useful for loops - - AttrKindEmptyKey, ///< Empty key value for DenseMapInfo - AttrKindTombstoneKey ///< Tombstone key value for DenseMapInfo }; private: AttributeImpl *pImpl; @@ -185,26 +183,6 @@ public: } }; -//===----------------------------------------------------------------------===// -/// \class -/// \brief Provide DenseMapInfo for Attribute::AttrKinds. This is used by -/// AttrBuilder. -template<> struct DenseMapInfo { - 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 /// \brief This class holds the attributes for a function, its return value, and @@ -400,16 +378,17 @@ template<> struct DenseMapInfo { /// value, however, is not. So this can be used as a quick way to test for /// equality, presence of attributes, etc. class AttrBuilder { - DenseSet Attrs; + uint64_t Attrs; std::map TargetDepAttrs; uint64_t Alignment; uint64_t StackAlignment; public: - AttrBuilder() : Alignment(0), StackAlignment(0) {} - explicit AttrBuilder(uint64_t Val) : Alignment(0), StackAlignment(0) { + AttrBuilder() : Attrs(0), Alignment(0), StackAlignment(0) {} + explicit AttrBuilder(uint64_t Val) + : Attrs(0), Alignment(0), StackAlignment(0) { addRawValue(Val); } - AttrBuilder(const Attribute &A) : Alignment(0), StackAlignment(0) { + AttrBuilder(const Attribute &A) : Attrs(0), Alignment(0), StackAlignment(0) { addAttribute(A); } AttrBuilder(AttributeSet AS, unsigned Idx); @@ -442,7 +421,11 @@ public: AttrBuilder &merge(const AttrBuilder &B); /// \brief Return true if the builder has the specified attribute. - bool contains(Attribute::AttrKind A) const; + bool contains(Attribute::AttrKind A) const { + assert((unsigned)A < 64 && A < Attribute::EndAttrKinds && + "Attribute out of range!"); + return Attrs & (1ULL << A); + } /// \brief Return true if the builder has the specified target-dependent /// attribute. @@ -472,17 +455,9 @@ public: /// the form used internally in Attribute. AttrBuilder &addStackAlignmentAttr(unsigned Align); - // Iterators for target-independent attributes. - typedef DenseSet::iterator iterator; - typedef DenseSet::const_iterator const_iterator; - - iterator begin() { return Attrs.begin(); } - iterator end() { return Attrs.end(); } - - const_iterator begin() const { return Attrs.begin(); } - const_iterator end() const { return Attrs.end(); } - - bool empty() const { return Attrs.empty(); } + /// \brief Return true if the builder contains no target-independent + /// attributes. + bool empty() const { return Attrs == 0; } // Iterators for target-dependent attributes. typedef std::pair td_type; -- cgit v1.2.3