Revert "[IR] Make AttributeSetNode public, avoid temporary AttributeList copies"

This reverts r299875. A Linux bot came back with a test failure:
http://bb.pgr.jp/builders/test-clang-i686-linux-RA/builds/741/steps/test_clang/logs/Clang%20%3A%3A%20CodeGen__2006-05-19-SingleEltReturn.c

llvm-svn: 299878
diff --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp
index 78de0d6..d8f6c1c 100644
--- a/llvm/lib/AsmParser/LLParser.cpp
+++ b/llvm/lib/AsmParser/LLParser.cpp
@@ -19,7 +19,6 @@
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/AsmParser/SlotMapping.h"
 #include "llvm/IR/Argument.h"
-#include "llvm/IR/AttributeSetNode.h"
 #include "llvm/IR/AutoUpgrade.h"
 #include "llvm/IR/BasicBlock.h"
 #include "llvm/IR/CallingConv.h"
@@ -132,8 +131,9 @@
 
     if (Function *Fn = dyn_cast<Function>(V)) {
       AttributeList AS = Fn->getAttributes();
-      AttrBuilder FnAttrs(AS.getFnAttributes());
-      AS = AS.removeAttributes(Context, AttributeList::FunctionIndex);
+      AttrBuilder FnAttrs(AS.getFnAttributes(), AttributeList::FunctionIndex);
+      AS = AS.removeAttributes(Context, AttributeList::FunctionIndex,
+                               AS.getFnAttributes());
 
       FnAttrs.merge(B);
 
@@ -150,8 +150,9 @@
       Fn->setAttributes(AS);
     } else if (CallInst *CI = dyn_cast<CallInst>(V)) {
       AttributeList AS = CI->getAttributes();
-      AttrBuilder FnAttrs(AS.getFnAttributes());
-      AS = AS.removeAttributes(Context, AttributeList::FunctionIndex);
+      AttrBuilder FnAttrs(AS.getFnAttributes(), AttributeList::FunctionIndex);
+      AS = AS.removeAttributes(Context, AttributeList::FunctionIndex,
+                               AS.getFnAttributes());
       FnAttrs.merge(B);
       AS = AS.addAttributes(
           Context, AttributeList::FunctionIndex,
@@ -159,8 +160,9 @@
       CI->setAttributes(AS);
     } else if (InvokeInst *II = dyn_cast<InvokeInst>(V)) {
       AttributeList AS = II->getAttributes();
-      AttrBuilder FnAttrs(AS.getFnAttributes());
-      AS = AS.removeAttributes(Context, AttributeList::FunctionIndex);
+      AttrBuilder FnAttrs(AS.getFnAttributes(), AttributeList::FunctionIndex);
+      AS = AS.removeAttributes(Context, AttributeList::FunctionIndex,
+                               AS.getFnAttributes());
       FnAttrs.merge(B);
       AS = AS.addAttributes(
           Context, AttributeList::FunctionIndex,
@@ -2093,6 +2095,7 @@
   if (ParseToken(lltok::lparen, "expected '(' in call"))
     return true;
 
+  unsigned AttrIndex = 1;
   while (Lex.getKind() != lltok::rparen) {
     // If this isn't the first argument, we need a comma.
     if (!ArgList.empty() &&
@@ -2127,7 +2130,7 @@
         return true;
     }
     ArgList.push_back(ParamInfo(
-        ArgLoc, V, AttributeSetNode::get(V->getContext(), ArgAttrs)));
+        ArgLoc, V, AttributeList::get(V->getContext(), AttrIndex++, ArgAttrs)));
   }
 
   if (IsMustTailCall && InVarArgsFunc)
@@ -2232,8 +2235,9 @@
     if (!FunctionType::isValidArgumentType(ArgTy))
       return Error(TypeLoc, "invalid type for function argument");
 
-    ArgList.emplace_back(TypeLoc, ArgTy,
-                         AttributeSetNode::get(ArgTy->getContext(), Attrs),
+    unsigned AttrIndex = 1;
+    ArgList.emplace_back(TypeLoc, ArgTy, AttributeList::get(ArgTy->getContext(),
+                                                            AttrIndex++, Attrs),
                          std::move(Name));
 
     while (EatIfPresent(lltok::comma)) {
@@ -2260,9 +2264,10 @@
       if (!ArgTy->isFirstClassType())
         return Error(TypeLoc, "invalid type for function argument");
 
-      ArgList.emplace_back(TypeLoc, ArgTy,
-                           AttributeSetNode::get(ArgTy->getContext(), Attrs),
-                           std::move(Name));
+      ArgList.emplace_back(
+          TypeLoc, ArgTy,
+          AttributeList::get(ArgTy->getContext(), AttrIndex++, Attrs),
+          std::move(Name));
     }
   }
 
@@ -2286,7 +2291,7 @@
   for (unsigned i = 0, e = ArgList.size(); i != e; ++i) {
     if (!ArgList[i].Name.empty())
       return Error(ArgList[i].Loc, "argument name invalid in function type");
-    if (ArgList[i].Attrs)
+    if (ArgList[i].Attrs.hasAttributes(i + 1))
       return Error(ArgList[i].Loc,
                    "argument attributes invalid in function type");
   }
@@ -4735,16 +4740,23 @@
   // Okay, if we got here, the function is syntactically valid.  Convert types
   // and do semantic checks.
   std::vector<Type*> ParamTypeList;
-  SmallVector<AttributeSetNode *, 8> Attrs;
+  SmallVector<AttributeList, 8> Attrs;
 
-  Attrs.push_back(AttributeSetNode::get(Context, RetAttrs));
+  if (RetAttrs.hasAttributes())
+    Attrs.push_back(AttributeList::get(RetType->getContext(),
+                                       AttributeList::ReturnIndex, RetAttrs));
 
   for (unsigned i = 0, e = ArgList.size(); i != e; ++i) {
     ParamTypeList.push_back(ArgList[i].Ty);
-    Attrs.push_back(ArgList[i].Attrs);
+    if (ArgList[i].Attrs.hasAttributes(i + 1)) {
+      AttrBuilder B(ArgList[i].Attrs, i + 1);
+      Attrs.push_back(AttributeList::get(RetType->getContext(), i + 1, B));
+    }
   }
 
-  Attrs.push_back(AttributeSetNode::get(Context, FuncAttrs));
+  if (FuncAttrs.hasAttributes())
+    Attrs.push_back(AttributeList::get(
+        RetType->getContext(), AttributeList::FunctionIndex, FuncAttrs));
 
   AttributeList PAL = AttributeList::get(Context, Attrs);
 
@@ -5356,8 +5368,10 @@
     return true;
 
   // Set up the Attribute for the function.
-  SmallVector<AttributeSetNode *, 8> Attrs;
-  Attrs.push_back(AttributeSetNode::get(Context, RetAttrs));
+  SmallVector<AttributeList, 8> Attrs;
+  if (RetAttrs.hasAttributes())
+    Attrs.push_back(AttributeList::get(RetType->getContext(),
+                                       AttributeList::ReturnIndex, RetAttrs));
 
   SmallVector<Value*, 8> Args;
 
@@ -5377,16 +5391,22 @@
       return Error(ArgList[i].Loc, "argument is not of expected type '" +
                    getTypeString(ExpectedTy) + "'");
     Args.push_back(ArgList[i].V);
-    Attrs.push_back(ArgList[i].Attrs);
+    if (ArgList[i].Attrs.hasAttributes(i + 1)) {
+      AttrBuilder B(ArgList[i].Attrs, i + 1);
+      Attrs.push_back(AttributeList::get(RetType->getContext(), i + 1, B));
+    }
   }
 
   if (I != E)
     return Error(CallLoc, "not enough parameters specified for call");
 
-  if (FnAttrs.hasAlignmentAttr())
-    return Error(CallLoc, "invoke instructions may not have an alignment");
+  if (FnAttrs.hasAttributes()) {
+    if (FnAttrs.hasAlignmentAttr())
+      return Error(CallLoc, "invoke instructions may not have an alignment");
 
-  Attrs.push_back(AttributeSetNode::get(Context, FnAttrs));
+    Attrs.push_back(AttributeList::get(RetType->getContext(),
+                                       AttributeList::FunctionIndex, FnAttrs));
+  }
 
   // Finish off the Attribute and check them
   AttributeList PAL = AttributeList::get(Context, Attrs);
@@ -5950,8 +5970,10 @@
     return true;
 
   // Set up the Attribute for the function.
-  SmallVector<AttributeSetNode *, 8> Attrs;
-  Attrs.push_back(AttributeSetNode::get(Context, RetAttrs));
+  SmallVector<AttributeList, 8> Attrs;
+  if (RetAttrs.hasAttributes())
+    Attrs.push_back(AttributeList::get(RetType->getContext(),
+                                       AttributeList::ReturnIndex, RetAttrs));
 
   SmallVector<Value*, 8> Args;
 
@@ -5971,16 +5993,22 @@
       return Error(ArgList[i].Loc, "argument is not of expected type '" +
                    getTypeString(ExpectedTy) + "'");
     Args.push_back(ArgList[i].V);
-    Attrs.push_back(ArgList[i].Attrs);
+    if (ArgList[i].Attrs.hasAttributes(i + 1)) {
+      AttrBuilder B(ArgList[i].Attrs, i + 1);
+      Attrs.push_back(AttributeList::get(RetType->getContext(), i + 1, B));
+    }
   }
 
   if (I != E)
     return Error(CallLoc, "not enough parameters specified for call");
 
-  if (FnAttrs.hasAlignmentAttr())
-    return Error(CallLoc, "call instructions may not have an alignment");
+  if (FnAttrs.hasAttributes()) {
+    if (FnAttrs.hasAlignmentAttr())
+      return Error(CallLoc, "call instructions may not have an alignment");
 
-  Attrs.push_back(AttributeSetNode::get(Context, FnAttrs));
+    Attrs.push_back(AttributeList::get(RetType->getContext(),
+                                       AttributeList::FunctionIndex, FnAttrs));
+  }
 
   // Finish off the Attribute and check them
   AttributeList PAL = AttributeList::get(Context, Attrs);