Use a 'Constant' object instead of a bit field to store the attribute data.
authorBill Wendling <isanbard@gmail.com>
Sat, 29 Dec 2012 12:29:38 +0000 (12:29 +0000)
committerBill Wendling <isanbard@gmail.com>
Sat, 29 Dec 2012 12:29:38 +0000 (12:29 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@171221 91177308-0d34-0410-b5e6-96231b3b80d8

lib/VMCore/AttributeImpl.h
lib/VMCore/Attributes.cpp

index e27a0297dfa017bc2ea9298da1c3d6346ad20264..3b8f818a17bea240c6c507ae197b8f0bd9e4e049 100644 (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);
 };
 
 //===----------------------------------------------------------------------===//
index 3a593574cc79825e28783ac757e49d9e047b5cbd..c85e5fe51c875d6dc4504534d2d9eca72d5d4039 100644 (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
 //===----------------------------------------------------------------------===//