llvm.org GIT mirror llvm / e1f95db
Add an accessor method to get the slot's index. This will limit the use of AttributeWithIndex. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@173495 91177308-0d34-0410-b5e6-96231b3b80d8 Bill Wendling 7 years ago
4 changed file(s) with 26 addition(s) and 13 deletion(s). Raw diff Collapse all Expand all
338338 /// function itself).
339339 unsigned getNumSlots() const;
340340
341 /// \brief Return the index for the given slot.
342 unsigned getSlotIndex(unsigned Slot) const;
343
341344 /// \brief Return the AttributeWithIndex at the specified slot. This holds a
342345 /// index number plus a set of attributes.
343346 const AttributeWithIndex &getSlot(unsigned Slot) const;
121121 LLVMContext &getContext() { return Context; }
122122 ArrayRef getAttributes() const { return AttrList; }
123123 unsigned getNumAttributes() const { return AttrList.size(); }
124 unsigned getSlotIndex(unsigned Slot) const {
125 // FIXME: This needs to use AttrNodes instead.
126 return AttrList[Slot].Index;
127 }
124128
125129 void Profile(FoldingSetNodeID &ID) const {
126130 Profile(ID, AttrList);
681681 return AttrList ? AttrList->getNumAttributes() : 0;
682682 }
683683
684 unsigned AttributeSet::getSlotIndex(unsigned Slot) const {
685 assert(AttrList && Slot < AttrList->getNumAttributes() &&
686 "Slot # out of range!");
687 return AttrList->getSlotIndex(Slot);
688 }
689
684690 /// getSlot - Return the AttributeWithIndex at the specified slot. This
685691 /// holds a number plus a set of attributes.
686692 const AttributeWithIndex &AttributeSet::getSlot(unsigned Slot) const {
717717 bool SawNest = false;
718718
719719 for (unsigned i = 0, e = Attrs.getNumSlots(); i != e; ++i) {
720 const AttributeWithIndex &Attr = Attrs.getSlot(i);
720 unsigned Index = Attrs.getSlotIndex(i);
721721
722722 Type *Ty;
723 if (Attr.Index == 0)
723 if (Index == 0)
724724 Ty = FT->getReturnType();
725 else if (Attr.Index-1 < FT->getNumParams())
726 Ty = FT->getParamType(Attr.Index-1);
725 else if (Index-1 < FT->getNumParams())
726 Ty = FT->getParamType(Index-1);
727727 else
728728 break; // VarArgs attributes, verified elsewhere.
729729
730 VerifyParameterAttrs(Attrs, Attr.Index, Ty, Attr.Index == 0, V);
731
732 if (Attrs.hasAttribute(Attr.Index, Attribute::Nest)) {
730 VerifyParameterAttrs(Attrs, Index, Ty, Index == 0, V);
731
732 if (Attrs.hasAttribute(i, Attribute::Nest)) {
733733 Assert1(!SawNest, "More than one parameter has attribute nest!", V);
734734 SawNest = true;
735735 }
736736
737 if (Attrs.hasAttribute(Attr.Index, Attribute::StructRet))
738 Assert1(Attr.Index == 1, "Attribute sret is not on first parameter!", V);
737 if (Attrs.hasAttribute(Index, Attribute::StructRet))
738 Assert1(Index == 1, "Attribute sret is not on first parameter!", V);
739739 }
740740
741741 if (!Attrs.hasAttributes(AttributeSet::FunctionIndex))
800800 return true;
801801
802802 unsigned LastSlot = Attrs.getNumSlots() - 1;
803 unsigned LastIndex = Attrs.getSlot(LastSlot).Index;
803 unsigned LastIndex = Attrs.getSlotIndex(LastSlot);
804804 if (LastIndex <= Params
805 || (LastIndex == (unsigned)~0
806 && (LastSlot == 0 || Attrs.getSlot(LastSlot - 1).Index <= Params)))
805 || (LastIndex == AttributeSet::FunctionIndex
806 && (LastSlot == 0 || Attrs.getSlotIndex(LastSlot - 1) <= Params)))
807807 return true;
808
808
809809 return false;
810810 }
811811