[llvm-commits] [llvm] r173641 - Remove a use of AttributeWithIndex.

Bill Wendling isanbard at gmail.com
Sun Jan 27 16:21:34 PST 2013


Author: void
Date: Sun Jan 27 18:21:34 2013
New Revision: 173641

URL: http://llvm.org/viewvc/llvm-project?rev=173641&view=rev
Log:
Remove a use of AttributeWithIndex.

We want to remove AttributeWithIndex because it provides a non-encapsulated view
of the AttributeSetImpl object. Instead, use accessor methods and iterators.

Eventually, this code can be simplified because the Attribute object will hold
only one attribute instead of multiple attributes.

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

Modified: llvm/trunk/lib/IR/AttributeImpl.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/AttributeImpl.h?rev=173641&r1=173640&r2=173641&view=diff
==============================================================================
--- llvm/trunk/lib/IR/AttributeImpl.h (original)
+++ llvm/trunk/lib/IR/AttributeImpl.h Sun Jan 27 18:21:34 2013
@@ -117,7 +117,8 @@ class AttributeSetImpl : public FoldingS
   LLVMContext &Context;
   SmallVector<AttributeWithIndex, 4> AttrList;
 
-  SmallVector<std::pair<uint64_t, AttributeSetNode*>, 4> AttrNodes;
+  typedef std::pair<uint64_t, AttributeSetNode*> IndexAttrPair;
+  SmallVector<IndexAttrPair, 4> AttrNodes;
 
   // AttributesSet is uniqued, these should not be publicly available.
   void operator=(const AttributeSetImpl &) LLVM_DELETED_FUNCTION;
@@ -137,7 +138,9 @@ public:
   /// is the index of the return, parameter, or function object that the
   /// attributes are applied to, not the index into the AttrNodes list where the
   /// attributes reside.
-  uint64_t getSlotIndex(unsigned Slot) const { return AttrNodes[Slot].first; }
+  uint64_t getSlotIndex(unsigned Slot) const {
+    return AttrNodes[Slot].first;
+  }
 
   /// \brief Retrieve the attributes for the given "slot" in the AttrNode list.
   /// \p Slot is an index into the AttrNodes list, not the index of the return /
@@ -147,6 +150,19 @@ public:
     return AttributeSet::get(Context, AttrList[Slot]);
   }
 
+  typedef AttributeSetNode::iterator       iterator;
+  typedef AttributeSetNode::const_iterator const_iterator;
+
+  iterator begin(unsigned Idx)
+    { return AttrNodes[Idx].second->begin(); }
+  iterator end(unsigned Idx)
+    { return AttrNodes[Idx].second->end(); }
+
+  const_iterator begin(unsigned Idx) const
+    { return AttrNodes[Idx].second->begin(); }
+  const_iterator end(unsigned Idx) const
+    { return AttrNodes[Idx].second->end(); }
+
   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=173641&r1=173640&r2=173641&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Attributes.cpp (original)
+++ llvm/trunk/lib/IR/Attributes.cpp Sun Jan 27 18:21:34 2013
@@ -197,17 +197,21 @@ AttrBuilder::AttrBuilder(AttributeSet AS
   AttributeSetImpl *pImpl = AS.pImpl;
   if (!pImpl) return;
 
-  ArrayRef<AttributeWithIndex> AttrList = pImpl->getAttributes();
-  const AttributeWithIndex *AWI = 0;
-  for (unsigned I = 0, E = AttrList.size(); I != E; ++I)
-    if (AttrList[I].Index == Idx) {
-      AWI = &AttrList[I];
-      break;
-    }
+  AttrBuilder B;
+
+  for (unsigned I = 0, E = pImpl->getNumAttributes(); I != E; ++I) {
+    if (pImpl->getSlotIndex(I) != Idx) continue;
+
+    for (AttributeSetNode::const_iterator II = pImpl->begin(I),
+           IE = pImpl->end(I); II != IE; ++II)
+      B.addAttributes(*II);
+
+    break;
+  }
 
-  if (!AWI) return;
+  if (!B.hasAttributes()) return;
 
-  uint64_t Mask = AWI->Attrs.Raw();
+  uint64_t Mask = B.Raw();
 
   for (Attribute::AttrKind I = Attribute::None; I != Attribute::EndAttrKinds;
        I = Attribute::AttrKind(I + 1)) {
@@ -861,8 +865,8 @@ AttributeSet AttributeSet::removeAttr(LL
 }
 
 void AttributeSet::dump() const {
-  dbgs() << "PAL[ ";
-  for (unsigned i = 0; i < getNumSlots(); ++i) {
+  dbgs() << "PAL[\n";
+  for (unsigned i = 0, e = getNumSlots(); i < e; ++i) {
     uint64_t Index = getSlotIndex(i);
     dbgs() << "  { ";
     if (Index == ~0U)





More information about the llvm-commits mailing list