summaryrefslogtreecommitdiffstats
path: root/llvm/lib/IR/Attributes.cpp
diff options
context:
space:
mode:
authorReid Kleckner <rnk@google.com>2017-05-31 19:23:09 +0000
committerReid Kleckner <rnk@google.com>2017-05-31 19:23:09 +0000
commit5fbdd17714e2b0ab6974787c43bf1758ea451d78 (patch)
tree5b0b68a3b37f1146ef3a77fb9055372886286793 /llvm/lib/IR/Attributes.cpp
parent23db6360804901e2df536c821c5a9f829e89545d (diff)
downloadbcm5719-llvm-5fbdd17714e2b0ab6974787c43bf1758ea451d78.tar.gz
bcm5719-llvm-5fbdd17714e2b0ab6974787c43bf1758ea451d78.zip
[IR] Add additional addParamAttr/removeParamAttr to AttributeList API
Summary: Fairly straightforward patch to fill in some of the holes in the attributes API with respect to accessing parameter/argument attributes. The patch aims to step further towards encapsulating the idx+FirstArgIndex pattern to access these attributes to within the AttributeList. Patch by Daniel Neilson! Reviewers: rnk, chandlerc, pete, javed.absar, reames Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D33355 llvm-svn: 304329
Diffstat (limited to 'llvm/lib/IR/Attributes.cpp')
-rw-r--r--llvm/lib/IR/Attributes.cpp41
1 files changed, 24 insertions, 17 deletions
diff --git a/llvm/lib/IR/Attributes.cpp b/llvm/lib/IR/Attributes.cpp
index a6d1c9035af..a76c944f000 100644
--- a/llvm/lib/IR/Attributes.cpp
+++ b/llvm/lib/IR/Attributes.cpp
@@ -1037,24 +1037,11 @@ AttributeList AttributeList::addAttribute(LLVMContext &C, unsigned Index,
return addAttributes(C, Index, B);
}
-AttributeList AttributeList::addAttribute(LLVMContext &C,
- ArrayRef<unsigned> Indices,
+AttributeList AttributeList::addAttribute(LLVMContext &C, unsigned Index,
Attribute A) const {
- assert(std::is_sorted(Indices.begin(), Indices.end()));
-
- SmallVector<AttributeSet, 4> AttrSets(this->begin(), this->end());
- unsigned MaxIndex = attrIdxToArrayIdx(Indices.back());
- if (MaxIndex >= AttrSets.size())
- AttrSets.resize(MaxIndex + 1);
-
- for (unsigned Index : Indices) {
- Index = attrIdxToArrayIdx(Index);
- AttrBuilder B(AttrSets[Index]);
- B.addAttribute(A);
- AttrSets[Index] = AttributeSet::get(C, B);
- }
-
- return getImpl(C, AttrSets);
+ AttrBuilder B;
+ B.addAttribute(A);
+ return addAttributes(C, Index, B);
}
AttributeList AttributeList::addAttributes(LLVMContext &C, unsigned Index,
@@ -1086,6 +1073,26 @@ AttributeList AttributeList::addAttributes(LLVMContext &C, unsigned Index,
return getImpl(C, AttrSets);
}
+AttributeList AttributeList::addParamAttribute(LLVMContext &C,
+ ArrayRef<unsigned> ArgNos,
+ Attribute A) const {
+ assert(std::is_sorted(ArgNos.begin(), ArgNos.end()));
+
+ SmallVector<AttributeSet, 4> AttrSets(this->begin(), this->end());
+ unsigned MaxIndex = attrIdxToArrayIdx(ArgNos.back() + FirstArgIndex);
+ if (MaxIndex >= AttrSets.size())
+ AttrSets.resize(MaxIndex + 1);
+
+ for (unsigned ArgNo : ArgNos) {
+ unsigned Index = attrIdxToArrayIdx(ArgNo + FirstArgIndex);
+ AttrBuilder B(AttrSets[Index]);
+ B.addAttribute(A);
+ AttrSets[Index] = AttributeSet::get(C, B);
+ }
+
+ return getImpl(C, AttrSets);
+}
+
AttributeList AttributeList::removeAttribute(LLVMContext &C, unsigned Index,
Attribute::AttrKind Kind) const {
if (!hasAttribute(Index, Kind)) return *this;
OpenPOWER on IntegriCloud