Add a few (as yet unused) query methods to determine if the attribute that's
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
diff --git a/lib/VMCore/AttributeImpl.h b/lib/VMCore/AttributeImpl.h
index 65ac3ea..38eef6f 100644
--- a/lib/VMCore/AttributeImpl.h
+++ b/lib/VMCore/AttributeImpl.h
@@ -34,6 +34,9 @@
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 @@
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);
diff --git a/lib/VMCore/Attributes.cpp b/lib/VMCore/Attributes.cpp
index a1e0856..52405f2 100644
--- a/lib/VMCore/Attributes.cpp
+++ b/lib/VMCore/Attributes.cpp
@@ -302,7 +302,21 @@
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();
}