From 529ec718ac6844d2b8b60cb668c80dc5d5acf979 Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Sun, 30 Dec 2012 01:38:39 +0000 Subject: [PATCH] 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 --- lib/VMCore/AttributeImpl.h | 17 +++++++++++++++++ lib/VMCore/Attributes.cpp | 14 ++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/lib/VMCore/AttributeImpl.h b/lib/VMCore/AttributeImpl.h index 65ac3ea9823..38eef6f16c3 100644 --- a/lib/VMCore/AttributeImpl.h +++ b/lib/VMCore/AttributeImpl.h @@ -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); diff --git a/lib/VMCore/Attributes.cpp b/lib/VMCore/Attributes.cpp index a1e0856971d..52405f25ae6 100644 --- a/lib/VMCore/Attributes.cpp +++ b/lib/VMCore/Attributes.cpp @@ -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(Data)) + return CI->getZExtValue() == Kind; + return false; +} + +bool AttributeImpl::contains(StringRef Kind) const { + if (ConstantDataArray *CDA = dyn_cast(Data)) + if (CDA->isString()) + return CDA->getAsString() == Kind; + return false; +} + uint64_t AttributeImpl::getBitMask() const { + // FIXME: Remove this. return cast(Data)->getZExtValue(); } -- 2.34.1