diff options
author | Reid Kleckner <rnk@google.com> | 2017-04-13 00:58:09 +0000 |
---|---|---|
committer | Reid Kleckner <rnk@google.com> | 2017-04-13 00:58:09 +0000 |
commit | 7f72033e1cde7a3a76da8c79634dfb7bf4919b54 (patch) | |
tree | 91cd8b6c041464464cf122c8b204588149e44536 /llvm/lib/IR/Attributes.cpp | |
parent | 4104cf8257717c068622383441ee37bacaa1b74a (diff) | |
download | bcm5719-llvm-7f72033e1cde7a3a76da8c79634dfb7bf4919b54.tar.gz bcm5719-llvm-7f72033e1cde7a3a76da8c79634dfb7bf4919b54.zip |
[IR] Take func, ret, and arg attrs separately in AttributeList::get
This seems like a much more natural API, based on Derek Schuff's
comments on r300015. It further hides the implementation detail of
AttributeList that function attributes come last and appear at index
~0U, which is easy for the user to screw up. git diff says it saves code
as well: 97 insertions(+), 137 deletions(-)
This also makes it easier to change the implementation, which I want to
do next.
llvm-svn: 300153
Diffstat (limited to 'llvm/lib/IR/Attributes.cpp')
-rw-r--r-- | llvm/lib/IR/Attributes.cpp | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/llvm/lib/IR/Attributes.cpp b/llvm/lib/IR/Attributes.cpp index 7faac60208f..2e3d7bdf709 100644 --- a/llvm/lib/IR/Attributes.cpp +++ b/llvm/lib/IR/Attributes.cpp @@ -778,7 +778,7 @@ AttributeList AttributeList::getImpl( #ifndef NDEBUG unsigned LastIndex = 0; bool IsFirst = true; - for (const auto &AttrPair : Attrs) { + for (auto &&AttrPair : Attrs) { assert((IsFirst || LastIndex < AttrPair.first) && "unsorted or duplicate AttributeList indices"); assert(AttrPair.second.hasAttributes() && "pointless AttributeList slot"); @@ -855,20 +855,20 @@ AttributeList::get(LLVMContext &C, return getImpl(C, Attrs); } -AttributeList AttributeList::get(LLVMContext &C, ArrayRef<AttributeSet> Attrs) { - assert(Attrs.size() >= 2 && - "should always have function and return attr slots"); +AttributeList AttributeList::get(LLVMContext &C, AttributeSet FnAttrs, + AttributeSet RetAttrs, + ArrayRef<AttributeSet> ArgAttrs) { SmallVector<std::pair<unsigned, AttributeSet>, 8> AttrPairs; - size_t Index = 0; - for (AttributeSet AS : Attrs) { - if (AS.hasAttributes()) { - // If this is the last AttributeSetNode, it's for the function. - if (Index == Attrs.size() - 1) - Index = AttributeList::FunctionIndex; + if (RetAttrs.hasAttributes()) + AttrPairs.emplace_back(ReturnIndex, RetAttrs); + size_t Index = 1; + for (AttributeSet AS : ArgAttrs) { + if (AS.hasAttributes()) AttrPairs.emplace_back(Index, AS); - } ++Index; } + if (FnAttrs.hasAttributes()) + AttrPairs.emplace_back(FunctionIndex, FnAttrs); if (AttrPairs.empty()) return AttributeList(); return getImpl(C, AttrPairs); |