Decode the LLVM attributes from bitcode using the attributes builder.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@165891 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Bill Wendling
2012-10-14 04:10:01 +00:00
parent da3f9d8edc
commit a19a53065f
2 changed files with 14 additions and 7 deletions

View File

@@ -103,6 +103,7 @@ public:
uint64_t Bits; uint64_t Bits;
public: public:
Builder() : Bits(0) {} Builder() : Bits(0) {}
explicit Builder(uint64_t B) : Bits(B) {}
Builder(const Attributes &A) : Bits(A.Raw()) {} Builder(const Attributes &A) : Bits(A.Raw()) {}
void clear() { Bits = 0; } void clear() { Bits = 0; }
@@ -118,6 +119,10 @@ public:
Builder &addAttribute(Attributes::AttrVal Val); Builder &addAttribute(Attributes::AttrVal Val);
Builder &removeAttribute(Attributes::AttrVal Val); Builder &removeAttribute(Attributes::AttrVal Val);
/// addRawValue - Add the raw value to the internal representation. This
/// should be used ONLY for decoding bitcode!
Builder &addRawValue(uint64_t Val);
/// addAlignmentAttr - This turns an int alignment (which must be a power of /// addAlignmentAttr - This turns an int alignment (which must be a power of
/// 2) into the form used internally in Attributes. /// 2) into the form used internally in Attributes.
Builder &addAlignmentAttr(unsigned Align); Builder &addAlignmentAttr(unsigned Align);
@@ -266,14 +271,11 @@ public:
assert((!Alignment || isPowerOf2_32(Alignment)) && assert((!Alignment || isPowerOf2_32(Alignment)) &&
"Alignment must be a power of two."); "Alignment must be a power of two.");
Attributes Attrs(EncodedAttrs & 0xffff); Attributes::Builder B(EncodedAttrs & 0xffff);
if (Alignment) { if (Alignment)
Attributes::Builder B;
B.addAlignmentAttr(Alignment); B.addAlignmentAttr(Alignment);
Attrs |= Attributes::get(B); B.addRawValue((EncodedAttrs & (0xfffULL << 32)) >> 11);
} return Attributes::get(B);
Attrs |= Attributes((EncodedAttrs & (0xfffULL << 32)) >> 11);
return Attrs;
} }
/// getAsString - The set of Attributes set in Attributes is converted to a /// getAsString - The set of Attributes set in Attributes is converted to a

View File

@@ -215,6 +215,11 @@ addAttribute(Attributes::AttrVal Val) {
return *this; return *this;
} }
Attributes::Builder &Attributes::Builder::addRawValue(uint64_t Val) {
Bits |= Val;
return *this;
}
Attributes::Builder &Attributes::Builder::addAlignmentAttr(unsigned Align) { Attributes::Builder &Attributes::Builder::addAlignmentAttr(unsigned Align) {
if (Align == 0) return *this; if (Align == 0) return *this;
assert(isPowerOf2_32(Align) && "Alignment must be a power of two."); assert(isPowerOf2_32(Align) && "Alignment must be a power of two.");