diff options
author | Peter Collingbourne <peter@pcc.me.uk> | 2013-08-02 22:29:40 +0000 |
---|---|---|
committer | Peter Collingbourne <peter@pcc.me.uk> | 2013-08-02 22:29:40 +0000 |
commit | bd6c7459bb1be4b492be95a3b19ab2dccaa7f53a (patch) | |
tree | 40e5bb226cc050b40261dbb5667ba50f95abf5b9 /llvm/lib/IR/Attributes.cpp | |
parent | f6e90afbf4bfee9894fed71656969bdee410b1d4 (diff) | |
download | bcm5719-llvm-bd6c7459bb1be4b492be95a3b19ab2dccaa7f53a.tar.gz bcm5719-llvm-bd6c7459bb1be4b492be95a3b19ab2dccaa7f53a.zip |
Make one of the AttributeSet ctors maintain the invariant that the
attribute list is ordered by index.
Differential Revision: http://llvm-reviews.chandlerc.com/D1265
llvm-svn: 187682
Diffstat (limited to 'llvm/lib/IR/Attributes.cpp')
-rw-r--r-- | llvm/lib/IR/Attributes.cpp | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/llvm/lib/IR/Attributes.cpp b/llvm/lib/IR/Attributes.cpp index 894ff7dda1f..c4834671ac6 100644 --- a/llvm/lib/IR/Attributes.cpp +++ b/llvm/lib/IR/Attributes.cpp @@ -621,12 +621,30 @@ AttributeSet AttributeSet::get(LLVMContext &C, unsigned Index, AttributeSet AttributeSet::get(LLVMContext &C, ArrayRef<AttributeSet> Attrs) { if (Attrs.empty()) return AttributeSet(); + if (Attrs.size() == 1) return Attrs[0]; SmallVector<std::pair<unsigned, AttributeSetNode*>, 8> AttrNodeVec; - for (unsigned I = 0, E = Attrs.size(); I != E; ++I) { + AttributeSetImpl *A0 = Attrs[0].pImpl; + if (A0) + AttrNodeVec.append(A0->getNode(0), A0->getNode(A0->getNumAttributes())); + // Copy all attributes from Attrs into AttrNodeVec while keeping AttrNodeVec + // ordered by index. Because we know that each list in Attrs is ordered by + // index we only need to merge each successive list in rather than doing a + // full sort. + for (unsigned I = 1, E = Attrs.size(); I != E; ++I) { AttributeSetImpl *AS = Attrs[I].pImpl; if (!AS) continue; - AttrNodeVec.append(AS->getNode(0), AS->getNode(AS->getNumAttributes())); + SmallVector<std::pair<unsigned, AttributeSetNode *>, 8>::iterator + ANVI = AttrNodeVec.begin(), ANVE; + for (const AttributeSetImpl::IndexAttrPair + *AI = AS->getNode(0), + *AE = AS->getNode(AS->getNumAttributes()); + AI != AE; ++AI) { + ANVE = AttrNodeVec.end(); + while (ANVI != ANVE && ANVI->first <= AI->first) + ++ANVI; + ANVI = AttrNodeVec.insert(ANVI, *AI) + 1; + } } return getImpl(C, AttrNodeVec); |