summaryrefslogtreecommitdiffstats
path: root/llvm/lib/IR
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/IR')
-rw-r--r--llvm/lib/IR/Attributes.cpp14
-rw-r--r--llvm/lib/IR/Core.cpp8
2 files changed, 18 insertions, 4 deletions
diff --git a/llvm/lib/IR/Attributes.cpp b/llvm/lib/IR/Attributes.cpp
index 0cdc48e2d64..158a02337ad 100644
--- a/llvm/lib/IR/Attributes.cpp
+++ b/llvm/lib/IR/Attributes.cpp
@@ -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())
diff --git a/llvm/lib/IR/Core.cpp b/llvm/lib/IR/Core.cpp
index f1843593a3b..2636ca1a724 100644
--- a/llvm/lib/IR/Core.cpp
+++ b/llvm/lib/IR/Core.cpp
@@ -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()))
OpenPOWER on IntegriCloud