Remove AttributeSetNode::get(AttributeList, unsigned) and sink constructor

The getter was equivalent to AttributeList::getAttributes(unsigned),
which seems like a better way to express getting the AttributeSet for a
given index. This static helper was only used in one place anyway.

The constructor doesn't benefit from inlining and doesn't need to be in
a header.

llvm-svn: 299900
This commit is contained in:
Reid Kleckner 2017-04-10 23:46:08 +00:00
parent eb9dd5b87f
commit 8ff7785ee1
3 changed files with 19 additions and 21 deletions

View File

@ -43,19 +43,7 @@ class AttributeSetNode final
/// Bitset with a bit for each available attribute Attribute::AttrKind.
uint64_t AvailableAttrs;
AttributeSetNode(ArrayRef<Attribute> Attrs)
: NumAttrs(Attrs.size()), AvailableAttrs(0) {
static_assert(Attribute::EndAttrKinds <= sizeof(AvailableAttrs) * CHAR_BIT,
"Too many attributes for AvailableAttrs");
// There's memory after the node where we can store the entries in.
std::copy(Attrs.begin(), Attrs.end(), getTrailingObjects<Attribute>());
for (Attribute I : *this) {
if (!I.isStringAttribute()) {
AvailableAttrs |= ((uint64_t)1) << I.getKindAsEnum();
}
}
}
AttributeSetNode(ArrayRef<Attribute> Attrs);
public:
// AttributesSetNode is uniqued, these should not be available.
@ -68,10 +56,6 @@ public:
static AttributeSetNode *get(LLVMContext &C, ArrayRef<Attribute> Attrs);
static AttributeSetNode *get(AttributeList AS, unsigned Index) {
return AS.getAttributes(Index);
}
/// \brief Return the number of attributes this AttributeList contains.
unsigned getNumAttributes() const { return NumAttrs; }

View File

@ -495,6 +495,20 @@ bool AttributeImpl::operator<(const AttributeImpl &AI) const {
// AttributeSetNode Definition
//===----------------------------------------------------------------------===//
AttributeSetNode::AttributeSetNode(ArrayRef<Attribute> Attrs)
: NumAttrs(Attrs.size()), AvailableAttrs(0) {
static_assert(Attribute::EndAttrKinds <= sizeof(AvailableAttrs) * CHAR_BIT,
"Too many attributes for AvailableAttrs");
// There's memory after the node where we can store the entries in.
std::copy(Attrs.begin(), Attrs.end(), getTrailingObjects<Attribute>());
for (Attribute I : *this) {
if (!I.isStringAttribute()) {
AvailableAttrs |= ((uint64_t)1) << I.getKindAsEnum();
}
}
}
AttributeSetNode *AttributeSetNode::get(LLVMContext &C,
ArrayRef<Attribute> Attrs) {
if (Attrs.empty())

View File

@ -1847,7 +1847,7 @@ void LLVMAddAttributeAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx,
}
unsigned LLVMGetAttributeCountAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx) {
auto *ASN = AttributeSetNode::get(unwrap<Function>(F)->getAttributes(), Idx);
auto *ASN = unwrap<Function>(F)->getAttributes().getAttributes(Idx);
if (!ASN)
return 0;
return ASN->getNumAttributes();
@ -1855,7 +1855,7 @@ unsigned LLVMGetAttributeCountAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx) {
void LLVMGetAttributesAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx,
LLVMAttributeRef *Attrs) {
auto *ASN = AttributeSetNode::get(unwrap<Function>(F)->getAttributes(), Idx);
auto *ASN = unwrap<Function>(F)->getAttributes().getAttributes(Idx);
if (!ASN)
return;
for (auto A: make_range(ASN->begin(), ASN->end()))
@ -2178,7 +2178,7 @@ void LLVMAddCallSiteAttribute(LLVMValueRef C, LLVMAttributeIndex Idx,
unsigned LLVMGetCallSiteAttributeCount(LLVMValueRef C,
LLVMAttributeIndex Idx) {
auto CS = CallSite(unwrap<Instruction>(C));
auto *ASN = AttributeSetNode::get(CS.getAttributes(), Idx);
auto *ASN = CS.getAttributes().getAttributes(Idx);
if (!ASN)
return 0;
return ASN->getNumAttributes();
@ -2187,7 +2187,7 @@ unsigned LLVMGetCallSiteAttributeCount(LLVMValueRef C,
void LLVMGetCallSiteAttributes(LLVMValueRef C, LLVMAttributeIndex Idx,
LLVMAttributeRef *Attrs) {
auto CS = CallSite(unwrap<Instruction>(C));
auto *ASN = AttributeSetNode::get(CS.getAttributes(), Idx);
auto *ASN = CS.getAttributes().getAttributes(Idx);
if (!ASN)
return;
for (auto A: make_range(ASN->begin(), ASN->end()))