/// value.
unsigned getAlignment() const;
+ /// \brief Set the alignment field of an attribute.
+ void setAlignment(unsigned Align);
+
/// \brief Returns the stack alignment field of an attribute as a byte
/// alignment value.
unsigned getStackAlignment() const;
+ /// \brief Set the stack alignment field of an attribute.
+ void setStackAlignment(unsigned Align);
+
/// \brief Equality and non-equality query methods.
bool operator==(AttrKind K) const;
bool operator!=(AttrKind K) const;
/// the form used internally in Attribute.
AttrBuilder &addStackAlignmentAttr(unsigned Align);
+ typedef DenseSet<Attribute::AttrKind>::iterator iterator;
+ typedef DenseSet<Attribute::AttrKind>::const_iterator const_iterator;
+
+ iterator begin() { return Attrs.begin(); }
+ iterator end() { return Attrs.end(); }
+
+ const_iterator begin() const { return Attrs.begin(); }
+ const_iterator end() const { return Attrs.end(); }
+
/// \brief Add the raw value to the internal representation.
///
/// N.B. This should be used ONLY for decoding LLVM bitcode!
/// \brief Return an AttributeSet with the specified parameters in it.
static AttributeSet get(LLVMContext &C, ArrayRef<AttributeWithIndex> Attrs);
+ static AttributeSet get(LLVMContext &C, unsigned Idx, AttrBuilder &B);
/// \brief Add the specified attribute at the specified index to this
/// attribute list. Since attribute lists are immutable, this returns the new
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 {
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;
}
// 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);
}
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
//===----------------------------------------------------------------------===//
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.
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
//===----------------------------------------------------------------------===//