summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorBill Wendling <isanbard@gmail.com>2013-01-25 21:30:53 +0000
committerBill Wendling <isanbard@gmail.com>2013-01-25 21:30:53 +0000
commite1f95db4803a48a30fc2a1d5868281a87a36fb85 (patch)
treeb788d661a144e15c1e5ddef5a09081338138e9b3 /lib
parent1f375e5bc78647f9b29564eafdc907250ccd91ed (diff)
downloadllvm-e1f95db4803a48a30fc2a1d5868281a87a36fb85.tar.gz
llvm-e1f95db4803a48a30fc2a1d5868281a87a36fb85.tar.bz2
llvm-e1f95db4803a48a30fc2a1d5868281a87a36fb85.tar.xz
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
Diffstat (limited to 'lib')
-rw-r--r--lib/IR/AttributeImpl.h4
-rw-r--r--lib/IR/Attributes.cpp6
-rw-r--r--lib/IR/Verifier.cpp24
3 files changed, 22 insertions, 12 deletions
diff --git a/lib/IR/AttributeImpl.h b/lib/IR/AttributeImpl.h
index b35e5e0f0b..ebd90e29e2 100644
--- a/lib/IR/AttributeImpl.h
+++ b/lib/IR/AttributeImpl.h
@@ -122,6 +122,10 @@ public:
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);
diff --git a/lib/IR/Attributes.cpp b/lib/IR/Attributes.cpp
index cbbf4848f6..b09d55db90 100644
--- a/lib/IR/Attributes.cpp
+++ b/lib/IR/Attributes.cpp
@@ -682,6 +682,12 @@ unsigned AttributeSet::getNumSlots() const {
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 {
diff --git a/lib/IR/Verifier.cpp b/lib/IR/Verifier.cpp
index b263bbef3a..9a482f1452 100644
--- a/lib/IR/Verifier.cpp
+++ b/lib/IR/Verifier.cpp
@@ -718,25 +718,25 @@ void Verifier::VerifyFunctionAttrs(FunctionType *FT,
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 @@ static bool VerifyAttributeCount(const AttributeSet &Attrs, unsigned Params) {
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;
}