General cleanups.
authorBill Wendling <isanbard@gmail.com>
Fri, 4 Jan 2013 20:54:35 +0000 (20:54 +0000)
committerBill Wendling <isanbard@gmail.com>
Fri, 4 Jan 2013 20:54:35 +0000 (20:54 +0000)
* 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

include/llvm/IR/Attributes.h
lib/IR/AttributeImpl.h
lib/IR/Attributes.cpp

index c28f0bd09075de6a5c97f29c25792905e8782129..b80e9069e51f41abbcf07fdc0f6a604214aebd5b 100644 (file)
@@ -109,9 +109,6 @@ public:
   /// \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 @@ public:
   /// 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 @@ public:
 
   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)
index ecdb9280ced2f22969f77753b537fc1b13f1612f..42b4fe36b22cd907b7daef5d2070eebff4abe00e 100644 (file)
@@ -42,34 +42,22 @@ public:
     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 @@ public:
 /// \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());
     }
   }
 };
index 427134b00f69e4c9a268afd4dab6b2e737d7eda7..5057f783bb5a727ba8c64255c84e3281c7d4f422 100644 (file)
@@ -69,10 +69,6 @@ bool Attribute::hasAttributes() const {
   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 @@ unsigned Attribute::getStackAlignment() const {
 }
 
 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::contains(Attribute::AttrKind A) const {
 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 @@ AttributeImpl::AttributeImpl(LLVMContext &C, StringRef 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))
     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 @@ uint64_t AttributeImpl::getAttrMask(uint64_t Val) {
   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 @@ bool AttributeImpl::hasAttributes() const {
   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 @@ const AttributeSet &AttributeSet::operator=(const AttributeSet &RHS) {
 /// 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 @@ uint64_t AttributeSet::getBitMask(unsigned Index) const {
 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 @@ Attribute AttributeSet::getAttributes(unsigned Idx) const {
 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 @@ AttributeSet AttributeSet::addAttr(LLVMContext &C, unsigned Idx,
   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 @@ AttributeSet AttributeSet::removeAttr(LLVMContext &C, unsigned Idx,
     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 @@ void AttributeSet::dump() const {
   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";