[llvm-commits] [llvm] r173495 - in /llvm/trunk: include/llvm/IR/Attributes.h lib/IR/AttributeImpl.h lib/IR/Attributes.cpp lib/IR/Verifier.cpp

Bill Wendling isanbard at gmail.com
Fri Jan 25 13:30:53 PST 2013


Author: void
Date: Fri Jan 25 15:30:53 2013
New Revision: 173495

URL: http://llvm.org/viewvc/llvm-project?rev=173495&view=rev
Log:
Add an accessor method to get the slot's index. This will limit the use of AttributeWithIndex.

Modified:
    llvm/trunk/include/llvm/IR/Attributes.h
    llvm/trunk/lib/IR/AttributeImpl.h
    llvm/trunk/lib/IR/Attributes.cpp
    llvm/trunk/lib/IR/Verifier.cpp

Modified: llvm/trunk/include/llvm/IR/Attributes.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/Attributes.h?rev=173495&r1=173494&r2=173495&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/Attributes.h (original)
+++ llvm/trunk/include/llvm/IR/Attributes.h Fri Jan 25 15:30:53 2013
@@ -339,6 +339,9 @@
   /// function itself).
   unsigned getNumSlots() const;
 
+  /// \brief Return the index for the given slot.
+  unsigned getSlotIndex(unsigned Slot) const;
+
   /// \brief Return the AttributeWithIndex at the specified slot.  This holds a
   /// index number plus a set of attributes.
   const AttributeWithIndex &getSlot(unsigned Slot) const;

Modified: llvm/trunk/lib/IR/AttributeImpl.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/AttributeImpl.h?rev=173495&r1=173494&r2=173495&view=diff
==============================================================================
--- llvm/trunk/lib/IR/AttributeImpl.h (original)
+++ llvm/trunk/lib/IR/AttributeImpl.h Fri Jan 25 15:30:53 2013
@@ -122,6 +122,10 @@
   LLVMContext &getContext() { return Context; }
   ArrayRef<AttributeWithIndex> getAttributes() const { return AttrList; }
   unsigned getNumAttributes() const { return AttrList.size(); }
+  unsigned getSlotIndex(unsigned Slot) const {
+    // FIXME: This needs to use AttrNodes instead.
+    return AttrList[Slot].Index;
+  }
 
   void Profile(FoldingSetNodeID &ID) const {
     Profile(ID, AttrList);

Modified: llvm/trunk/lib/IR/Attributes.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Attributes.cpp?rev=173495&r1=173494&r2=173495&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Attributes.cpp (original)
+++ llvm/trunk/lib/IR/Attributes.cpp Fri Jan 25 15:30:53 2013
@@ -682,6 +682,12 @@
   return AttrList ? AttrList->getNumAttributes() : 0;
 }
 
+unsigned AttributeSet::getSlotIndex(unsigned Slot) const {
+  assert(AttrList && Slot < AttrList->getNumAttributes() &&
+         "Slot # out of range!");
+  return AttrList->getSlotIndex(Slot);
+}
+
 /// getSlot - Return the AttributeWithIndex at the specified slot.  This
 /// holds a number plus a set of attributes.
 const AttributeWithIndex &AttributeSet::getSlot(unsigned Slot) const {

Modified: llvm/trunk/lib/IR/Verifier.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Verifier.cpp?rev=173495&r1=173494&r2=173495&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Verifier.cpp (original)
+++ llvm/trunk/lib/IR/Verifier.cpp Fri Jan 25 15:30:53 2013
@@ -718,25 +718,25 @@
   bool SawNest = false;
 
   for (unsigned i = 0, e = Attrs.getNumSlots(); i != e; ++i) {
-    const AttributeWithIndex &Attr = Attrs.getSlot(i);
+    unsigned Index = Attrs.getSlotIndex(i);
 
     Type *Ty;
-    if (Attr.Index == 0)
+    if (Index == 0)
       Ty = FT->getReturnType();
-    else if (Attr.Index-1 < FT->getNumParams())
-      Ty = FT->getParamType(Attr.Index-1);
+    else if (Index-1 < FT->getNumParams())
+      Ty = FT->getParamType(Index-1);
     else
       break;  // VarArgs attributes, verified elsewhere.
 
-    VerifyParameterAttrs(Attrs, Attr.Index, Ty, Attr.Index == 0, V);
+    VerifyParameterAttrs(Attrs, Index, Ty, Index == 0, V);
 
-    if (Attrs.hasAttribute(Attr.Index, Attribute::Nest)) {
+    if (Attrs.hasAttribute(i, Attribute::Nest)) {
       Assert1(!SawNest, "More than one parameter has attribute nest!", V);
       SawNest = true;
     }
 
-    if (Attrs.hasAttribute(Attr.Index, Attribute::StructRet))
-      Assert1(Attr.Index == 1, "Attribute sret is not on first parameter!", V);
+    if (Attrs.hasAttribute(Index, Attribute::StructRet))
+      Assert1(Index == 1, "Attribute sret is not on first parameter!", V);
   }
 
   if (!Attrs.hasAttributes(AttributeSet::FunctionIndex))
@@ -801,12 +801,12 @@
     return true;
 
   unsigned LastSlot = Attrs.getNumSlots() - 1;
-  unsigned LastIndex = Attrs.getSlot(LastSlot).Index;
+  unsigned LastIndex = Attrs.getSlotIndex(LastSlot);
   if (LastIndex <= Params
-      || (LastIndex == (unsigned)~0
-          && (LastSlot == 0 || Attrs.getSlot(LastSlot - 1).Index <= Params)))  
+      || (LastIndex == AttributeSet::FunctionIndex
+          && (LastSlot == 0 || Attrs.getSlotIndex(LastSlot - 1) <= Params)))
     return true;
-
+ 
   return false;
 }
 





More information about the llvm-commits mailing list