diff options
author | Bill Wendling <isanbard@gmail.com> | 2012-10-15 04:46:55 +0000 |
---|---|---|
committer | Bill Wendling <isanbard@gmail.com> | 2012-10-15 04:46:55 +0000 |
commit | cb3de0bc800d7920087b19bb12a545d4cc84114e (patch) | |
tree | cbd5a447bcc1d11449532b3c92119f26eeb5a815 /lib/VMCore/Attributes.cpp | |
parent | a239c2e6a7775e890bcfb0867b84e512ceb993de (diff) |
Attributes Rewrite
Convert the internal representation of the Attributes class into a pointer to an
opaque object that's uniqued by and stored in the LLVMContext object. The
Attributes class then becomes a thin wrapper around this opaque
object. Eventually, the internal representation will be expanded to include
attributes that represent code generation options, etc.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@165917 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore/Attributes.cpp')
-rw-r--r-- | lib/VMCore/Attributes.cpp | 35 |
1 files changed, 16 insertions, 19 deletions
diff --git a/lib/VMCore/Attributes.cpp b/lib/VMCore/Attributes.cpp index 15890f92b3..010a356dea 100644 --- a/lib/VMCore/Attributes.cpp +++ b/lib/VMCore/Attributes.cpp @@ -27,21 +27,18 @@ using namespace llvm; // Attributes Implementation //===----------------------------------------------------------------------===// -Attributes::Attributes(uint64_t Val) : Attrs(Val) {} - -Attributes::Attributes(LLVMContext &C, AttrVal Val) - : Attrs(Attributes::get(Attributes::Builder().addAttribute(Val)).Attrs) {} +Attributes::Attributes(LLVMContext &C, ArrayRef<AttrVal> Vals) { + Attributes::Builder B; + for (ArrayRef<AttrVal>::iterator I = Vals.begin(), E = Vals.end(); + I != E; ++I) + B.addAttribute(*I); + Attrs = Attributes::get(C, B).Attrs; +} -Attributes::Attributes(AttributesImpl *A) : Attrs(A->Bits) {} +Attributes::Attributes(AttributesImpl *A) : Attrs(A) {} Attributes::Attributes(const Attributes &A) : Attrs(A.Attrs) {} -// FIXME: This is temporary until we have implemented the uniquified version of -// AttributesImpl. -Attributes Attributes::get(Attributes::Builder &B) { - return Attributes(B.Bits); -} - Attributes Attributes::get(LLVMContext &Context, Attributes::Builder &B) { // If there are no attributes, return an empty Attributes class. if (B.Bits == 0) @@ -67,18 +64,18 @@ Attributes Attributes::get(LLVMContext &Context, Attributes::Builder &B) { } bool Attributes::hasAttribute(AttrVal Val) const { - return Attrs.hasAttribute(Val); + return Attrs && Attrs->hasAttribute(Val); } bool Attributes::hasAttributes(const Attributes &A) const { - return Attrs.hasAttributes(A); + return Attrs && Attrs->hasAttributes(A); } /// This returns the alignment field of an attribute as a byte alignment value. unsigned Attributes::getAlignment() const { if (!hasAttribute(Attributes::Alignment)) return 0; - return 1U << ((Attrs.getAlignment() >> 16) - 1); + return 1U << ((Attrs->getAlignment() >> 16) - 1); } /// This returns the stack alignment field of an attribute as a byte alignment @@ -86,11 +83,11 @@ unsigned Attributes::getAlignment() const { unsigned Attributes::getStackAlignment() const { if (!hasAttribute(Attributes::StackAlignment)) return 0; - return 1U << ((Attrs.getStackAlignment() >> 26) - 1); + return 1U << ((Attrs->getStackAlignment() >> 26) - 1); } uint64_t Attributes::Raw() const { - return Attrs.Bits; + return Attrs ? Attrs->Bits : 0; // FIXME: Don't access this directly! } Attributes Attributes::typeIncompatible(Type *Ty) { @@ -109,7 +106,7 @@ Attributes Attributes::typeIncompatible(Type *Ty) { .addAttribute(Attributes::NoCapture) .addAttribute(Attributes::StructRet); - return Attributes(Incompatible.Bits); // FIXME: Use Attributes::get(). + return Attributes::get(Ty->getContext(), Incompatible); } std::string Attributes::getAsString() const { @@ -514,7 +511,7 @@ AttrListPtr AttrListPtr::addAttr(LLVMContext &C, unsigned Idx, // If there are attributes already at this index, merge them in. if (i != e && OldAttrList[i].Index == Idx) { Attrs = - Attributes::get(Attributes::Builder(Attrs). + Attributes::get(C, Attributes::Builder(Attrs). addAttributes(OldAttrList[i].Attrs)); ++i; } @@ -555,7 +552,7 @@ AttrListPtr AttrListPtr::removeAttr(LLVMContext &C, unsigned Idx, // If there are attributes already at this index, merge them in. assert(OldAttrList[i].Index == Idx && "Attribute isn't set?"); - Attrs = Attributes::get(Attributes::Builder(OldAttrList[i].Attrs). + Attrs = Attributes::get(C, Attributes::Builder(OldAttrList[i].Attrs). removeAttributes(Attrs)); ++i; if (Attrs.hasAttributes()) // If any attributes left for this param, add them. |