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
diff --git a/include/llvm/IR/Attributes.h b/include/llvm/IR/Attributes.h
index c28f0bd..b80e906 100644
--- a/include/llvm/IR/Attributes.h
+++ b/include/llvm/IR/Attributes.h
@@ -109,9 +109,6 @@
/// \brief Return true if attributes exist
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
/// value.
unsigned getAlignment() const;
@@ -120,6 +117,7 @@
/// alignment value.
unsigned getStackAlignment() const;
+ /// \brief Equality and non-equality query methods.
bool operator==(AttrKind K) const;
bool operator!=(AttrKind K) const;
@@ -167,50 +165,51 @@
void clear() { Bits = 0; }
- /// addAttribute - Add an attribute to the builder.
+ /// \brief Add an attribute to the builder.
AttrBuilder &addAttribute(Attribute::AttrKind Val);
- /// removeAttribute - Remove an attribute from the builder.
+ /// \brief Remove an attribute from the builder.
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);
- /// removeAttribute - Remove the attributes from A from the builder.
+ /// \brief Remove the attributes from A from the builder.
AttrBuilder &removeAttributes(const Attribute &A);
/// \brief Return true if the builder has the specified attribute.
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;
- /// 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.
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;
- /// getAlignment - Retrieve the alignment attribute, if it exists.
+ /// \brief Retrieve the alignment attribute, if it exists.
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;
- /// addAlignmentAttr - This turns an int alignment (which must be a power of
- /// 2) into the form used internally in Attribute.
+ /// \brief This turns an int alignment (which must be a power of 2) into the
+ /// form used internally in Attribute.
AttrBuilder &addAlignmentAttr(unsigned Align);
- /// addStackAlignmentAttr - This turns an int stack alignment (which must be a
- /// power of 2) into the form used internally in Attribute.
+ /// \brief This turns an int stack alignment (which must be a power of 2) into
+ /// the form used internally in Attribute.
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!
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() {
removeAttribute(Attribute::NoReturn)
.removeAttribute(Attribute::NoUnwind)
diff --git a/lib/IR/AttributeImpl.h b/lib/IR/AttributeImpl.h
index ecdb928..42b4fe3 100644
--- a/lib/IR/AttributeImpl.h
+++ b/lib/IR/AttributeImpl.h
@@ -42,34 +42,22 @@
return Vals;
}
- bool contains(Attribute::AttrKind Kind) const;
- bool contains(StringRef Kind) const;
-
- bool hasAttribute(uint64_t A) const;
+ bool hasAttribute(Attribute::AttrKind A) const;
bool hasAttributes() const;
- bool hasAttributes(const Attribute &A) const;
uint64_t getAlignment() const;
uint64_t getStackAlignment() const;
- bool operator==(Attribute::AttrKind Kind) const {
- return contains(Kind);
- }
- bool operator!=(Attribute::AttrKind Kind) const {
- return !contains(Kind);
- }
+ bool operator==(Attribute::AttrKind Kind) const;
+ bool operator!=(Attribute::AttrKind Kind) const;
- bool operator==(StringRef Kind) const {
- return contains(Kind);
- }
- bool operator!=(StringRef Kind) const {
- return !contains(Kind);
- }
+ bool operator==(StringRef Kind) const;
+ bool operator!=(StringRef Kind) const;
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 {
Profile(ID, Data, Vals);
@@ -87,23 +75,28 @@
/// \class
/// \brief This class represents a set of attributes.
class AttributeSetImpl : public FoldingSetNode {
+ LLVMContext &Context;
+ SmallVector<AttributeWithIndex, 4> AttrList;
+
// AttributesSet is uniqued, these should not be publicly available.
void operator=(const AttributeSetImpl &) LLVM_DELETED_FUNCTION;
AttributeSetImpl(const AttributeSetImpl &) LLVM_DELETED_FUNCTION;
public:
- LLVMContext &Context;
- SmallVector<AttributeWithIndex, 4> 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 {
- Profile(ID, Attrs);
+ Profile(ID, AttrList);
}
- static void Profile(FoldingSetNodeID &ID, ArrayRef<AttributeWithIndex> Attrs){
- for (unsigned i = 0, e = Attrs.size(); i != e; ++i) {
- ID.AddInteger(Attrs[i].Attrs.getBitMask());
- ID.AddInteger(Attrs[i].Index);
+ static void Profile(FoldingSetNodeID &ID,
+ ArrayRef<AttributeWithIndex> AttrList){
+ for (unsigned i = 0, e = AttrList.size(); i != e; ++i) {
+ ID.AddInteger(AttrList[i].Index);
+ ID.AddInteger(AttrList[i].Attrs.getBitMask());
}
}
};
diff --git a/lib/IR/Attributes.cpp b/lib/IR/Attributes.cpp
index 427134b..5057f78 100644
--- a/lib/IR/Attributes.cpp
+++ b/lib/IR/Attributes.cpp
@@ -69,10 +69,6 @@
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.
unsigned Attribute::getAlignment() const {
if (!hasAttribute(Attribute::Alignment))
@@ -89,11 +85,10 @@
}
bool Attribute::operator==(AttrKind K) const {
- return pImpl && pImpl->contains(K);
+ return pImpl && *pImpl == K;
}
-
bool Attribute::operator!=(AttrKind K) const {
- return !(pImpl && pImpl->contains(K));
+ return !(*this == K);
}
uint64_t Attribute::getBitMask() const {
@@ -281,9 +276,11 @@
bool AttrBuilder::hasAttributes() const {
return Bits != 0;
}
+
bool AttrBuilder::hasAttributes(const Attribute &A) const {
return Bits & A.getBitMask();
}
+
bool AttrBuilder::hasAlignmentAttr() const {
return Bits & AttributeImpl::getAttrMask(Attribute::Alignment);
}
@@ -322,25 +319,31 @@
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))
return CI->getZExtValue() == Kind;
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 (CDA->isString())
return CDA->getAsString() == Kind;
return false;
}
+bool AttributeImpl::operator!=(StringRef Kind) const {
+ return !(*this == Kind);
+}
uint64_t AttributeImpl::getBitMask() const {
// FIXME: Remove this.
return cast<ConstantInt>(Data)->getZExtValue();
}
-uint64_t AttributeImpl::getAttrMask(uint64_t Val) {
+uint64_t AttributeImpl::getAttrMask(Attribute::AttrKind Val) {
switch (Val) {
case Attribute::None: return 0;
case Attribute::ZExt: return 1 << 0;
@@ -376,7 +379,7 @@
llvm_unreachable("Unsupported attribute type");
}
-bool AttributeImpl::hasAttribute(uint64_t A) const {
+bool AttributeImpl::hasAttribute(Attribute::AttrKind A) const {
return (getBitMask() & getAttrMask(A)) != 0;
}
@@ -384,11 +387,6 @@
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 {
return getBitMask() & getAttrMask(Attribute::Alignment);
}
@@ -449,14 +447,15 @@
/// This is the number of arguments that have an attribute set on them
/// (including the function itself).
unsigned AttributeSet::getNumSlots() const {
- return AttrList ? AttrList->Attrs.size() : 0;
+ return AttrList ? AttrList->getNumAttributes() : 0;
}
/// getSlot - Return the AttributeWithIndex at the specified slot. This
/// holds a number plus a set of attributes.
const AttributeWithIndex &AttributeSet::getSlot(unsigned Slot) const {
- assert(AttrList && Slot < AttrList->Attrs.size() && "Slot # out of range!");
- return AttrList->Attrs[Slot];
+ assert(AttrList && Slot < AttrList->getNumAttributes() &&
+ "Slot # out of range!");
+ return AttrList->getAttributes()[Slot];
}
bool AttributeSet::hasAttribute(unsigned Index, Attribute::AttrKind Kind) const{
@@ -486,7 +485,7 @@
Attribute AttributeSet::getAttributes(unsigned Idx) const {
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)
if (Attrs[i].Index == Idx)
return Attrs[i].Attrs;
@@ -499,7 +498,7 @@
bool AttributeSet::hasAttrSomewhere(Attribute::AttrKind Attr) const {
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)
if (Attrs[i].Attrs.hasAttribute(Attr))
return true;
@@ -528,7 +527,7 @@
if (AttrList == 0)
NewAttrList.push_back(AttributeWithIndex::get(Idx, Attrs));
else {
- const SmallVector<AttributeWithIndex, 4> &OldAttrList = AttrList->Attrs;
+ ArrayRef<AttributeWithIndex> OldAttrList = AttrList->getAttributes();
unsigned i = 0, e = OldAttrList.size();
// Copy attributes for arguments before this one.
for (; i != e && OldAttrList[i].Index < Idx; ++i)
@@ -569,7 +568,7 @@
return *this;
SmallVector<AttributeWithIndex, 8> NewAttrList;
- const SmallVector<AttributeWithIndex, 4> &OldAttrList = AttrList->Attrs;
+ ArrayRef<AttributeWithIndex> OldAttrList = AttrList->getAttributes();
unsigned i = 0, e = OldAttrList.size();
// Copy attributes for arguments before this one.
@@ -595,7 +594,7 @@
dbgs() << "PAL[ ";
for (unsigned i = 0; i < getNumSlots(); ++i) {
const AttributeWithIndex &PAWI = getSlot(i);
- dbgs() << "{" << PAWI.Index << "," << PAWI.Attrs.getAsString() << "} ";
+ dbgs() << "{ " << PAWI.Index << ", " << PAWI.Attrs.getAsString() << " } ";
}
dbgs() << "]\n";