Get rid of the 'Bits' mask in the attribute builder.

The bit mask thing will be a thing of the past. It's not extensible enough. Get
rid of its use here. Opt instead for using a vector to hold the attributes.

Note: Some of this code will become obsolete once the rewrite is further along.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@171553 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Bill Wendling
2013-01-04 23:27:34 +00:00
parent 73c35d86b9
commit 0319888773
2 changed files with 137 additions and 45 deletions

View File

@@ -17,6 +17,7 @@
#define LLVM_ATTRIBUTES_H
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/DenseSet.h"
#include "llvm/Support/MathExtras.h"
#include <cassert>
#include <string>
@@ -90,7 +91,9 @@ public:
StackProtectReq, ///< Stack protection required.
StructRet, ///< Hidden pointer to structure to return
UWTable, ///< Function must be in a unwind table
ZExt ///< Zero extended before/after call
ZExt, ///< Zero extended before/after call
EndAttrKinds ///< Sentinal value useful for loops
};
private:
AttributeImpl *pImpl;
@@ -150,6 +153,26 @@ public:
std::string getAsString() const;
};
//===----------------------------------------------------------------------===//
/// \class
/// \brief Provide DenseMapInfo for Attribute::AttrKinds. This is used by
/// AttrBuilder.
template<> struct DenseMapInfo<Attribute::AttrKind> {
static inline Attribute::AttrKind getEmptyKey() {
return Attribute::AttrKind(~0U);
}
static inline Attribute::AttrKind getTombstoneKey() {
return Attribute::AttrKind(~0U - 1);
}
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 is used in conjunction with the Attribute::get method to
@@ -157,13 +180,19 @@ public:
/// value, however, is not. So this can be used as a quick way to test for
/// equality, presence of attributes, etc.
class AttrBuilder {
uint64_t Bits;
DenseSet<Attribute::AttrKind> Attrs;
uint64_t Alignment;
uint64_t StackAlignment;
public:
AttrBuilder() : Bits(0) {}
explicit AttrBuilder(uint64_t B) : Bits(B) {}
AttrBuilder(const Attribute &A) : Bits(A.getBitMask()) {}
AttrBuilder() : Alignment(0), StackAlignment(0) {}
explicit AttrBuilder(uint64_t B) : Alignment(0), StackAlignment(0) {
addRawValue(B);
}
AttrBuilder(const Attribute &A) : Alignment(0), StackAlignment(0) {
addAttributes(A);
}
void clear() { Bits = 0; }
void clear();
/// \brief Add an attribute to the builder.
AttrBuilder &addAttribute(Attribute::AttrKind Val);
@@ -191,10 +220,10 @@ public:
bool hasAlignmentAttr() const;
/// \brief Retrieve the alignment attribute, if it exists.
uint64_t getAlignment() const;
uint64_t getAlignment() const { return Alignment; }
/// \brief Retrieve the stack alignment attribute, if it exists.
uint64_t getStackAlignment() const;
uint64_t getStackAlignment() const { return StackAlignment; }
/// \brief This turns an int alignment (which must be a power of 2) into the
/// form used internally in Attribute.
@@ -233,13 +262,11 @@ public:
.removeAttribute(Attribute::NoDuplicate);
}
uint64_t getBitMask() const { return Bits; }
uint64_t getBitMask() const;
bool operator==(const AttrBuilder &B) {
return Bits == B.Bits;
}
bool operator==(const AttrBuilder &B);
bool operator!=(const AttrBuilder &B) {
return Bits != B.Bits;
return !(*this == B);
}
};