Have AttributeSet::getRetAttributes() return an AttributeSet instead of Attribute.

This further restricts the use of the Attribute class to the Attribute family of
classes.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@173098 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/IR/Attributes.cpp b/lib/IR/Attributes.cpp
index d3f284a..5c95d4a 100644
--- a/lib/IR/Attributes.cpp
+++ b/lib/IR/Attributes.cpp
@@ -544,9 +544,18 @@
 // AttributeSetImpl Definition
 //===----------------------------------------------------------------------===//
 
+AttributeSet AttributeSet::getRetAttributes() const {
+  // FIXME: Remove.
+  return AttrList && hasAttributes(ReturnIndex) ?
+    AttributeSet::get(AttrList->getContext(),
+                      AttributeWithIndex::get(ReturnIndex,
+                                              getAttributes(ReturnIndex))) :
+    AttributeSet();
+}
+
 AttributeSet AttributeSet::getFnAttributes() const {
   // FIXME: Remove.
-  return AttrList ?
+  return AttrList && hasAttributes(FunctionIndex) ?
     AttributeSet::get(AttrList->getContext(),
                       AttributeWithIndex::get(FunctionIndex,
                                               getAttributes(FunctionIndex))) :
@@ -588,20 +597,22 @@
 }
 
 AttributeSet AttributeSet::get(LLVMContext &C, unsigned Idx, AttrBuilder &B) {
-  SmallVector<AttributeWithIndex, 8> Attrs;
-  for (AttrBuilder::iterator I = B.begin(), E = B.end(); I != E; ++I) {
-    Attribute::AttrKind Kind = *I;
-    Attribute A = Attribute::get(C, Kind);
+  // FIXME: This should be implemented as a loop that creates the
+  // AttributeWithIndexes that then are used to create the AttributeSet.
+  if (!B.hasAttributes())
+    return AttributeSet();
 
-    if (Kind == Attribute::Alignment)
-      A.setAlignment(B.getAlignment());
-    else if (Kind == Attribute::StackAlignment)
-      A.setStackAlignment(B.getStackAlignment());
+  uint64_t Mask = 0;
 
-    Attrs.push_back(AttributeWithIndex::get(Idx, A));
-  }
+  for (AttrBuilder::iterator I = B.begin(), E = B.end(); I != E; ++I)
+    Mask |= AttributeImpl::getAttrMask(*I);
 
-  return get(C, Attrs);
+  Attribute A = Attribute::decodeLLVMAttributesForBitcode(C, Mask);
+  if (B.getAlignment())
+    A.setAlignment(B.getAlignment());
+  if (B.getStackAlignment())
+    A.setStackAlignment(B.getStackAlignment());
+  return get(C, AttributeWithIndex::get(Idx, A));
 }
 
 //===----------------------------------------------------------------------===//