Now Attributes are divided in three groups
- return attributes - inreg, zext and sext
- parameter attributes
- function attributes - nounwind, readonly, readnone, noreturn

Return attributes use 0 as the index.
Function attributes use ~0U as the index.

This patch requires corresponding changes in llvm-gcc and clang.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@56704 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Transforms/IPO/StructRetPromotion.cpp b/lib/Transforms/IPO/StructRetPromotion.cpp
index 07b9e50..96ef66c 100644
--- a/lib/Transforms/IPO/StructRetPromotion.cpp
+++ b/lib/Transforms/IPO/StructRetPromotion.cpp
@@ -210,7 +210,7 @@
   const AttrListPtr &PAL = F->getAttributes();
 
   // Add any return attributes.
-  if (Attributes attrs = PAL.getAttributes(0))
+  if (Attributes attrs = PAL.getRetAttributes())
     AttributesVec.push_back(AttributeWithIndex::get(0, attrs));
 
   // Skip first argument.
@@ -221,12 +221,17 @@
   unsigned ParamIndex = 2; 
   while (I != E) {
     Params.push_back(I->getType());
-    if (Attributes Attrs = PAL.getAttributes(ParamIndex))
+    if (Attributes Attrs = PAL.getParamAttributes(ParamIndex))
       AttributesVec.push_back(AttributeWithIndex::get(ParamIndex - 1, Attrs));
     ++I;
     ++ParamIndex;
   }
 
+  // Add any fn attributes.
+  if (Attributes attrs = PAL.getFnAttributes())
+    AttributesVec.push_back(AttributeWithIndex::get(~0, attrs));
+
+
   FunctionType *NFTy = FunctionType::get(STy, Params, FTy->isVarArg());
   Function *NF = Function::Create(NFTy, F->getLinkage());
   NF->takeName(F);
@@ -264,7 +269,7 @@
 
     const AttrListPtr &PAL = F->getAttributes();
     // Add any return attributes.
-    if (Attributes attrs = PAL.getAttributes(0))
+    if (Attributes attrs = PAL.getRetAttributes())
       ArgAttrsVec.push_back(AttributeWithIndex::get(0, attrs));
 
     // Copy arguments, however skip first one.
@@ -276,12 +281,15 @@
     unsigned ParamIndex = 2; 
     while (AI != AE) {
       Args.push_back(*AI); 
-      if (Attributes Attrs = PAL.getAttributes(ParamIndex))
+      if (Attributes Attrs = PAL.getParamAttributes(ParamIndex))
         ArgAttrsVec.push_back(AttributeWithIndex::get(ParamIndex - 1, Attrs));
       ++ParamIndex;
       ++AI;
     }
 
+    // Add any function attributes.
+    if (Attributes attrs = PAL.getFnAttributes())
+      ArgAttrsVec.push_back(AttributeWithIndex::get(~0, attrs));
     
     AttrListPtr NewPAL = AttrListPtr::get(ArgAttrsVec.begin(), ArgAttrsVec.end());