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
This commit is contained in:
Bill Wendling 2012-12-30 01:38:39 +00:00
parent b4912b9dcc
commit 529ec718ac
2 changed files with 31 additions and 0 deletions

View 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);

View 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();
}