diff options
author | Bill Wendling <isanbard@gmail.com> | 2013-01-05 01:36:54 +0000 |
---|---|---|
committer | Bill Wendling <isanbard@gmail.com> | 2013-01-05 01:36:54 +0000 |
commit | 960f52a1322931129f75f558ffc5a28d95a7604d (patch) | |
tree | a73adad9c20e2ca724821575af9e047b24e9514f /llvm/lib/IR/Attributes.cpp | |
parent | 3c98afe2aed24d8a38770a894d4d0fb9f7d03f23 (diff) | |
download | bcm5719-llvm-960f52a1322931129f75f558ffc5a28d95a7604d.tar.gz bcm5719-llvm-960f52a1322931129f75f558ffc5a28d95a7604d.zip |
Add a method to create an AttributeSet from an AttrBuilder.
The Attribute class is eventually going to represent one attribute. So we need
this class to create the set of attributes. Add some iterator methods to the
builder to access its internal bits in a nice way.
llvm-svn: 171586
Diffstat (limited to 'llvm/lib/IR/Attributes.cpp')
-rw-r--r-- | llvm/lib/IR/Attributes.cpp | 52 |
1 files changed, 46 insertions, 6 deletions
diff --git a/llvm/lib/IR/Attributes.cpp b/llvm/lib/IR/Attributes.cpp index 068b5042948..84f90ade8b2 100644 --- a/llvm/lib/IR/Attributes.cpp +++ b/llvm/lib/IR/Attributes.cpp @@ -76,6 +76,12 @@ unsigned Attribute::getAlignment() const { return 1U << ((pImpl->getAlignment() >> 16) - 1); } +void Attribute::setAlignment(unsigned Align) { + assert(hasAttribute(Attribute::Alignment) && + "Trying to set the alignment on a non-alignment attribute!"); + pImpl->setAlignment(Align); +} + /// This returns the stack alignment field of an attribute as a byte alignment /// value. unsigned Attribute::getStackAlignment() const { @@ -84,6 +90,12 @@ unsigned Attribute::getStackAlignment() const { return 1U << ((pImpl->getStackAlignment() >> 26) - 1); } +void Attribute::setStackAlignment(unsigned Align) { + assert(hasAttribute(Attribute::StackAlignment) && + "Trying to set the stack alignment on a non-alignment attribute!"); + pImpl->setStackAlignment(Align); +} + bool Attribute::operator==(AttrKind K) const { return pImpl && *pImpl == K; } @@ -367,19 +379,23 @@ bool AttrBuilder::operator==(const AttrBuilder &B) { // AttributeImpl Definition //===----------------------------------------------------------------------===// -AttributeImpl::AttributeImpl(LLVMContext &C, uint64_t data) { +AttributeImpl::AttributeImpl(LLVMContext &C, uint64_t data) + : Context(C) { Data = ConstantInt::get(Type::getInt64Ty(C), data); } -AttributeImpl::AttributeImpl(LLVMContext &C, Attribute::AttrKind data) { +AttributeImpl::AttributeImpl(LLVMContext &C, Attribute::AttrKind data) + : Context(C) { Data = ConstantInt::get(Type::getInt64Ty(C), data); } AttributeImpl::AttributeImpl(LLVMContext &C, Attribute::AttrKind data, - ArrayRef<Constant*> values) { + ArrayRef<Constant*> values) + : Context(C) { Data = ConstantInt::get(Type::getInt64Ty(C), data); Vals.reserve(values.size()); Vals.append(values.begin(), values.end()); } -AttributeImpl::AttributeImpl(LLVMContext &C, StringRef data) { +AttributeImpl::AttributeImpl(LLVMContext &C, StringRef data) + : Context(C) { Data = ConstantDataArray::getString(C, data); } @@ -456,10 +472,18 @@ uint64_t AttributeImpl::getAlignment() const { return getBitMask() & getAttrMask(Attribute::Alignment); } +void AttributeImpl::setAlignment(unsigned Align) { + Vals.push_back(ConstantInt::get(Type::getInt64Ty(Context), Align)); +} + uint64_t AttributeImpl::getStackAlignment() const { return getBitMask() & getAttrMask(Attribute::StackAlignment); } +void AttributeImpl::setStackAlignment(unsigned Align) { + Vals.push_back(ConstantInt::get(Type::getInt64Ty(Context), Align)); +} + //===----------------------------------------------------------------------===// // AttributeSetImpl Definition //===----------------------------------------------------------------------===// @@ -485,8 +509,7 @@ AttributeSet AttributeSet::get(LLVMContext &C, AttributeSetImpl::Profile(ID, Attrs); void *InsertPoint; - AttributeSetImpl *PA = pImpl->AttrsLists.FindNodeOrInsertPos(ID, - InsertPoint); + AttributeSetImpl *PA = pImpl->AttrsLists.FindNodeOrInsertPos(ID, InsertPoint); // If we didn't find any existing attributes of the same shape then // create a new one and insert it. @@ -499,6 +522,23 @@ AttributeSet AttributeSet::get(LLVMContext &C, return AttributeSet(PA); } +AttributeSet AttributeSet::get(LLVMContext &C, unsigned Idx, AttrBuilder &B) { + SmallVector<AttributeWithIndex, 8> Attrs; + for (AttrBuilder::iterator I = B.begin(), E = B.end(); I != E; ++I) { + Attribute::AttrKind Kind = *I; + Attribute A = Attribute::get(C, Kind); + + if (Kind == Attribute::Alignment) + A.setAlignment(B.getAlignment()); + else if (Kind == Attribute::StackAlignment) + A.setStackAlignment(B.getStackAlignment()); + + Attrs.push_back(AttributeWithIndex::get(Idx, A)); + } + + return get(C, Attrs); +} + //===----------------------------------------------------------------------===// // AttributeSet Method Implementations //===----------------------------------------------------------------------===// |