Index: llvm/trunk/lib/IR/AttributeImpl.h =================================================================== --- llvm/trunk/lib/IR/AttributeImpl.h +++ llvm/trunk/lib/IR/AttributeImpl.h @@ -223,12 +223,12 @@ private: LLVMContext &Context; - unsigned NumAttrs; ///< Number of entries in this set. + unsigned NumSlots; ///< Number of entries in this set. /// Bitset with a bit for each available attribute Attribute::AttrKind. uint64_t AvailableFunctionAttrs; // Helper fn for TrailingObjects class. - size_t numTrailingObjects(OverloadToken) { return NumAttrs; } + size_t numTrailingObjects(OverloadToken) { return NumSlots; } /// \brief Return a pointer to the IndexAttrPair for the specified slot. const IndexAttrPair *getNode(unsigned Slot) const { @@ -240,29 +240,29 @@ AttributeSetImpl(const AttributeSetImpl &) = delete; public: AttributeSetImpl(LLVMContext &C, - ArrayRef > Attrs) - : Context(C), NumAttrs(Attrs.size()), AvailableFunctionAttrs(0) { + ArrayRef > Slots) + : Context(C), NumSlots(Slots.size()), AvailableFunctionAttrs(0) { static_assert(Attribute::EndAttrKinds <= sizeof(AvailableFunctionAttrs) * CHAR_BIT, "Too many attributes"); #ifndef NDEBUG - if (Attrs.size() >= 2) { - for (const std::pair *i = Attrs.begin() + 1, - *e = Attrs.end(); + if (Slots.size() >= 2) { + for (const std::pair *i = Slots.begin() + 1, + *e = Slots.end(); i != e; ++i) { assert((i-1)->first <= i->first && "Attribute set not ordered!"); } } #endif // There's memory after the node where we can store the entries in. - std::copy(Attrs.begin(), Attrs.end(), getTrailingObjects()); + std::copy(Slots.begin(), Slots.end(), getTrailingObjects()); // Initialize AvailableFunctionAttrs summary bitset. - if (NumAttrs > 0) { + if (NumSlots > 0) { static_assert(AttributeSet::FunctionIndex == ~0u, "FunctionIndex should be biggest possible index"); - const std::pair &Last = Attrs.back(); + const std::pair &Last = Slots.back(); if (Last.first == AttributeSet::FunctionIndex) { const AttributeSetNode *Node = Last.second; for (AttributeSetNode::iterator I = Node->begin(), E = Node->end(); @@ -279,8 +279,10 @@ /// \brief Get the context that created this AttributeSetImpl. LLVMContext &getContext() { return Context; } - /// \brief Return the number of attributes this AttributeSet contains. - unsigned getNumAttributes() const { return NumAttrs; } + /// \brief Return the number of slots used in this attribute list. This is + /// the number of arguments that have an attribute set on them (including the + /// function itself). + unsigned getNumSlots() const { return NumSlots; } /// \brief Get the index of the given "slot" in the AttrNodes list. This index /// is the index of the return, parameter, or function object that the @@ -314,7 +316,7 @@ iterator end(unsigned Slot) const { return getSlotNode(Slot)->end(); } void Profile(FoldingSetNodeID &ID) const { - Profile(ID, makeArrayRef(getNode(0), getNumAttributes())); + Profile(ID, makeArrayRef(getNode(0), getNumSlots())); } static void Profile(FoldingSetNodeID &ID, ArrayRef > Nodes) { Index: llvm/trunk/lib/IR/Attributes.cpp =================================================================== --- llvm/trunk/lib/IR/Attributes.cpp +++ llvm/trunk/lib/IR/Attributes.cpp @@ -643,7 +643,7 @@ //===----------------------------------------------------------------------===// uint64_t AttributeSetImpl::Raw(unsigned Index) const { - for (unsigned I = 0, E = getNumAttributes(); I != E; ++I) { + for (unsigned I = 0, E = getNumSlots(); I != E; ++I) { if (getSlotIndex(I) != Index) continue; const AttributeSetNode *ASN = getSlotNode(I); uint64_t Mask = 0; @@ -814,7 +814,7 @@ SmallVector, 8> AttrNodeVec; AttributeSetImpl *A0 = Attrs[0].pImpl; if (A0) - AttrNodeVec.append(A0->getNode(0), A0->getNode(A0->getNumAttributes())); + AttrNodeVec.append(A0->getNode(0), A0->getNode(A0->getNumSlots())); // Copy all attributes from Attrs into AttrNodeVec while keeping AttrNodeVec // ordered by index. Because we know that each list in Attrs is ordered by // index we only need to merge each successive list in rather than doing a @@ -825,7 +825,7 @@ SmallVector, 8>::iterator ANVI = AttrNodeVec.begin(), ANVE; for (const IndexAttrPair *AI = AS->getNode(0), - *AE = AS->getNode(AS->getNumAttributes()); + *AE = AS->getNode(AS->getNumSlots()); AI != AE; ++AI) { ANVE = AttrNodeVec.end(); while (ANVI != ANVE && ANVI->first <= AI->first) @@ -853,7 +853,7 @@ AttributeSet AttributeSet::addAttribute(LLVMContext &C, ArrayRef Indices, Attribute A) const { - unsigned I = 0, E = pImpl ? pImpl->getNumAttributes() : 0; + unsigned I = 0, E = pImpl ? pImpl->getNumSlots() : 0; auto IdxI = Indices.begin(), IdxE = Indices.end(); SmallVector AttrSet; @@ -896,7 +896,7 @@ // Add the attribute slots before the one we're trying to add. SmallVector AttrSet; - uint64_t NumAttrs = pImpl->getNumAttributes(); + uint64_t NumAttrs = pImpl->getNumSlots(); AttributeSet AS; uint64_t LastIndex = 0; for (unsigned I = 0, E = NumAttrs; I != E; ++I) { @@ -912,7 +912,7 @@ // AttributeSet there. AttrBuilder B(AS, Index); - for (unsigned I = 0, E = Attrs.pImpl->getNumAttributes(); I != E; ++I) + for (unsigned I = 0, E = Attrs.pImpl->getNumSlots(); I != E; ++I) if (Attrs.getSlotIndex(I) == Index) { for (AttributeSetImpl::iterator II = Attrs.pImpl->begin(I), IE = Attrs.pImpl->end(I); II != IE; ++II) @@ -947,7 +947,7 @@ // Add the attribute slots before the one we're trying to add. SmallVector AttrSet; - uint64_t NumAttrs = pImpl->getNumAttributes(); + uint64_t NumAttrs = pImpl->getNumSlots(); AttributeSet AS; uint64_t LastIndex = 0; for (unsigned I = 0, E = NumAttrs; I != E; ++I) { @@ -963,7 +963,7 @@ // AttributeSet there. AttrBuilder B(AS, Index); - for (unsigned I = 0, E = Attrs.pImpl->getNumAttributes(); I != E; ++I) + for (unsigned I = 0, E = Attrs.pImpl->getNumSlots(); I != E; ++I) if (Attrs.getSlotIndex(I) == Index) { B.removeAttributes(Attrs.pImpl->getSlotAttributes(I), Index); break; @@ -988,7 +988,7 @@ // Add the attribute slots before the one we're trying to add. SmallVector AttrSet; - uint64_t NumAttrs = pImpl->getNumAttributes(); + uint64_t NumAttrs = pImpl->getNumSlots(); AttributeSet AS; uint64_t LastIndex = 0; for (unsigned I = 0, E = NumAttrs; I != E; ++I) { @@ -1094,7 +1094,7 @@ bool AttributeSet::hasAttrSomewhere(Attribute::AttrKind Attr) const { if (!pImpl) return false; - for (unsigned I = 0, E = pImpl->getNumAttributes(); I != E; ++I) + for (unsigned I = 0, E = pImpl->getNumSlots(); I != E; ++I) for (AttributeSetImpl::iterator II = pImpl->begin(I), IE = pImpl->end(I); II != IE; ++II) if (II->hasAttribute(Attr)) @@ -1150,7 +1150,7 @@ if (!pImpl) return nullptr; // Loop through to find the attribute node we want. - for (unsigned I = 0, E = pImpl->getNumAttributes(); I != E; ++I) + for (unsigned I = 0, E = pImpl->getNumSlots(); I != E; ++I) if (pImpl->getSlotIndex(I) == Index) return pImpl->getSlotNode(I); @@ -1174,17 +1174,17 @@ //===----------------------------------------------------------------------===// unsigned AttributeSet::getNumSlots() const { - return pImpl ? pImpl->getNumAttributes() : 0; + return pImpl ? pImpl->getNumSlots() : 0; } unsigned AttributeSet::getSlotIndex(unsigned Slot) const { - assert(pImpl && Slot < pImpl->getNumAttributes() && + assert(pImpl && Slot < pImpl->getNumSlots() && "Slot # out of range!"); return pImpl->getSlotIndex(Slot); } AttributeSet AttributeSet::getSlotAttributes(unsigned Slot) const { - assert(pImpl && Slot < pImpl->getNumAttributes() && + assert(pImpl && Slot < pImpl->getNumSlots() && "Slot # out of range!"); return pImpl->getSlotAttributes(Slot); } @@ -1220,7 +1220,7 @@ AttributeSetImpl *pImpl = AS.pImpl; if (!pImpl) return; - for (unsigned I = 0, E = pImpl->getNumAttributes(); I != E; ++I) { + for (unsigned I = 0, E = pImpl->getNumSlots(); I != E; ++I) { if (pImpl->getSlotIndex(I) != Index) continue; for (AttributeSetImpl::iterator II = pImpl->begin(I),