General cleanups.

* Remove dead methods.
* Use the 'operator==' method instead of 'contains', which isn't needed.
* Fix some comments.

No functionality change.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@171523 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Bill Wendling 2013-01-04 20:54:35 +00:00
parent 4d9c5397b4
commit 60507d53e7
3 changed files with 60 additions and 69 deletions

View File

@ -109,9 +109,6 @@ public:
/// \brief Return true if attributes exist /// \brief Return true if attributes exist
bool hasAttributes() const; bool hasAttributes() const;
/// \brief Return true if the attributes are a non-null intersection.
bool hasAttributes(const Attribute &A) const;
/// \brief Returns the alignment field of an attribute as a byte alignment /// \brief Returns the alignment field of an attribute as a byte alignment
/// value. /// value.
unsigned getAlignment() const; unsigned getAlignment() const;
@ -120,6 +117,7 @@ public:
/// alignment value. /// alignment value.
unsigned getStackAlignment() const; unsigned getStackAlignment() const;
/// \brief Equality and non-equality query methods.
bool operator==(AttrKind K) const; bool operator==(AttrKind K) const;
bool operator!=(AttrKind K) const; bool operator!=(AttrKind K) const;
@ -167,50 +165,51 @@ public:
void clear() { Bits = 0; } void clear() { Bits = 0; }
/// addAttribute - Add an attribute to the builder. /// \brief Add an attribute to the builder.
AttrBuilder &addAttribute(Attribute::AttrKind Val); AttrBuilder &addAttribute(Attribute::AttrKind Val);
/// removeAttribute - Remove an attribute from the builder. /// \brief Remove an attribute from the builder.
AttrBuilder &removeAttribute(Attribute::AttrKind Val); AttrBuilder &removeAttribute(Attribute::AttrKind Val);
/// addAttribute - Add the attributes from A to the builder. /// \brief Add the attributes from A to the builder.
AttrBuilder &addAttributes(const Attribute &A); AttrBuilder &addAttributes(const Attribute &A);
/// removeAttribute - Remove the attributes from A from the builder. /// \brief Remove the attributes from A from the builder.
AttrBuilder &removeAttributes(const Attribute &A); AttrBuilder &removeAttributes(const Attribute &A);
/// \brief Return true if the builder has the specified attribute. /// \brief Return true if the builder has the specified attribute.
bool contains(Attribute::AttrKind A) const; bool contains(Attribute::AttrKind A) const;
/// hasAttributes - Return true if the builder has IR-level attributes. /// \brief Return true if the builder has IR-level attributes.
bool hasAttributes() const; bool hasAttributes() const;
/// hasAttributes - Return true if the builder has any attribute that's in the /// \brief Return true if the builder has any attribute that's in the
/// specified attribute. /// specified attribute.
bool hasAttributes(const Attribute &A) const; bool hasAttributes(const Attribute &A) const;
/// hasAlignmentAttr - Return true if the builder has an alignment attribute. /// \brief Return true if the builder has an alignment attribute.
bool hasAlignmentAttr() const; bool hasAlignmentAttr() const;
/// getAlignment - Retrieve the alignment attribute, if it exists. /// \brief Retrieve the alignment attribute, if it exists.
uint64_t getAlignment() const; uint64_t getAlignment() const;
/// getStackAlignment - Retrieve the stack alignment attribute, if it exists. /// \brief Retrieve the stack alignment attribute, if it exists.
uint64_t getStackAlignment() const; uint64_t getStackAlignment() const;
/// addAlignmentAttr - This turns an int alignment (which must be a power of /// \brief This turns an int alignment (which must be a power of 2) into the
/// 2) into the form used internally in Attribute. /// form used internally in Attribute.
AttrBuilder &addAlignmentAttr(unsigned Align); AttrBuilder &addAlignmentAttr(unsigned Align);
/// addStackAlignmentAttr - This turns an int stack alignment (which must be a /// \brief This turns an int stack alignment (which must be a power of 2) into
/// power of 2) into the form used internally in Attribute. /// the form used internally in Attribute.
AttrBuilder &addStackAlignmentAttr(unsigned Align); AttrBuilder &addStackAlignmentAttr(unsigned Align);
/// addRawValue - Add the raw value to the internal representation. /// \brief Add the raw value to the internal representation.
///
/// N.B. This should be used ONLY for decoding LLVM bitcode! /// N.B. This should be used ONLY for decoding LLVM bitcode!
AttrBuilder &addRawValue(uint64_t Val); AttrBuilder &addRawValue(uint64_t Val);
/// @brief Remove attributes that are used on functions only. /// \brief Remove attributes that are used on functions only.
void removeFunctionOnlyAttrs() { void removeFunctionOnlyAttrs() {
removeAttribute(Attribute::NoReturn) removeAttribute(Attribute::NoReturn)
.removeAttribute(Attribute::NoUnwind) .removeAttribute(Attribute::NoUnwind)

View File

@ -42,34 +42,22 @@ public:
return Vals; return Vals;
} }
bool contains(Attribute::AttrKind Kind) const; bool hasAttribute(Attribute::AttrKind A) const;
bool contains(StringRef Kind) const;
bool hasAttribute(uint64_t A) const;
bool hasAttributes() const; bool hasAttributes() const;
bool hasAttributes(const Attribute &A) const;
uint64_t getAlignment() const; uint64_t getAlignment() const;
uint64_t getStackAlignment() const; uint64_t getStackAlignment() const;
bool operator==(Attribute::AttrKind Kind) const { bool operator==(Attribute::AttrKind Kind) const;
return contains(Kind); bool operator!=(Attribute::AttrKind Kind) const;
}
bool operator!=(Attribute::AttrKind Kind) const {
return !contains(Kind);
}
bool operator==(StringRef Kind) const { bool operator==(StringRef Kind) const;
return contains(Kind); bool operator!=(StringRef Kind) const;
}
bool operator!=(StringRef Kind) const {
return !contains(Kind);
}
uint64_t getBitMask() const; // FIXME: Remove. uint64_t getBitMask() const; // FIXME: Remove.
static uint64_t getAttrMask(uint64_t Val); static uint64_t getAttrMask(Attribute::AttrKind Val);
void Profile(FoldingSetNodeID &ID) const { void Profile(FoldingSetNodeID &ID) const {
Profile(ID, Data, Vals); Profile(ID, Data, Vals);
@ -87,23 +75,28 @@ public:
/// \class /// \class
/// \brief This class represents a set of attributes. /// \brief This class represents a set of attributes.
class AttributeSetImpl : public FoldingSetNode { class AttributeSetImpl : public FoldingSetNode {
LLVMContext &Context;
SmallVector<AttributeWithIndex, 4> AttrList;
// AttributesSet is uniqued, these should not be publicly available. // AttributesSet is uniqued, these should not be publicly available.
void operator=(const AttributeSetImpl &) LLVM_DELETED_FUNCTION; void operator=(const AttributeSetImpl &) LLVM_DELETED_FUNCTION;
AttributeSetImpl(const AttributeSetImpl &) LLVM_DELETED_FUNCTION; AttributeSetImpl(const AttributeSetImpl &) LLVM_DELETED_FUNCTION;
public: public:
LLVMContext &Context;
SmallVector<AttributeWithIndex, 4> Attrs;
AttributeSetImpl(LLVMContext &C, ArrayRef<AttributeWithIndex> attrs) AttributeSetImpl(LLVMContext &C, ArrayRef<AttributeWithIndex> attrs)
: Context(C), Attrs(attrs.begin(), attrs.end()) {} : Context(C), AttrList(attrs.begin(), attrs.end()) {}
LLVMContext &getContext() { return Context; }
ArrayRef<AttributeWithIndex> getAttributes() const { return AttrList; }
unsigned getNumAttributes() const { return AttrList.size(); }
void Profile(FoldingSetNodeID &ID) const { void Profile(FoldingSetNodeID &ID) const {
Profile(ID, Attrs); Profile(ID, AttrList);
} }
static void Profile(FoldingSetNodeID &ID, ArrayRef<AttributeWithIndex> Attrs){ static void Profile(FoldingSetNodeID &ID,
for (unsigned i = 0, e = Attrs.size(); i != e; ++i) { ArrayRef<AttributeWithIndex> AttrList){
ID.AddInteger(Attrs[i].Attrs.getBitMask()); for (unsigned i = 0, e = AttrList.size(); i != e; ++i) {
ID.AddInteger(Attrs[i].Index); ID.AddInteger(AttrList[i].Index);
ID.AddInteger(AttrList[i].Attrs.getBitMask());
} }
} }
}; };

View File

@ -69,10 +69,6 @@ bool Attribute::hasAttributes() const {
return pImpl && pImpl->hasAttributes(); return pImpl && pImpl->hasAttributes();
} }
bool Attribute::hasAttributes(const Attribute &A) const {
return pImpl && pImpl->hasAttributes(A);
}
/// This returns the alignment field of an attribute as a byte alignment value. /// This returns the alignment field of an attribute as a byte alignment value.
unsigned Attribute::getAlignment() const { unsigned Attribute::getAlignment() const {
if (!hasAttribute(Attribute::Alignment)) if (!hasAttribute(Attribute::Alignment))
@ -89,11 +85,10 @@ unsigned Attribute::getStackAlignment() const {
} }
bool Attribute::operator==(AttrKind K) const { bool Attribute::operator==(AttrKind K) const {
return pImpl && pImpl->contains(K); return pImpl && *pImpl == K;
} }
bool Attribute::operator!=(AttrKind K) const { bool Attribute::operator!=(AttrKind K) const {
return !(pImpl && pImpl->contains(K)); return !(*this == K);
} }
uint64_t Attribute::getBitMask() const { uint64_t Attribute::getBitMask() const {
@ -281,9 +276,11 @@ bool AttrBuilder::contains(Attribute::AttrKind A) const {
bool AttrBuilder::hasAttributes() const { bool AttrBuilder::hasAttributes() const {
return Bits != 0; return Bits != 0;
} }
bool AttrBuilder::hasAttributes(const Attribute &A) const { bool AttrBuilder::hasAttributes(const Attribute &A) const {
return Bits & A.getBitMask(); return Bits & A.getBitMask();
} }
bool AttrBuilder::hasAlignmentAttr() const { bool AttrBuilder::hasAlignmentAttr() const {
return Bits & AttributeImpl::getAttrMask(Attribute::Alignment); return Bits & AttributeImpl::getAttrMask(Attribute::Alignment);
} }
@ -322,25 +319,31 @@ AttributeImpl::AttributeImpl(LLVMContext &C, StringRef data) {
Data = ConstantDataArray::getString(C, data); Data = ConstantDataArray::getString(C, data);
} }
bool AttributeImpl::contains(Attribute::AttrKind Kind) const { bool AttributeImpl::operator==(Attribute::AttrKind Kind) const {
if (ConstantInt *CI = dyn_cast<ConstantInt>(Data)) if (ConstantInt *CI = dyn_cast<ConstantInt>(Data))
return CI->getZExtValue() == Kind; return CI->getZExtValue() == Kind;
return false; return false;
} }
bool AttributeImpl::operator!=(Attribute::AttrKind Kind) const {
return !(*this == Kind);
}
bool AttributeImpl::contains(StringRef Kind) const { bool AttributeImpl::operator==(StringRef Kind) const {
if (ConstantDataArray *CDA = dyn_cast<ConstantDataArray>(Data)) if (ConstantDataArray *CDA = dyn_cast<ConstantDataArray>(Data))
if (CDA->isString()) if (CDA->isString())
return CDA->getAsString() == Kind; return CDA->getAsString() == Kind;
return false; return false;
} }
bool AttributeImpl::operator!=(StringRef Kind) const {
return !(*this == Kind);
}
uint64_t AttributeImpl::getBitMask() const { uint64_t AttributeImpl::getBitMask() const {
// FIXME: Remove this. // FIXME: Remove this.
return cast<ConstantInt>(Data)->getZExtValue(); return cast<ConstantInt>(Data)->getZExtValue();
} }
uint64_t AttributeImpl::getAttrMask(uint64_t Val) { uint64_t AttributeImpl::getAttrMask(Attribute::AttrKind Val) {
switch (Val) { switch (Val) {
case Attribute::None: return 0; case Attribute::None: return 0;
case Attribute::ZExt: return 1 << 0; case Attribute::ZExt: return 1 << 0;
@ -376,7 +379,7 @@ uint64_t AttributeImpl::getAttrMask(uint64_t Val) {
llvm_unreachable("Unsupported attribute type"); llvm_unreachable("Unsupported attribute type");
} }
bool AttributeImpl::hasAttribute(uint64_t A) const { bool AttributeImpl::hasAttribute(Attribute::AttrKind A) const {
return (getBitMask() & getAttrMask(A)) != 0; return (getBitMask() & getAttrMask(A)) != 0;
} }
@ -384,11 +387,6 @@ bool AttributeImpl::hasAttributes() const {
return getBitMask() != 0; return getBitMask() != 0;
} }
bool AttributeImpl::hasAttributes(const Attribute &A) const {
// FIXME: getBitMask() won't work here in the future.
return getBitMask() & A.getBitMask();
}
uint64_t AttributeImpl::getAlignment() const { uint64_t AttributeImpl::getAlignment() const {
return getBitMask() & getAttrMask(Attribute::Alignment); return getBitMask() & getAttrMask(Attribute::Alignment);
} }
@ -449,14 +447,15 @@ const AttributeSet &AttributeSet::operator=(const AttributeSet &RHS) {
/// This is the number of arguments that have an attribute set on them /// This is the number of arguments that have an attribute set on them
/// (including the function itself). /// (including the function itself).
unsigned AttributeSet::getNumSlots() const { unsigned AttributeSet::getNumSlots() const {
return AttrList ? AttrList->Attrs.size() : 0; return AttrList ? AttrList->getNumAttributes() : 0;
} }
/// getSlot - Return the AttributeWithIndex at the specified slot. This /// getSlot - Return the AttributeWithIndex at the specified slot. This
/// holds a number plus a set of attributes. /// holds a number plus a set of attributes.
const AttributeWithIndex &AttributeSet::getSlot(unsigned Slot) const { const AttributeWithIndex &AttributeSet::getSlot(unsigned Slot) const {
assert(AttrList && Slot < AttrList->Attrs.size() && "Slot # out of range!"); assert(AttrList && Slot < AttrList->getNumAttributes() &&
return AttrList->Attrs[Slot]; "Slot # out of range!");
return AttrList->getAttributes()[Slot];
} }
bool AttributeSet::hasAttribute(unsigned Index, Attribute::AttrKind Kind) const{ bool AttributeSet::hasAttribute(unsigned Index, Attribute::AttrKind Kind) const{
@ -486,7 +485,7 @@ uint64_t AttributeSet::getBitMask(unsigned Index) const {
Attribute AttributeSet::getAttributes(unsigned Idx) const { Attribute AttributeSet::getAttributes(unsigned Idx) const {
if (AttrList == 0) return Attribute(); if (AttrList == 0) return Attribute();
const SmallVectorImpl<AttributeWithIndex> &Attrs = AttrList->Attrs; ArrayRef<AttributeWithIndex> Attrs = AttrList->getAttributes();
for (unsigned i = 0, e = Attrs.size(); i != e && Attrs[i].Index <= Idx; ++i) for (unsigned i = 0, e = Attrs.size(); i != e && Attrs[i].Index <= Idx; ++i)
if (Attrs[i].Index == Idx) if (Attrs[i].Index == Idx)
return Attrs[i].Attrs; return Attrs[i].Attrs;
@ -499,7 +498,7 @@ Attribute AttributeSet::getAttributes(unsigned Idx) const {
bool AttributeSet::hasAttrSomewhere(Attribute::AttrKind Attr) const { bool AttributeSet::hasAttrSomewhere(Attribute::AttrKind Attr) const {
if (AttrList == 0) return false; if (AttrList == 0) return false;
const SmallVector<AttributeWithIndex, 4> &Attrs = AttrList->Attrs; ArrayRef<AttributeWithIndex> Attrs = AttrList->getAttributes();
for (unsigned i = 0, e = Attrs.size(); i != e; ++i) for (unsigned i = 0, e = Attrs.size(); i != e; ++i)
if (Attrs[i].Attrs.hasAttribute(Attr)) if (Attrs[i].Attrs.hasAttribute(Attr))
return true; return true;
@ -528,7 +527,7 @@ AttributeSet AttributeSet::addAttr(LLVMContext &C, unsigned Idx,
if (AttrList == 0) if (AttrList == 0)
NewAttrList.push_back(AttributeWithIndex::get(Idx, Attrs)); NewAttrList.push_back(AttributeWithIndex::get(Idx, Attrs));
else { else {
const SmallVector<AttributeWithIndex, 4> &OldAttrList = AttrList->Attrs; ArrayRef<AttributeWithIndex> OldAttrList = AttrList->getAttributes();
unsigned i = 0, e = OldAttrList.size(); unsigned i = 0, e = OldAttrList.size();
// Copy attributes for arguments before this one. // Copy attributes for arguments before this one.
for (; i != e && OldAttrList[i].Index < Idx; ++i) for (; i != e && OldAttrList[i].Index < Idx; ++i)
@ -569,7 +568,7 @@ AttributeSet AttributeSet::removeAttr(LLVMContext &C, unsigned Idx,
return *this; return *this;
SmallVector<AttributeWithIndex, 8> NewAttrList; SmallVector<AttributeWithIndex, 8> NewAttrList;
const SmallVector<AttributeWithIndex, 4> &OldAttrList = AttrList->Attrs; ArrayRef<AttributeWithIndex> OldAttrList = AttrList->getAttributes();
unsigned i = 0, e = OldAttrList.size(); unsigned i = 0, e = OldAttrList.size();
// Copy attributes for arguments before this one. // Copy attributes for arguments before this one.
@ -595,7 +594,7 @@ void AttributeSet::dump() const {
dbgs() << "PAL[ "; dbgs() << "PAL[ ";
for (unsigned i = 0; i < getNumSlots(); ++i) { for (unsigned i = 0; i < getNumSlots(); ++i) {
const AttributeWithIndex &PAWI = getSlot(i); const AttributeWithIndex &PAWI = getSlot(i);
dbgs() << "{" << PAWI.Index << "," << PAWI.Attrs.getAsString() << "} "; dbgs() << "{ " << PAWI.Index << ", " << PAWI.Attrs.getAsString() << " } ";
} }
dbgs() << "]\n"; dbgs() << "]\n";