Initial cleanups of the param-attribute code in the bitcode reader/writer.
authorBill Wendling <isanbard@gmail.com>
Mon, 4 Feb 2013 23:32:23 +0000 (23:32 +0000)
committerBill Wendling <isanbard@gmail.com>
Mon, 4 Feb 2013 23:32:23 +0000 (23:32 +0000)
Rename the PARAMATTR_CODE_ENTRY to PARAMATTR_CODE_ENTRY_OLD. It will be replaced
by another encoding. Keep around the current LLVM attribute encoder/decoder
code, but move it to the bitcode directories so that no one's tempted to use
them.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@174335 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Bitcode/LLVMBitCodes.h
include/llvm/IR/Attributes.h
lib/Bitcode/Reader/BitcodeReader.cpp
lib/Bitcode/Writer/BitcodeWriter.cpp
lib/IR/Attributes.cpp

index 601777d11a8d62f8927da3860643a042f25ca742..de8ac39204c8e76b7ad9fafd29ccf52454fc9cd4 100644 (file)
@@ -77,7 +77,11 @@ namespace bitc {
 
   /// PARAMATTR blocks have code for defining a parameter attribute set.
   enum AttributeCodes {
 
   /// PARAMATTR blocks have code for defining a parameter attribute set.
   enum AttributeCodes {
-    PARAMATTR_CODE_ENTRY = 1   // ENTRY: [paramidx0, attr0, paramidx1, attr1...]
+    // FIXME: Remove `PARAMATTR_CODE_ENTRY_OLD' in 4.0
+    PARAMATTR_CODE_ENTRY_OLD = 1, // ENTRY: [paramidx0, attr0,
+                                  //         paramidx1, attr1...]
+    PARAMATTR_CODE_ENTRY = 2      // ENTRY: [paramidx0, attrgrp0,
+                                  //         paramidx1, attrgrp1...]
   };
 
   /// TYPE blocks have codes for each type primitive they use.
   };
 
   /// TYPE blocks have codes for each type primitive they use.
@@ -143,6 +147,7 @@ namespace bitc {
     METADATA_NAMED_NODE    = 10,  // NAMED_NODE:    [n x mdnodes]
     METADATA_ATTACHMENT    = 11   // [m x [value, [n x [id, mdnode]]]
   };
     METADATA_NAMED_NODE    = 10,  // NAMED_NODE:    [n x mdnodes]
     METADATA_ATTACHMENT    = 11   // [m x [value, [n x [id, mdnode]]]
   };
+
   // The constants block (CONSTANTS_BLOCK_ID) describes emission for each
   // constant and maintains an implicit current type value.
   enum ConstantsCodes {
   // The constants block (CONSTANTS_BLOCK_ID) describes emission for each
   // constant and maintains an implicit current type value.
   enum ConstantsCodes {
index c5b5a47c59cfb23943d5e0ec69691a8429395a28..c726020ab80de1c640af5d6e9ce40a91563dcb73 100644 (file)
@@ -345,8 +345,8 @@ class AttrBuilder {
   uint64_t StackAlignment;
 public:
   AttrBuilder() : Alignment(0), StackAlignment(0) {}
   uint64_t StackAlignment;
 public:
   AttrBuilder() : Alignment(0), StackAlignment(0) {}
-  explicit AttrBuilder(uint64_t B) : Alignment(0), StackAlignment(0) {
-    addRawValue(B);
+  explicit AttrBuilder(uint64_t Val) : Alignment(0), StackAlignment(0) {
+    addRawValue(Val);
   }
   AttrBuilder(const Attribute &A) : Alignment(0), StackAlignment(0) {
     addAttribute(A);
   }
   AttrBuilder(const Attribute &A) : Alignment(0), StackAlignment(0) {
     addAttribute(A);
@@ -433,11 +433,9 @@ public:
     return !(*this == B);
   }
 
     return !(*this == B);
   }
 
-  // FIXME: Remove these.
+  // FIXME: Remove this in 4.0.
 
   /// \brief Add the raw value to the internal representation.
 
   /// \brief Add the raw value to the internal representation.
-  /// 
-  /// N.B. This should be used ONLY for decoding LLVM bitcode!
   AttrBuilder &addRawValue(uint64_t Val);
 };
 
   AttrBuilder &addRawValue(uint64_t Val);
 };
 
@@ -446,18 +444,6 @@ namespace AttributeFuncs {
 /// \brief Which attributes cannot be applied to a type.
 AttributeSet typeIncompatible(Type *Ty, uint64_t Index);
 
 /// \brief Which attributes cannot be applied to a type.
 AttributeSet typeIncompatible(Type *Ty, uint64_t Index);
 
-/// \brief This returns an integer containing an encoding of all the LLVM
-/// attributes found in the given attribute bitset.  Any change to this encoding
-/// is a breaking change to bitcode compatibility.
-uint64_t encodeLLVMAttributesForBitcode(AttributeSet Attrs, unsigned Index);
-
-/// \brief This fills an AttrBuilder object with the LLVM attributes that have
-/// been decoded from the given integer. This function must stay in sync with
-/// 'encodeLLVMAttributesForBitcode'.
-/// N.B. This should be used only by the bitcode reader!
-void decodeLLVMAttributesForBitcode(LLVMContext &C, AttrBuilder &B,
-                                    uint64_t EncodedAttrs);
-
 } // end AttributeFuncs namespace
 
 } // end llvm namespace
 } // end AttributeFuncs namespace
 
 } // end llvm namespace
index ca299c007c66a72c854ce01f92e6bc5258fe70ff..6ab7011187181eb4daa1e8c5e950b6204b42f8e6 100644 (file)
@@ -428,6 +428,26 @@ Type *BitcodeReader::getTypeByID(unsigned ID) {
 //  Functions for parsing blocks from the bitcode file
 //===----------------------------------------------------------------------===//
 
 //  Functions for parsing blocks from the bitcode file
 //===----------------------------------------------------------------------===//
 
+
+/// \brief This fills an AttrBuilder object with the LLVM attributes that have
+/// been decoded from the given integer. This function must stay in sync with
+/// 'encodeLLVMAttributesForBitcode'.
+static void decodeLLVMAttributesForBitcode(AttrBuilder &B,
+                                           uint64_t EncodedAttrs) {
+  // FIXME: Remove in 4.0.
+
+  // The alignment is stored as a 16-bit raw value from bits 31--16.  We shift
+  // the bits above 31 down by 11 bits.
+  unsigned Alignment = (EncodedAttrs & (0xffffULL << 16)) >> 16;
+  assert((!Alignment || isPowerOf2_32(Alignment)) &&
+         "Alignment must be a power of two.");
+
+  if (Alignment)
+    B.addAlignmentAttr(Alignment);
+  B.addRawValue(((EncodedAttrs & (0xffffULL << 32)) >> 11) |
+                (EncodedAttrs & 0xffff));
+}
+
 bool BitcodeReader::ParseAttributeBlock() {
   if (Stream.EnterSubBlock(bitc::PARAMATTR_BLOCK_ID))
     return Error("Malformed block record");
 bool BitcodeReader::ParseAttributeBlock() {
   if (Stream.EnterSubBlock(bitc::PARAMATTR_BLOCK_ID))
     return Error("Malformed block record");
@@ -459,14 +479,14 @@ bool BitcodeReader::ParseAttributeBlock() {
     switch (Stream.readRecord(Entry.ID, Record)) {
     default:  // Default behavior: ignore.
       break;
     switch (Stream.readRecord(Entry.ID, Record)) {
     default:  // Default behavior: ignore.
       break;
-    case bitc::PARAMATTR_CODE_ENTRY: { // ENTRY: [paramidx0, attr0, ...]
+    case bitc::PARAMATTR_CODE_ENTRY_OLD: { // ENTRY: [paramidx0, attr0, ...]
+      // FIXME: Remove in 4.0.
       if (Record.size() & 1)
         return Error("Invalid ENTRY record");
 
       for (unsigned i = 0, e = Record.size(); i != e; i += 2) {
         AttrBuilder B;
       if (Record.size() & 1)
         return Error("Invalid ENTRY record");
 
       for (unsigned i = 0, e = Record.size(); i != e; i += 2) {
         AttrBuilder B;
-        AttributeFuncs::decodeLLVMAttributesForBitcode(Context, B,
-                                                       Record[i+1]);
+        decodeLLVMAttributesForBitcode(B, Record[i+1]);
         Attrs.push_back(AttributeSet::get(Context, Record[i], B));
       }
 
         Attrs.push_back(AttributeSet::get(Context, Record[i], B));
       }
 
index b6c2bc0f7500fa13237aaaf63a7b4ac339160051..c6d0371de7076072f48348662c33fa7adba756dc 100644 (file)
@@ -161,7 +161,30 @@ static void WriteStringRecord(unsigned Code, StringRef Str,
   Stream.EmitRecord(Code, Vals, AbbrevToUse);
 }
 
   Stream.EmitRecord(Code, Vals, AbbrevToUse);
 }
 
-// Emit information about parameter attributes.
+/// \brief This returns an integer containing an encoding of all the LLVM
+/// attributes found in the given attribute bitset.  Any change to this encoding
+/// is a breaking change to bitcode compatibility.
+/// N.B. This should be used only by the bitcode writer!
+static uint64_t encodeLLVMAttributesForBitcode(AttributeSet Attrs,
+                                               unsigned Index) {
+  // FIXME: Remove in 4.0!
+
+  // FIXME: It doesn't make sense to store the alignment information as an
+  // expanded out value, we should store it as a log2 value.  However, we can't
+  // just change that here without breaking bitcode compatibility.  If this ever
+  // becomes a problem in practice, we should introduce new tag numbers in the
+  // bitcode file and have those tags use a more efficiently encoded alignment
+  // field.
+
+  // Store the alignment in the bitcode as a 16-bit raw value instead of a 5-bit
+  // log2 encoded value. Shift the bits above the alignment up by 11 bits.
+  uint64_t EncodedAttrs = Attrs.Raw(Index) & 0xffff;
+  if (Attrs.hasAttribute(Index, Attribute::Alignment))
+    EncodedAttrs |= Attrs.getParamAlignment(Index) << 16;
+  EncodedAttrs |= (Attrs.Raw(Index) & (0xffffULL << 21)) << 11;
+  return EncodedAttrs;
+}
+
 static void WriteAttributeTable(const ValueEnumerator &VE,
                                 BitstreamWriter &Stream) {
   const std::vector<AttributeSet> &Attrs = VE.getAttributes();
 static void WriteAttributeTable(const ValueEnumerator &VE,
                                 BitstreamWriter &Stream) {
   const std::vector<AttributeSet> &Attrs = VE.getAttributes();
@@ -175,12 +198,11 @@ static void WriteAttributeTable(const ValueEnumerator &VE,
     for (unsigned i = 0, e = A.getNumSlots(); i != e; ++i) {
       unsigned Index = A.getSlotIndex(i);
       Record.push_back(Index);
     for (unsigned i = 0, e = A.getNumSlots(); i != e; ++i) {
       unsigned Index = A.getSlotIndex(i);
       Record.push_back(Index);
-      Record.push_back(AttributeFuncs::
-                       encodeLLVMAttributesForBitcode(A.getSlotAttributes(i),
+      Record.push_back(encodeLLVMAttributesForBitcode(A.getSlotAttributes(i),
                                                       Index));
     }
 
                                                       Index));
     }
 
-    Stream.EmitRecord(bitc::PARAMATTR_CODE_ENTRY, Record);
+    Stream.EmitRecord(bitc::PARAMATTR_CODE_ENTRY_OLD, Record);
     Record.clear();
   }
 
     Record.clear();
   }
 
index 3b4ece99b9d50e9a64402216e5bbe2e28cf15358..909f22f15221f63d59924edf50e1c2d0a86429a4 100644 (file)
@@ -927,6 +927,7 @@ bool AttrBuilder::operator==(const AttrBuilder &B) {
 }
 
 AttrBuilder &AttrBuilder::addRawValue(uint64_t Val) {
 }
 
 AttrBuilder &AttrBuilder::addRawValue(uint64_t Val) {
+  // FIXME: Remove this in 4.0.
   if (!Val) return *this;
 
   for (Attribute::AttrKind I = Attribute::None; I != Attribute::EndAttrKinds;
   if (!Val) return *this;
 
   for (Attribute::AttrKind I = Attribute::None; I != Attribute::EndAttrKinds;
@@ -967,44 +968,3 @@ AttributeSet AttributeFuncs::typeIncompatible(Type *Ty, uint64_t Index) {
 
   return AttributeSet::get(Ty->getContext(), Index, Incompatible);
 }
 
   return AttributeSet::get(Ty->getContext(), Index, Incompatible);
 }
-
-/// \brief This returns an integer containing an encoding of all the LLVM
-/// attributes found in the given attribute bitset.  Any change to this encoding
-/// is a breaking change to bitcode compatibility.
-/// N.B. This should be used only by the bitcode reader!
-uint64_t AttributeFuncs::encodeLLVMAttributesForBitcode(AttributeSet Attrs,
-                                                        unsigned Index) {
-  // FIXME: It doesn't make sense to store the alignment information as an
-  // expanded out value, we should store it as a log2 value.  However, we can't
-  // just change that here without breaking bitcode compatibility.  If this ever
-  // becomes a problem in practice, we should introduce new tag numbers in the
-  // bitcode file and have those tags use a more efficiently encoded alignment
-  // field.
-
-  // Store the alignment in the bitcode as a 16-bit raw value instead of a 5-bit
-  // log2 encoded value. Shift the bits above the alignment up by 11 bits.
-  uint64_t EncodedAttrs = Attrs.Raw(Index) & 0xffff;
-  if (Attrs.hasAttribute(Index, Attribute::Alignment))
-    EncodedAttrs |= Attrs.getParamAlignment(Index) << 16;
-  EncodedAttrs |= (Attrs.Raw(Index) & (0xffffULL << 21)) << 11;
-  return EncodedAttrs;
-}
-
-/// \brief This fills an AttrBuilder object with the LLVM attributes that have
-/// been decoded from the given integer. This function must stay in sync with
-/// 'encodeLLVMAttributesForBitcode'.
-/// N.B. This should be used only by the bitcode reader!
-void AttributeFuncs::decodeLLVMAttributesForBitcode(LLVMContext &C,
-                                                    AttrBuilder &B,
-                                                    uint64_t EncodedAttrs) {
-  // The alignment is stored as a 16-bit raw value from bits 31--16.  We shift
-  // the bits above 31 down by 11 bits.
-  unsigned Alignment = (EncodedAttrs & (0xffffULL << 16)) >> 16;
-  assert((!Alignment || isPowerOf2_32(Alignment)) &&
-         "Alignment must be a power of two.");
-
-  if (Alignment)
-    B.addAlignmentAttr(Alignment);
-  B.addRawValue(((EncodedAttrs & (0xffffULL << 32)) >> 11) |
-                (EncodedAttrs & 0xffff));
-}