Have AttributeSet::getRetAttributes() return an AttributeSet instead of Attribute.
authorBill Wendling <isanbard@gmail.com>
Mon, 21 Jan 2013 22:44:49 +0000 (22:44 +0000)
committerBill Wendling <isanbard@gmail.com>
Mon, 21 Jan 2013 22:44:49 +0000 (22:44 +0000)
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

include/llvm/IR/Attributes.h
lib/IR/Attributes.cpp
lib/Transforms/IPO/ArgumentPromotion.cpp
lib/Transforms/IPO/DeadArgumentElimination.cpp
lib/Transforms/InstCombine/InstCombineCalls.cpp

index 121eae29704a60bb45c9ef9e87142b9d7a0b884a..ef80b4d46385b99f49eb2823a694240f9398db90 100644 (file)
@@ -254,9 +254,7 @@ public:
   }
 
   /// \brief The attributes for the ret value are returned.
-  Attribute getRetAttributes() const {
-    return getAttributes(ReturnIndex);
-  }
+  AttributeSet getRetAttributes() const;
 
   /// \brief The function attributes are returned.
   AttributeSet getFnAttributes() const;
index d3f284a41d8268e52743769a01178008eeb57616..5c95d4a380acdc2a8e5bdb45c6aeb63c4ce29fba 100644 (file)
@@ -544,9 +544,18 @@ AttributeWithIndex AttributeWithIndex::get(LLVMContext &C, unsigned Idx,
 // 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,
 }
 
 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));
 }
 
 //===----------------------------------------------------------------------===//
index c5b17dba515b21f9bb63fc77f47d0a28fee3e688..39062e676c11c836357deb9f825bcee9610a62a9 100644 (file)
@@ -519,7 +519,8 @@ CallGraphNode *ArgPromotion::DoPromotion(Function *F,
 
   // Add any return attributes.
   if (PAL.hasAttributes(AttributeSet::ReturnIndex))
-    AttributesVec.push_back(AttributeWithIndex::get(AttributeSet::ReturnIndex,
+    AttributesVec.push_back(AttributeWithIndex::get(F->getContext(),
+                                                    AttributeSet::ReturnIndex,
                                                     PAL.getRetAttributes()));
 
   // First, determine the new argument list
@@ -639,7 +640,8 @@ CallGraphNode *ArgPromotion::DoPromotion(Function *F,
 
     // Add any return attributes.
     if (CallPAL.hasAttributes(AttributeSet::ReturnIndex))
-      AttributesVec.push_back(AttributeWithIndex::get(AttributeSet::ReturnIndex,
+      AttributesVec.push_back(AttributeWithIndex::get(F->getContext(),
+                                                      AttributeSet::ReturnIndex,
                                                       CallPAL.getRetAttributes()));
 
     // Loop over the operands, inserting GEP and loads in the caller as
index f6486e12eb2cd4eb61f6c9e91d013c7dafd7dbef..5204248c1fad031a6eeebecebe1c11da11145985 100644 (file)
@@ -700,9 +700,6 @@ bool DAE::RemoveDeadStuffFromFunction(Function *F) {
   SmallVector<AttributeWithIndex, 8> AttributesVec;
   const AttributeSet &PAL = F->getAttributes();
 
-  // The existing function return attributes.
-  Attribute RAttrs = PAL.getRetAttributes();
-
   // Find out the new return value.
   Type *RetTy = FTy->getReturnType();
   Type *NRetTy = NULL;
@@ -757,21 +754,26 @@ bool DAE::RemoveDeadStuffFromFunction(Function *F) {
 
   assert(NRetTy && "No new return type found?");
 
+  // The existing function return attributes.
+  AttributeSet RAttrs = PAL.getRetAttributes();
+
   // Remove any incompatible attributes, but only if we removed all return
   // values. Otherwise, ensure that we don't have any conflicting attributes
   // here. Currently, this should not be possible, but special handling might be
   // required when new return value attributes are added.
   if (NRetTy->isVoidTy())
     RAttrs =
-      Attribute::get(NRetTy->getContext(), AttrBuilder(RAttrs).
-                      removeAttributes(Attribute::typeIncompatible(NRetTy)));
+      AttributeSet::get(NRetTy->getContext(), AttributeSet::ReturnIndex,
+                        AttrBuilder(RAttrs, AttributeSet::ReturnIndex).
+                         removeAttributes(Attribute::typeIncompatible(NRetTy)));
   else
-    assert(!AttrBuilder(RAttrs).
+    assert(!AttrBuilder(RAttrs, AttributeSet::ReturnIndex).
              hasAttributes(Attribute::typeIncompatible(NRetTy)) &&
            "Return attributes no longer compatible?");
 
-  if (RAttrs.hasAttributes())
-    AttributesVec.push_back(AttributeWithIndex::get(AttributeSet::ReturnIndex,
+  if (RAttrs.hasAttributes(AttributeSet::ReturnIndex))
+    AttributesVec.push_back(AttributeWithIndex::get(NRetTy->getContext(),
+                                                    AttributeSet::ReturnIndex,
                                                     RAttrs));
 
   // Remember which arguments are still alive.
@@ -835,14 +837,16 @@ bool DAE::RemoveDeadStuffFromFunction(Function *F) {
     const AttributeSet &CallPAL = CS.getAttributes();
 
     // The call return attributes.
-    Attribute RAttrs = CallPAL.getRetAttributes();
+    AttributeSet RAttrs = CallPAL.getRetAttributes();
 
     // Adjust in case the function was changed to return void.
     RAttrs =
-      Attribute::get(NF->getContext(), AttrBuilder(RAttrs).
+      AttributeSet::get(NF->getContext(), AttributeSet::ReturnIndex,
+                        AttrBuilder(RAttrs, AttributeSet::ReturnIndex).
            removeAttributes(Attribute::typeIncompatible(NF->getReturnType())));
-    if (RAttrs.hasAttributes())
-      AttributesVec.push_back(AttributeWithIndex::get(AttributeSet::ReturnIndex,
+    if (RAttrs.hasAttributes(AttributeSet::ReturnIndex))
+      AttributesVec.push_back(AttributeWithIndex::get(NF->getContext(),
+                                                      AttributeSet::ReturnIndex,
                                                       RAttrs));
 
     // Declare these outside of the loops, so we can reuse them for the second
index f3036d82dd5dd49e92978cab3348211dcfba4c34..6d4f1883b694537480e17a43d8ccb15e3e1c6515 100644 (file)
@@ -1287,10 +1287,10 @@ InstCombiner::transformCallThroughTrampoline(CallSite CS,
       // mean appending it.  Likewise for attributes.
 
       // Add any result attributes.
-      Attribute Attr = Attrs.getRetAttributes();
       if (Attrs.hasAttributes(AttributeSet::ReturnIndex))
-        NewAttrs.push_back(AttributeWithIndex::get(AttributeSet::ReturnIndex,
-                                                   Attr));
+        NewAttrs.push_back(AttributeWithIndex::get(Caller->getContext(),
+                                                   AttributeSet::ReturnIndex,
+                                                   Attrs.getRetAttributes()));
 
       {
         unsigned Idx = 1;
@@ -1310,7 +1310,7 @@ InstCombiner::transformCallThroughTrampoline(CallSite CS,
 
           // Add the original argument and attributes.
           NewArgs.push_back(*I);
-          Attr = Attrs.getParamAttributes(Idx);
+          Attribute Attr = Attrs.getParamAttributes(Idx);
           if (Attr.hasAttributes())
             NewAttrs.push_back
               (AttributeWithIndex::get(Idx + (Idx >= NestIdx), Attr));