summaryrefslogtreecommitdiff
path: root/lib/IR
diff options
context:
space:
mode:
authorPeter Collingbourne <peter@pcc.me.uk>2013-08-02 22:29:40 +0000
committerPeter Collingbourne <peter@pcc.me.uk>2013-08-02 22:29:40 +0000
commit7bba9c5c0a5235f585ee4bd3efec29e0982de3f8 (patch)
treea71aaf7262c355f807479751ebe690794b2ce8d6 /lib/IR
parent6bf104b165cec9c14dacf10bf3380eeb32c278d7 (diff)
downloadllvm-7bba9c5c0a5235f585ee4bd3efec29e0982de3f8.tar.gz
llvm-7bba9c5c0a5235f585ee4bd3efec29e0982de3f8.tar.bz2
llvm-7bba9c5c0a5235f585ee4bd3efec29e0982de3f8.tar.xz
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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@187682 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/IR')
-rw-r--r--lib/IR/AttributeImpl.h9
-rw-r--r--lib/IR/Attributes.cpp22
2 files changed, 29 insertions, 2 deletions
diff --git a/lib/IR/AttributeImpl.h b/lib/IR/AttributeImpl.h
index 5a72c37505..7bf9e8ab6b 100644
--- a/lib/IR/AttributeImpl.h
+++ b/lib/IR/AttributeImpl.h
@@ -200,6 +200,15 @@ public:
AttributeSetImpl(LLVMContext &C,
ArrayRef<std::pair<unsigned, AttributeSetNode *> > Attrs)
: Context(C), NumAttrs(Attrs.size()) {
+#ifndef NDEBUG
+ if (Attrs.size() >= 2) {
+ for (const std::pair<unsigned, AttributeSetNode *> *i = Attrs.begin() + 1,
+ *e = Attrs.end();
+ i != e; ++i) {
+ assert((i-1)->first <= i->first && "Attribute set not ordered!");
+ }
+ }
+#endif
// There's memory after the node where we can store the entries in.
std::copy(Attrs.begin(), Attrs.end(),
reinterpret_cast<IndexAttrPair *>(this + 1));
diff --git a/lib/IR/Attributes.cpp b/lib/IR/Attributes.cpp
index 894ff7dda1..c4834671ac 100644
--- a/lib/IR/Attributes.cpp
+++ b/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);