Use a 'Constant' object instead of a bit field to store the attribute data.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@171221 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Bill Wendling 2012-12-29 12:29:38 +00:00
parent 4d5e5e5d61
commit 7c1683d47c
2 changed files with 19 additions and 8 deletions

View File

@ -21,6 +21,7 @@
namespace llvm {
class Constant;
class LLVMContext;
//===----------------------------------------------------------------------===//
@ -29,9 +30,9 @@ class LLVMContext;
/// could be a single enum, a tuple, or a string. It uses a discriminated union
/// to distinguish them.
class AttributeImpl : public FoldingSetNode {
uint64_t Bits; // FIXME: We will be expanding this.
Constant *Data;
public:
AttributeImpl(uint64_t bits) : Bits(bits) {}
AttributeImpl(LLVMContext &C, uint64_t data);
bool hasAttribute(uint64_t A) const;
@ -41,16 +42,14 @@ public:
uint64_t getAlignment() const;
uint64_t getStackAlignment() const;
uint64_t Raw() const { return Bits; } // FIXME: Remove.
uint64_t Raw() const; // FIXME: Remove.
static uint64_t getAttrMask(uint64_t Val);
void Profile(FoldingSetNodeID &ID) const {
Profile(ID, Bits);
}
static void Profile(FoldingSetNodeID &ID, uint64_t Bits) {
ID.AddInteger(Bits);
Profile(ID, Data);
}
static void Profile(FoldingSetNodeID &ID, Constant *Data);
};
//===----------------------------------------------------------------------===//

View File

@ -53,7 +53,7 @@ Attribute Attribute::get(LLVMContext &Context, AttrBuilder &B) {
if (!PA) {
// If we didn't find any existing attributes of the same shape then create a
// new one and insert it.
PA = new AttributeImpl(B.Raw());
PA = new AttributeImpl(Context, B.Raw());
pImpl->AttrsSet.InsertNode(PA, InsertPoint);
}
@ -298,6 +298,14 @@ uint64_t AttrBuilder::getStackAlignment() const {
// AttributeImpl Definition
//===----------------------------------------------------------------------===//
AttributeImpl::AttributeImpl(LLVMContext &C, uint64_t data) {
Data = ConstantInt::get(Type::getInt64Ty(C), data);
}
uint64_t AttributeImpl::Raw() const {
return cast<ConstantInt>(Data)->getZExtValue();
}
uint64_t AttributeImpl::getAttrMask(uint64_t Val) {
switch (Val) {
case Attribute::None: return 0;
@ -354,6 +362,10 @@ uint64_t AttributeImpl::getStackAlignment() const {
return Raw() & getAttrMask(Attribute::StackAlignment);
}
void AttributeImpl::Profile(FoldingSetNodeID &ID, Constant *Data) {
ID.AddInteger(cast<ConstantInt>(Data)->getZExtValue());
}
//===----------------------------------------------------------------------===//
// AttributeSetImpl Definition
//===----------------------------------------------------------------------===//