Add a few (as yet unused) query methods to determine if the attribute that's
authorBill Wendling <isanbard@gmail.com>
Sun, 30 Dec 2012 01:38:39 +0000 (01:38 +0000)
committerBill Wendling <isanbard@gmail.com>
Sun, 30 Dec 2012 01:38:39 +0000 (01:38 +0000)
stored here is of a certain kind. This is in preparation for when an Attribute
object represents a single attribute, instead of a bitmask of attributes.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@171247 91177308-0d34-0410-b5e6-96231b3b80d8

lib/VMCore/AttributeImpl.h
lib/VMCore/Attributes.cpp

index 65ac3ea98230e7817ba853f06f2d1cb7842d6f78..38eef6f16c386ab64e8b805ca0028efd6cca9500 100644 (file)
@@ -34,6 +34,9 @@ class AttributeImpl : public FoldingSetNode {
 public:
   AttributeImpl(LLVMContext &C, uint64_t data);
 
+  bool contains(Attribute::AttrKind Kind) const;
+  bool contains(StringRef Kind) const;
+
   bool hasAttribute(uint64_t A) const;
 
   bool hasAttributes() const;
@@ -42,6 +45,20 @@ public:
   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==(StringRef Kind) const {
+    return contains(Kind);
+  }
+  bool operator!=(StringRef Kind) const {
+    return !contains(Kind);
+  }
+
   uint64_t getBitMask() const;         // FIXME: Remove.
 
   static uint64_t getAttrMask(uint64_t Val);
index a1e0856971de1a3cd6be326f65b557259683a4c2..52405f25ae6a420eb581fe425568f82f29c20ece 100644 (file)
@@ -302,7 +302,21 @@ AttributeImpl::AttributeImpl(LLVMContext &C, uint64_t data) {
   Data = ConstantInt::get(Type::getInt64Ty(C), data);
 }
 
+bool AttributeImpl::contains(Attribute::AttrKind Kind) const {
+  if (ConstantInt *CI = dyn_cast<ConstantInt>(Data))
+    return CI->getZExtValue() == Kind;
+  return false;
+}
+
+bool AttributeImpl::contains(StringRef Kind) const {
+  if (ConstantDataArray *CDA = dyn_cast<ConstantDataArray>(Data))
+    if (CDA->isString())
+      return CDA->getAsString() == Kind;
+  return false;
+}
+
 uint64_t AttributeImpl::getBitMask() const {
+  // FIXME: Remove this.
   return cast<ConstantInt>(Data)->getZExtValue();
 }