[llvm-commits] [llvm] r173094 - in /llvm/trunk: include/llvm/IR/Attributes.h lib/IR/AttributeImpl.h lib/IR/Attributes.cpp lib/Transforms/IPO/ArgumentPromotion.cpp lib/Transforms/IPO/DeadArgumentElimination.cpp lib/Transforms/InstCombine/InstCombineCalls.cpp

Bill Wendling isanbard at gmail.com
Mon Jan 21 13:57:28 PST 2013


Author: void
Date: Mon Jan 21 15:57:28 2013
New Revision: 173094

URL: http://llvm.org/viewvc/llvm-project?rev=173094&view=rev
Log:
Make AttributeSet::getFnAttributes() return an AttributeSet instead of an Attribute.

This is more code to isolate the use of the Attribute class to that of just
holding one attribute instead of a collection of attributes.

Modified:
    llvm/trunk/include/llvm/IR/Attributes.h
    llvm/trunk/lib/IR/AttributeImpl.h
    llvm/trunk/lib/IR/Attributes.cpp
    llvm/trunk/lib/Transforms/IPO/ArgumentPromotion.cpp
    llvm/trunk/lib/Transforms/IPO/DeadArgumentElimination.cpp
    llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp

Modified: llvm/trunk/include/llvm/IR/Attributes.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/Attributes.h?rev=173094&r1=173093&r2=173094&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/Attributes.h (original)
+++ llvm/trunk/include/llvm/IR/Attributes.h Mon Jan 21 15:57:28 2013
@@ -184,42 +184,12 @@
 };
 
 //===----------------------------------------------------------------------===//
-/// \class
-/// \brief This is just a pair of values to associate a set of attributes with
-/// an index.
-struct AttributeWithIndex {
-  Attribute Attrs;  ///< The attributes that are set, or'd together.
-  Constant *Val;    ///< Value attached to attribute, e.g. alignment.
-  unsigned Index;   ///< Index of the parameter for which the attributes apply.
-                    ///< Index 0 is used for return value attributes.
-                    ///< Index ~0U is used for function attributes.
-
-  static AttributeWithIndex get(LLVMContext &C, unsigned Idx,
-                                ArrayRef<Attribute::AttrKind> Attrs) {
-    return get(Idx, Attribute::get(C, Attrs));
-  }
-  static AttributeWithIndex get(unsigned Idx, Attribute Attrs) {
-    AttributeWithIndex P;
-    P.Index = Idx;
-    P.Attrs = Attrs;
-    P.Val = 0;
-    return P;
-  }
-  static AttributeWithIndex get(unsigned Idx, Attribute Attrs, Constant *Val) {
-    AttributeWithIndex P;
-    P.Index = Idx;
-    P.Attrs = Attrs;
-    P.Val = Val;
-    return P;
-  }
-};
-
-//===----------------------------------------------------------------------===//
 // AttributeSet Smart Pointer
 //===----------------------------------------------------------------------===//
 
 class AttrBuilder;
 class AttributeSetImpl;
+struct AttributeWithIndex;
 
 //===----------------------------------------------------------------------===//
 /// \class
@@ -289,9 +259,7 @@
   }
 
   /// \brief The function attributes are returned.
-  Attribute getFnAttributes() const {
-    return getAttributes(FunctionIndex);
-  }
+  AttributeSet getFnAttributes() const;
 
   /// \brief Return the alignment for the specified function parameter.
   unsigned getParamAlignment(unsigned Idx) const;
@@ -354,6 +322,39 @@
 
 //===----------------------------------------------------------------------===//
 /// \class
+/// \brief This is just a pair of values to associate a set of attributes with
+/// an index.
+struct AttributeWithIndex {
+  Attribute Attrs;  ///< The attributes that are set, or'd together.
+  Constant *Val;    ///< Value attached to attribute, e.g. alignment.
+  unsigned Index;   ///< Index of the parameter for which the attributes apply.
+                    ///< Index 0 is used for return value attributes.
+                    ///< Index ~0U is used for function attributes.
+
+  // FIXME: These methods all need to be revised. The first one is temporary.
+  static AttributeWithIndex get(LLVMContext &C, unsigned Idx, AttributeSet AS);
+  static AttributeWithIndex get(LLVMContext &C, unsigned Idx,
+                                ArrayRef<Attribute::AttrKind> Attrs) {
+    return get(Idx, Attribute::get(C, Attrs));
+  }
+  static AttributeWithIndex get(unsigned Idx, Attribute Attrs) {
+    AttributeWithIndex P;
+    P.Index = Idx;
+    P.Attrs = Attrs;
+    P.Val = 0;
+    return P;
+  }
+  static AttributeWithIndex get(unsigned Idx, Attribute Attrs, Constant *Val) {
+    AttributeWithIndex P;
+    P.Index = Idx;
+    P.Attrs = Attrs;
+    P.Val = Val;
+    return P;
+  }
+};
+
+//===----------------------------------------------------------------------===//
+/// \class
 /// \brief This class is used in conjunction with the Attribute::get method to
 /// create an Attribute object. The object itself is uniquified. The Builder's
 /// value, however, is not. So this can be used as a quick way to test for

Modified: llvm/trunk/lib/IR/AttributeImpl.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/AttributeImpl.h?rev=173094&r1=173093&r2=173094&view=diff
==============================================================================
--- llvm/trunk/lib/IR/AttributeImpl.h (original)
+++ llvm/trunk/lib/IR/AttributeImpl.h Mon Jan 21 15:57:28 2013
@@ -39,6 +39,8 @@
                 ArrayRef<Constant*> values);
   AttributeImpl(LLVMContext &C, StringRef data);
 
+  LLVMContext &getContext() { return Context; }
+
   ArrayRef<Constant*> getValues() const { return Vals; }
 
   bool hasAttribute(Attribute::AttrKind A) const;

Modified: llvm/trunk/lib/IR/Attributes.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Attributes.cpp?rev=173094&r1=173093&r2=173094&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Attributes.cpp (original)
+++ llvm/trunk/lib/IR/Attributes.cpp Mon Jan 21 15:57:28 2013
@@ -530,9 +530,29 @@
 }
 
 //===----------------------------------------------------------------------===//
+// AttributeWithIndex Definition
+//===----------------------------------------------------------------------===//
+
+AttributeWithIndex AttributeWithIndex::get(LLVMContext &C, unsigned Idx,
+                                           AttributeSet AS) {
+  // FIXME: This is temporary, but necessary for the conversion.
+  AttrBuilder B(AS, Idx);
+  return get(Idx, Attribute::get(C, B));
+}
+
+//===----------------------------------------------------------------------===//
 // AttributeSetImpl Definition
 //===----------------------------------------------------------------------===//
 
+AttributeSet AttributeSet::getFnAttributes() const {
+  // FIXME: Remove.
+  return AttrList ?
+    AttributeSet::get(AttrList->getContext(),
+                      AttributeWithIndex::get(FunctionIndex,
+                                              getAttributes(FunctionIndex))) :
+    AttributeSet();
+}
+
 AttributeSet AttributeSet::get(LLVMContext &C,
                                ArrayRef<AttributeWithIndex> Attrs) {
   // If there are no attributes then return a null AttributesList pointer.

Modified: llvm/trunk/lib/Transforms/IPO/ArgumentPromotion.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/ArgumentPromotion.cpp?rev=173094&r1=173093&r2=173094&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/ArgumentPromotion.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/ArgumentPromotion.cpp Mon Jan 21 15:57:28 2013
@@ -591,7 +591,8 @@
 
   // Add any function attributes.
   if (PAL.hasAttributes(AttributeSet::FunctionIndex))
-    AttributesVec.push_back(AttributeWithIndex::get(AttributeSet::FunctionIndex,
+    AttributesVec.push_back(AttributeWithIndex::get(FTy->getContext(),
+                                                    AttributeSet::FunctionIndex,
                                                     PAL.getFnAttributes()));
 
   Type *RetTy = FTy->getReturnType();
@@ -719,7 +720,8 @@
 
     // Add any function attributes.
     if (CallPAL.hasAttributes(AttributeSet::FunctionIndex))
-      AttributesVec.push_back(AttributeWithIndex::get(AttributeSet::FunctionIndex,
+      AttributesVec.push_back(AttributeWithIndex::get(Call->getContext(),
+                                                      AttributeSet::FunctionIndex,
                                                       CallPAL.getFnAttributes()));
 
     Instruction *New;

Modified: llvm/trunk/lib/Transforms/IPO/DeadArgumentElimination.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/DeadArgumentElimination.cpp?rev=173094&r1=173093&r2=173094&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/DeadArgumentElimination.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/DeadArgumentElimination.cpp Mon Jan 21 15:57:28 2013
@@ -276,10 +276,10 @@
       SmallVector<AttributeWithIndex, 8> AttributesVec;
       for (unsigned i = 0; PAL.getSlot(i).Index <= NumArgs; ++i)
         AttributesVec.push_back(PAL.getSlot(i));
-      Attribute FnAttrs = PAL.getFnAttributes();
       if (PAL.hasAttributes(AttributeSet::FunctionIndex))
-        AttributesVec.push_back(AttributeWithIndex::get(AttributeSet::FunctionIndex,
-                                                        FnAttrs));
+        AttributesVec.push_back(AttributeWithIndex::get(Fn.getContext(),
+                                                        AttributeSet::FunctionIndex,
+                                                        PAL.getFnAttributes()));
       PAL = AttributeSet::get(Fn.getContext(), AttributesVec);
     }
 
@@ -702,10 +702,8 @@
 
   // The existing function return attributes.
   Attribute RAttrs = PAL.getRetAttributes();
-  Attribute FnAttrs = PAL.getFnAttributes();
 
   // Find out the new return value.
-
   Type *RetTy = FTy->getReturnType();
   Type *NRetTy = NULL;
   unsigned RetCount = NumRetVals(F);
@@ -801,9 +799,10 @@
     }
   }
 
-  if (FnAttrs.hasAttributes())
-    AttributesVec.push_back(AttributeWithIndex::get(AttributeSet::FunctionIndex,
-                                                    FnAttrs));
+  if (PAL.hasAttributes(AttributeSet::FunctionIndex))
+    AttributesVec.push_back(AttributeWithIndex::get(F->getContext(),
+                                                    AttributeSet::FunctionIndex,
+                                                    PAL.getFnAttributes()));
 
   // Reconstruct the AttributesList based on the vector we constructed.
   AttributeSet NewPAL = AttributeSet::get(F->getContext(), AttributesVec);
@@ -837,7 +836,7 @@
 
     // The call return attributes.
     Attribute RAttrs = CallPAL.getRetAttributes();
-    Attribute FnAttrs = CallPAL.getFnAttributes();
+
     // Adjust in case the function was changed to return void.
     RAttrs =
       Attribute::get(NF->getContext(), AttrBuilder(RAttrs).
@@ -869,9 +868,10 @@
         AttributesVec.push_back(AttributeWithIndex::get(Args.size(), Attrs));
     }
 
-    if (FnAttrs.hasAttributes())
-      AttributesVec.push_back(AttributeWithIndex::get(AttributeSet::FunctionIndex,
-                                                      FnAttrs));
+    if (CallPAL.hasAttributes(AttributeSet::FunctionIndex))
+      AttributesVec.push_back(AttributeWithIndex::get(Call->getContext(),
+                                                      AttributeSet::FunctionIndex,
+                                                      CallPAL.getFnAttributes()));
 
     // Reconstruct the AttributesList based on the vector we constructed.
     AttributeSet NewCallPAL = AttributeSet::get(F->getContext(), AttributesVec);

Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp?rev=173094&r1=173093&r2=173094&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp Mon Jan 21 15:57:28 2013
@@ -1175,16 +1175,17 @@
     }
   }
 
-  Attribute FnAttrs = CallerPAL.getFnAttributes();
+  AttributeSet FnAttrs = CallerPAL.getFnAttributes();
   if (CallerPAL.hasAttributes(AttributeSet::FunctionIndex))
-    attrVec.push_back(AttributeWithIndex::get(AttributeSet::FunctionIndex,
+    attrVec.push_back(AttributeWithIndex::get(Callee->getContext(),
+                                              AttributeSet::FunctionIndex,
                                               FnAttrs));
 
   if (NewRetTy->isVoidTy())
     Caller->setName("");   // Void type should not have a name.
 
   const AttributeSet &NewCallerPAL = AttributeSet::get(Callee->getContext(),
-                                                     attrVec);
+                                                       attrVec);
 
   Instruction *NC;
   if (InvokeInst *II = dyn_cast<InvokeInst>(Caller)) {
@@ -1319,10 +1320,10 @@
       }
 
       // Add any function attributes.
-      Attr = Attrs.getFnAttributes();
       if (Attrs.hasAttributes(AttributeSet::FunctionIndex))
-        NewAttrs.push_back(AttributeWithIndex::get(AttributeSet::FunctionIndex,
-                                                   Attr));
+        NewAttrs.push_back(AttributeWithIndex::get(FTy->getContext(),
+                                                   AttributeSet::FunctionIndex,
+                                                   Attrs.getFnAttributes()));
 
       // The trampoline may have been bitcast to a bogus type (FTy).
       // Handle this by synthesizing a new function type, equal to FTy





More information about the llvm-commits mailing list