diff options
author | Bill Wendling <isanbard@gmail.com> | 2013-01-31 23:16:25 +0000 |
---|---|---|
committer | Bill Wendling <isanbard@gmail.com> | 2013-01-31 23:16:25 +0000 |
commit | 169d5270751597aed4095ead00401a3374906147 (patch) | |
tree | 7eca2760854ffdd8e7f398981cb756e2a3908b10 /lib/IR | |
parent | 68cbd91f97b4f963971c941405227fe943e376ac (diff) | |
download | external_llvm-169d5270751597aed4095ead00401a3374906147.zip external_llvm-169d5270751597aed4095ead00401a3374906147.tar.gz external_llvm-169d5270751597aed4095ead00401a3374906147.tar.bz2 |
Remove the AttrBuilder form of the Attribute::get creators.
The AttrBuilder is for building a collection of attributes. The Attribute object
holds only one attribute. So it's not really useful for the Attribute object to
have a creator which takes an AttrBuilder.
This has two fallouts:
1. The AttrBuilder no longer holds its internal attributes in a bit-mask form.
2. The attributes are now ordered alphabetically (hence why the tests have changed).
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@174110 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/IR')
-rw-r--r-- | lib/IR/AttributeImpl.h | 2 | ||||
-rw-r--r-- | lib/IR/Attributes.cpp | 70 |
2 files changed, 38 insertions, 34 deletions
diff --git a/lib/IR/AttributeImpl.h b/lib/IR/AttributeImpl.h index 442860d..e952578 100644 --- a/lib/IR/AttributeImpl.h +++ b/lib/IR/AttributeImpl.h @@ -40,6 +40,8 @@ class AttributeImpl : public FoldingSetNode { public: AttributeImpl(LLVMContext &C, Constant *Kind) : Context(C), Kind(Kind) {} + AttributeImpl(LLVMContext &C, Constant *Kind, ArrayRef<Constant*> Vals) + : Context(C), Kind(Kind), Vals(Vals.begin(), Vals.end()) {} explicit AttributeImpl(LLVMContext &C, Attribute::AttrKind data); AttributeImpl(LLVMContext &C, Attribute::AttrKind data, ArrayRef<Constant*> values); diff --git a/lib/IR/Attributes.cpp b/lib/IR/Attributes.cpp index 5608cbd..c2ea2b2 100644 --- a/lib/IR/Attributes.cpp +++ b/lib/IR/Attributes.cpp @@ -30,24 +30,11 @@ using namespace llvm; // Attribute Construction Methods //===----------------------------------------------------------------------===// -Attribute Attribute::get(LLVMContext &Context, AttrKind Kind) { - AttrBuilder B; - return Attribute::get(Context, B.addAttribute(Kind)); -} - -Attribute Attribute::get(LLVMContext &Context, AttrBuilder &B) { - // If there are no attributes, return an empty Attribute class. - if (!B.hasAttributes()) - return Attribute(); - - assert(std::distance(B.begin(), B.end()) == 1 && - "The Attribute object should represent one attribute only!"); - - // Otherwise, build a key to look up the existing attributes. +Attribute Attribute::get(LLVMContext &Context, Constant *Kind, Constant *Val) { LLVMContextImpl *pImpl = Context.pImpl; FoldingSetNodeID ID; - ConstantInt *CI = ConstantInt::get(Type::getInt64Ty(Context), B.Raw()); - ID.AddPointer(CI); + ID.AddPointer(Kind); + if (Val) ID.AddPointer(Val); void *InsertPoint; AttributeImpl *PA = pImpl->AttrsSet.FindNodeOrInsertPos(ID, InsertPoint); @@ -55,7 +42,9 @@ 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(Context, CI); + PA = (!Val) ? + new AttributeImpl(Context, Kind) : + new AttributeImpl(Context, Kind, Val); pImpl->AttrsSet.InsertNode(PA, InsertPoint); } @@ -63,15 +52,24 @@ Attribute Attribute::get(LLVMContext &Context, AttrBuilder &B) { return Attribute(PA); } +Attribute Attribute::get(LLVMContext &Context, AttrKind Kind, Constant *Val) { + ConstantInt *KindVal = ConstantInt::get(Type::getInt64Ty(Context), Kind); + return get(Context, KindVal, Val); +} + Attribute Attribute::getWithAlignment(LLVMContext &Context, uint64_t Align) { - AttrBuilder B; - return get(Context, B.addAlignmentAttr(Align)); + assert(isPowerOf2_32(Align) && "Alignment must be a power of two."); + assert(Align <= 0x40000000 && "Alignment too large."); + return get(Context, Alignment, + ConstantInt::get(Type::getInt64Ty(Context), Align)); } Attribute Attribute::getWithStackAlignment(LLVMContext &Context, uint64_t Align) { - AttrBuilder B; - return get(Context, B.addStackAlignmentAttr(Align)); + assert(isPowerOf2_32(Align) && "Alignment must be a power of two."); + assert(Align <= 0x100 && "Alignment too large."); + return get(Context, StackAlignment, + ConstantInt::get(Type::getInt64Ty(Context), Align)); } //===----------------------------------------------------------------------===// @@ -250,17 +248,21 @@ AttributeImpl::AttributeImpl(LLVMContext &C, StringRef kind) } bool AttributeImpl::hasAttribute(Attribute::AttrKind A) const { - return (Raw() & getAttrMask(A)) != 0; + if (ConstantInt *CI = dyn_cast<ConstantInt>(Kind)) + return CI->getZExtValue() == A; + return false; } uint64_t AttributeImpl::getAlignment() const { - uint64_t Mask = Raw() & getAttrMask(Attribute::Alignment); - return 1ULL << ((Mask >> 16) - 1); + assert(hasAttribute(Attribute::Alignment) && + "Trying to retrieve the alignment from a non-alignment attr!"); + return cast<ConstantInt>(Vals[0])->getZExtValue(); } uint64_t AttributeImpl::getStackAlignment() const { - uint64_t Mask = Raw() & getAttrMask(Attribute::StackAlignment); - return 1ULL << ((Mask >> 26) - 1); + assert(hasAttribute(Attribute::StackAlignment) && + "Trying to retrieve the stack alignment from a non-alignment attr!"); + return cast<ConstantInt>(Vals[0])->getZExtValue(); } bool AttributeImpl::operator==(Attribute::AttrKind kind) const { @@ -808,12 +810,15 @@ void AttrBuilder::clear() { } AttrBuilder &AttrBuilder::addAttribute(Attribute::AttrKind Val) { + assert(Val != Attribute::Alignment && Val != Attribute::StackAlignment && + "Adding alignment attribute without adding alignment value!"); Attrs.insert(Val); return *this; } AttrBuilder &AttrBuilder::removeAttribute(Attribute::AttrKind Val) { Attrs.erase(Val); + if (Val == Attribute::Alignment) Alignment = 0; else if (Val == Attribute::StackAlignment) @@ -823,16 +828,13 @@ AttrBuilder &AttrBuilder::removeAttribute(Attribute::AttrKind Val) { } AttrBuilder &AttrBuilder::addAttributes(Attribute Attr) { - uint64_t Mask = Attr.Raw(); - - for (Attribute::AttrKind I = Attribute::None; I != Attribute::EndAttrKinds; - I = Attribute::AttrKind(I + 1)) - if ((Mask & AttributeImpl::getAttrMask(I)) != 0) - Attrs.insert(I); + ConstantInt *Kind = cast<ConstantInt>(Attr.getAttributeKind()); + Attribute::AttrKind KindVal = Attribute::AttrKind(Kind->getZExtValue()); + Attrs.insert(KindVal); - if (Attr.getAlignment()) + if (KindVal == Attribute::Alignment) Alignment = Attr.getAlignment(); - if (Attr.getStackAlignment()) + else if (KindVal == Attribute::StackAlignment) StackAlignment = Attr.getStackAlignment(); return *this; } |