diff options
| author | Bill Wendling <isanbard@gmail.com> | 2013-02-13 08:42:21 +0000 |
|---|---|---|
| committer | Bill Wendling <isanbard@gmail.com> | 2013-02-13 08:42:21 +0000 |
| commit | bce7b97c805c0907f4639fa17abc2bd8727116b0 (patch) | |
| tree | 2a6361dbae9166bd6a7bc9a01401f188ff3d1805 /llvm/lib | |
| parent | ee6bc533658813d1b04dbd23452089751ab01c96 (diff) | |
| download | bcm5719-llvm-bce7b97c805c0907f4639fa17abc2bd8727116b0.tar.gz bcm5719-llvm-bce7b97c805c0907f4639fa17abc2bd8727116b0.zip | |
Add some accessor and query methods for retrieving Attribute objects and such.
llvm-svn: 175046
Diffstat (limited to 'llvm/lib')
| -rw-r--r-- | llvm/lib/IR/AttributeImpl.h | 4 | ||||
| -rw-r--r-- | llvm/lib/IR/Attributes.cpp | 41 |
2 files changed, 45 insertions, 0 deletions
diff --git a/llvm/lib/IR/AttributeImpl.h b/llvm/lib/IR/AttributeImpl.h index 7bb1fccba0a..cb2c55ccbe7 100644 --- a/llvm/lib/IR/AttributeImpl.h +++ b/llvm/lib/IR/AttributeImpl.h @@ -170,8 +170,12 @@ public: static AttributeSetNode *get(LLVMContext &C, ArrayRef<Attribute> Attrs); bool hasAttribute(Attribute::AttrKind Kind) const; + bool hasAttribute(StringRef Kind) const; bool hasAttributes() const { return !AttrList.empty(); } + Attribute getAttribute(Attribute::AttrKind Kind) const; + Attribute getAttribute(StringRef Kind) const; + unsigned getAlignment() const; unsigned getStackAlignment() const; std::string getAsString(bool InAttrGrp) const; diff --git a/llvm/lib/IR/Attributes.cpp b/llvm/lib/IR/Attributes.cpp index 8249be45746..7d0bec2b118 100644 --- a/llvm/lib/IR/Attributes.cpp +++ b/llvm/lib/IR/Attributes.cpp @@ -441,6 +441,30 @@ bool AttributeSetNode::hasAttribute(Attribute::AttrKind Kind) const { return false; } +bool AttributeSetNode::hasAttribute(StringRef Kind) const { + for (SmallVectorImpl<Attribute>::const_iterator I = AttrList.begin(), + E = AttrList.end(); I != E; ++I) + if (I->hasAttribute(Kind)) + return true; + return false; +} + +Attribute AttributeSetNode::getAttribute(Attribute::AttrKind Kind) const { + for (SmallVectorImpl<Attribute>::const_iterator I = AttrList.begin(), + E = AttrList.end(); I != E; ++I) + if (I->hasAttribute(Kind)) + return *I; + return Attribute(); +} + +Attribute AttributeSetNode::getAttribute(StringRef Kind) const { + for (SmallVectorImpl<Attribute>::const_iterator I = AttrList.begin(), + E = AttrList.end(); I != E; ++I) + if (I->hasAttribute(Kind)) + return *I; + return Attribute(); +} + unsigned AttributeSetNode::getAlignment() const { for (SmallVectorImpl<Attribute>::const_iterator I = AttrList.begin(), E = AttrList.end(); I != E; ++I) @@ -760,6 +784,11 @@ bool AttributeSet::hasAttribute(unsigned Index, Attribute::AttrKind Kind) const{ return ASN ? ASN->hasAttribute(Kind) : false; } +bool AttributeSet::hasAttribute(unsigned Index, StringRef Kind) const { + AttributeSetNode *ASN = getAttributes(Index); + return ASN ? ASN->hasAttribute(Kind) : false; +} + bool AttributeSet::hasAttributes(unsigned Index) const { AttributeSetNode *ASN = getAttributes(Index); return ASN ? ASN->hasAttributes() : false; @@ -779,6 +808,18 @@ bool AttributeSet::hasAttrSomewhere(Attribute::AttrKind Attr) const { return false; } +Attribute AttributeSet::getAttribute(unsigned Index, + Attribute::AttrKind Kind) const { + AttributeSetNode *ASN = getAttributes(Index); + return ASN ? ASN->getAttribute(Kind) : Attribute(); +} + +Attribute AttributeSet::getAttribute(unsigned Index, + StringRef Kind) const { + AttributeSetNode *ASN = getAttributes(Index); + return ASN ? ASN->getAttribute(Kind) : Attribute(); +} + unsigned AttributeSet::getParamAlignment(unsigned Index) const { AttributeSetNode *ASN = getAttributes(Index); return ASN ? ASN->getAlignment() : 0; |

