aboutsummaryrefslogtreecommitdiff
path: root/lib/IR/Attributes.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/IR/Attributes.cpp')
-rw-r--r--lib/IR/Attributes.cpp142
1 files changed, 64 insertions, 78 deletions
diff --git a/lib/IR/Attributes.cpp b/lib/IR/Attributes.cpp
index 6eb51f0edc..4fe6f9ddc5 100644
--- a/lib/IR/Attributes.cpp
+++ b/lib/IR/Attributes.cpp
@@ -195,6 +195,8 @@ std::string Attribute::getAsString(bool InAttrGrp) const {
return "readnone";
if (hasAttribute(Attribute::ReadOnly))
return "readonly";
+ if (hasAttribute(Attribute::Returned))
+ return "returned";
if (hasAttribute(Attribute::ReturnsTwice))
return "returns_twice";
if (hasAttribute(Attribute::SExt))
@@ -393,6 +395,7 @@ uint64_t AttributeImpl::getAttrMask(Attribute::AttrKind Val) {
case Attribute::SanitizeThread: return 1ULL << 36;
case Attribute::SanitizeMemory: return 1ULL << 37;
case Attribute::NoBuiltin: return 1ULL << 38;
+ case Attribute::Returned: return 1ULL << 39;
}
llvm_unreachable("Unsupported attribute type");
}
@@ -481,11 +484,12 @@ unsigned AttributeSetNode::getStackAlignment() const {
}
std::string AttributeSetNode::getAsString(bool InAttrGrp) const {
- std::string Str = "";
+ std::string Str;
for (SmallVectorImpl<Attribute>::const_iterator I = AttrList.begin(),
- E = AttrList.end(); I != E; ) {
+ E = AttrList.end(); I != E; ++I) {
+ if (I != AttrList.begin())
+ Str += ' ';
Str += I->getAsString(InAttrGrp);
- if (++I != E) Str += " ";
}
return Str;
}
@@ -494,7 +498,7 @@ std::string AttributeSetNode::getAsString(bool InAttrGrp) const {
// AttributeSetImpl Definition
//===----------------------------------------------------------------------===//
-uint64_t AttributeSetImpl::Raw(uint64_t Index) const {
+uint64_t AttributeSetImpl::Raw(unsigned Index) const {
for (unsigned I = 0, E = getNumAttributes(); I != E; ++I) {
if (getSlotIndex(I) != Index) continue;
const AttributeSetNode *ASN = AttrNodes[I].second;
@@ -592,7 +596,7 @@ AttributeSet AttributeSet::get(LLVMContext &C,
return getImpl(C, Attrs);
}
-AttributeSet AttributeSet::get(LLVMContext &C, unsigned Idx, AttrBuilder &B) {
+AttributeSet AttributeSet::get(LLVMContext &C, unsigned Index, AttrBuilder &B) {
if (!B.hasAttributes())
return AttributeSet();
@@ -604,29 +608,29 @@ AttributeSet AttributeSet::get(LLVMContext &C, unsigned Idx, AttrBuilder &B) {
continue;
if (Kind == Attribute::Alignment)
- Attrs.push_back(std::make_pair(Idx, Attribute::
+ Attrs.push_back(std::make_pair(Index, Attribute::
getWithAlignment(C, B.getAlignment())));
else if (Kind == Attribute::StackAlignment)
- Attrs.push_back(std::make_pair(Idx, Attribute::
+ Attrs.push_back(std::make_pair(Index, Attribute::
getWithStackAlignment(C, B.getStackAlignment())));
else
- Attrs.push_back(std::make_pair(Idx, Attribute::get(C, Kind)));
+ Attrs.push_back(std::make_pair(Index, Attribute::get(C, Kind)));
}
// Add target-dependent (string) attributes.
for (AttrBuilder::td_iterator I = B.td_begin(), E = B.td_end();
I != E; ++I)
- Attrs.push_back(std::make_pair(Idx, Attribute::get(C, I->first,I->second)));
+ Attrs.push_back(std::make_pair(Index, Attribute::get(C, I->first,I->second)));
return get(C, Attrs);
}
-AttributeSet AttributeSet::get(LLVMContext &C, unsigned Idx,
+AttributeSet AttributeSet::get(LLVMContext &C, unsigned Index,
ArrayRef<Attribute::AttrKind> Kind) {
SmallVector<std::pair<unsigned, Attribute>, 8> Attrs;
for (ArrayRef<Attribute::AttrKind>::iterator I = Kind.begin(),
E = Kind.end(); I != E; ++I)
- Attrs.push_back(std::make_pair(Idx, Attribute::get(C, *I)));
+ Attrs.push_back(std::make_pair(Index, Attribute::get(C, *I)));
return get(C, Attrs);
}
@@ -643,12 +647,20 @@ AttributeSet AttributeSet::get(LLVMContext &C, ArrayRef<AttributeSet> Attrs) {
return getImpl(C, AttrNodeVec);
}
-AttributeSet AttributeSet::addAttribute(LLVMContext &C, unsigned Idx,
+AttributeSet AttributeSet::addAttribute(LLVMContext &C, unsigned Index,
Attribute::AttrKind Attr) const {
- return addAttributes(C, Idx, AttributeSet::get(C, Idx, Attr));
+ if (hasAttribute(Index, Attr)) return *this;
+ return addAttributes(C, Index, AttributeSet::get(C, Index, Attr));
}
-AttributeSet AttributeSet::addAttributes(LLVMContext &C, unsigned Idx,
+AttributeSet AttributeSet::addAttribute(LLVMContext &C, unsigned Index,
+ StringRef Kind) const {
+ llvm::AttrBuilder B;
+ B.addAttribute(Kind);
+ return addAttributes(C, Index, AttributeSet::get(C, Index, B));
+}
+
+AttributeSet AttributeSet::addAttributes(LLVMContext &C, unsigned Index,
AttributeSet Attrs) const {
if (!pImpl) return Attrs;
if (!Attrs.pImpl) return *this;
@@ -656,8 +668,8 @@ AttributeSet AttributeSet::addAttributes(LLVMContext &C, unsigned Idx,
#ifndef NDEBUG
// FIXME it is not obvious how this should work for alignment. For now, say
// we can't change a known alignment.
- unsigned OldAlign = getParamAlignment(Idx);
- unsigned NewAlign = Attrs.getParamAlignment(Idx);
+ unsigned OldAlign = getParamAlignment(Index);
+ unsigned NewAlign = Attrs.getParamAlignment(Index);
assert((!OldAlign || !NewAlign || OldAlign == NewAlign) &&
"Attempt to change alignment!");
#endif
@@ -668,8 +680,8 @@ AttributeSet AttributeSet::addAttributes(LLVMContext &C, unsigned Idx,
AttributeSet AS;
uint64_t LastIndex = 0;
for (unsigned I = 0, E = NumAttrs; I != E; ++I) {
- if (getSlotIndex(I) >= Idx) {
- if (getSlotIndex(I) == Idx) AS = getSlotAttributes(LastIndex++);
+ if (getSlotIndex(I) >= Index) {
+ if (getSlotIndex(I) == Index) AS = getSlotAttributes(LastIndex++);
break;
}
LastIndex = I + 1;
@@ -678,17 +690,17 @@ AttributeSet AttributeSet::addAttributes(LLVMContext &C, unsigned Idx,
// Now add the attribute into the correct slot. There may already be an
// AttributeSet there.
- AttrBuilder B(AS, Idx);
+ AttrBuilder B(AS, Index);
for (unsigned I = 0, E = Attrs.pImpl->getNumAttributes(); I != E; ++I)
- if (Attrs.getSlotIndex(I) == Idx) {
+ if (Attrs.getSlotIndex(I) == Index) {
for (AttributeSetImpl::const_iterator II = Attrs.pImpl->begin(I),
IE = Attrs.pImpl->end(I); II != IE; ++II)
B.addAttribute(*II);
break;
}
- AttrSet.push_back(AttributeSet::get(C, Idx, B));
+ AttrSet.push_back(AttributeSet::get(C, Index, B));
// Add the remaining attribute slots.
for (unsigned I = LastIndex, E = NumAttrs; I < E; ++I)
@@ -697,12 +709,13 @@ AttributeSet AttributeSet::addAttributes(LLVMContext &C, unsigned Idx,
return get(C, AttrSet);
}
-AttributeSet AttributeSet::removeAttribute(LLVMContext &C, unsigned Idx,
+AttributeSet AttributeSet::removeAttribute(LLVMContext &C, unsigned Index,
Attribute::AttrKind Attr) const {
- return removeAttributes(C, Idx, AttributeSet::get(C, Idx, Attr));
+ if (!hasAttribute(Index, Attr)) return *this;
+ return removeAttributes(C, Index, AttributeSet::get(C, Index, Attr));
}
-AttributeSet AttributeSet::removeAttributes(LLVMContext &C, unsigned Idx,
+AttributeSet AttributeSet::removeAttributes(LLVMContext &C, unsigned Index,
AttributeSet Attrs) const {
if (!pImpl) return AttributeSet();
if (!Attrs.pImpl) return *this;
@@ -710,7 +723,7 @@ AttributeSet AttributeSet::removeAttributes(LLVMContext &C, unsigned Idx,
#ifndef NDEBUG
// FIXME it is not obvious how this should work for alignment.
// For now, say we can't pass in alignment, which no current use does.
- assert(!Attrs.hasAttribute(Idx, Attribute::Alignment) &&
+ assert(!Attrs.hasAttribute(Index, Attribute::Alignment) &&
"Attempt to change alignment!");
#endif
@@ -720,8 +733,8 @@ AttributeSet AttributeSet::removeAttributes(LLVMContext &C, unsigned Idx,
AttributeSet AS;
uint64_t LastIndex = 0;
for (unsigned I = 0, E = NumAttrs; I != E; ++I) {
- if (getSlotIndex(I) >= Idx) {
- if (getSlotIndex(I) == Idx) AS = getSlotAttributes(LastIndex++);
+ if (getSlotIndex(I) >= Index) {
+ if (getSlotIndex(I) == Index) AS = getSlotAttributes(LastIndex++);
break;
}
LastIndex = I + 1;
@@ -730,15 +743,15 @@ AttributeSet AttributeSet::removeAttributes(LLVMContext &C, unsigned Idx,
// Now remove the attribute from the correct slot. There may already be an
// AttributeSet there.
- AttrBuilder B(AS, Idx);
+ AttrBuilder B(AS, Index);
for (unsigned I = 0, E = Attrs.pImpl->getNumAttributes(); I != E; ++I)
- if (Attrs.getSlotIndex(I) == Idx) {
- B.removeAttributes(Attrs.pImpl->getSlotAttributes(I), Idx);
+ if (Attrs.getSlotIndex(I) == Index) {
+ B.removeAttributes(Attrs.pImpl->getSlotAttributes(I), Index);
break;
}
- AttrSet.push_back(AttributeSet::get(C, Idx, B));
+ AttrSet.push_back(AttributeSet::get(C, Index, B));
// Add the remaining attribute slots.
for (unsigned I = LastIndex, E = NumAttrs; I < E; ++I)
@@ -755,11 +768,11 @@ LLVMContext &AttributeSet::getContext() const {
return pImpl->getContext();
}
-AttributeSet AttributeSet::getParamAttributes(unsigned Idx) const {
- return pImpl && hasAttributes(Idx) ?
+AttributeSet AttributeSet::getParamAttributes(unsigned Index) const {
+ return pImpl && hasAttributes(Index) ?
AttributeSet::get(pImpl->getContext(),
ArrayRef<std::pair<unsigned, AttributeSetNode*> >(
- std::make_pair(Idx, getAttributes(Idx)))) :
+ std::make_pair(Index, getAttributes(Index)))) :
AttributeSet();
}
@@ -839,27 +852,27 @@ std::string AttributeSet::getAsString(unsigned Index,
}
/// \brief The attributes for the specified index are returned.
-AttributeSetNode *AttributeSet::getAttributes(unsigned Idx) const {
+AttributeSetNode *AttributeSet::getAttributes(unsigned Index) const {
if (!pImpl) return 0;
// Loop through to find the attribute node we want.
for (unsigned I = 0, E = pImpl->getNumAttributes(); I != E; ++I)
- if (pImpl->getSlotIndex(I) == Idx)
+ if (pImpl->getSlotIndex(I) == Index)
return pImpl->getSlotNode(I);
return 0;
}
-AttributeSet::iterator AttributeSet::begin(unsigned Idx) const {
+AttributeSet::iterator AttributeSet::begin(unsigned Slot) const {
if (!pImpl)
return ArrayRef<Attribute>().begin();
- return pImpl->begin(Idx);
+ return pImpl->begin(Slot);
}
-AttributeSet::iterator AttributeSet::end(unsigned Idx) const {
+AttributeSet::iterator AttributeSet::end(unsigned Slot) const {
if (!pImpl)
return ArrayRef<Attribute>().end();
- return pImpl->end(Idx);
+ return pImpl->end(Slot);
}
//===----------------------------------------------------------------------===//
@@ -873,7 +886,7 @@ unsigned AttributeSet::getNumSlots() const {
return pImpl ? pImpl->getNumAttributes() : 0;
}
-uint64_t AttributeSet::getSlotIndex(unsigned Slot) const {
+unsigned AttributeSet::getSlotIndex(unsigned Slot) const {
assert(pImpl && Slot < pImpl->getNumAttributes() &&
"Slot # out of range!");
return pImpl->getSlotIndex(Slot);
@@ -910,13 +923,13 @@ void AttributeSet::dump() const {
// AttrBuilder Method Implementations
//===----------------------------------------------------------------------===//
-AttrBuilder::AttrBuilder(AttributeSet AS, unsigned Idx)
+AttrBuilder::AttrBuilder(AttributeSet AS, unsigned Index)
: Attrs(0), Alignment(0), StackAlignment(0) {
AttributeSetImpl *pImpl = AS.pImpl;
if (!pImpl) return;
for (unsigned I = 0, E = pImpl->getNumAttributes(); I != E; ++I) {
- if (pImpl->getSlotIndex(I) != Idx) continue;
+ if (pImpl->getSlotIndex(I) != Index) continue;
for (AttributeSetImpl::const_iterator II = pImpl->begin(I),
IE = pImpl->end(I); II != IE; ++II)
@@ -973,16 +986,16 @@ AttrBuilder &AttrBuilder::removeAttribute(Attribute::AttrKind Val) {
}
AttrBuilder &AttrBuilder::removeAttributes(AttributeSet A, uint64_t Index) {
- unsigned Idx = ~0U;
+ unsigned Slot = ~0U;
for (unsigned I = 0, E = A.getNumSlots(); I != E; ++I)
if (A.getSlotIndex(I) == Index) {
- Idx = I;
+ Slot = I;
break;
}
- assert(Idx != ~0U && "Couldn't find index in AttributeSet!");
+ assert(Slot != ~0U && "Couldn't find index in AttributeSet!");
- for (AttributeSet::iterator I = A.begin(Idx), E = A.end(Idx); I != E; ++I) {
+ for (AttributeSet::iterator I = A.begin(Slot), E = A.end(Slot); I != E; ++I) {
Attribute Attr = *I;
if (Attr.isEnumAttribute() || Attr.isAlignAttribute()) {
Attribute::AttrKind Kind = I->getKindAsEnum();
@@ -1060,16 +1073,16 @@ bool AttrBuilder::hasAttributes() const {
}
bool AttrBuilder::hasAttributes(AttributeSet A, uint64_t Index) const {
- unsigned Idx = ~0U;
+ unsigned Slot = ~0U;
for (unsigned I = 0, E = A.getNumSlots(); I != E; ++I)
if (A.getSlotIndex(I) == Index) {
- Idx = I;
+ Slot = I;
break;
}
- assert(Idx != ~0U && "Couldn't find the index!");
+ assert(Slot != ~0U && "Couldn't find the index!");
- for (AttributeSet::iterator I = A.begin(Idx), E = A.end(Idx);
+ for (AttributeSet::iterator I = A.begin(Slot), E = A.end(Slot);
I != E; ++I) {
Attribute Attr = *I;
if (Attr.isEnumAttribute() || Attr.isAlignAttribute()) {
@@ -1100,33 +1113,6 @@ bool AttrBuilder::operator==(const AttrBuilder &B) {
return Alignment == B.Alignment && StackAlignment == B.StackAlignment;
}
-void AttrBuilder::removeFunctionOnlyAttrs() {
- removeAttribute(Attribute::NoReturn)
- .removeAttribute(Attribute::NoUnwind)
- .removeAttribute(Attribute::ReadNone)
- .removeAttribute(Attribute::ReadOnly)
- .removeAttribute(Attribute::NoInline)
- .removeAttribute(Attribute::AlwaysInline)
- .removeAttribute(Attribute::OptimizeForSize)
- .removeAttribute(Attribute::StackProtect)
- .removeAttribute(Attribute::StackProtectReq)
- .removeAttribute(Attribute::StackProtectStrong)
- .removeAttribute(Attribute::NoRedZone)
- .removeAttribute(Attribute::NoImplicitFloat)
- .removeAttribute(Attribute::Naked)
- .removeAttribute(Attribute::InlineHint)
- .removeAttribute(Attribute::StackAlignment)
- .removeAttribute(Attribute::UWTable)
- .removeAttribute(Attribute::NonLazyBind)
- .removeAttribute(Attribute::ReturnsTwice)
- .removeAttribute(Attribute::SanitizeAddress)
- .removeAttribute(Attribute::SanitizeThread)
- .removeAttribute(Attribute::SanitizeMemory)
- .removeAttribute(Attribute::MinSize)
- .removeAttribute(Attribute::NoDuplicate)
- .removeAttribute(Attribute::NoBuiltin);
-}
-
AttrBuilder &AttrBuilder::addRawValue(uint64_t Val) {
// FIXME: Remove this in 4.0.
if (!Val) return *this;