From 9e2ef7780b91d8e01a9ab172f80272fc94f6956b Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Thu, 25 Jul 2013 18:34:24 +0000 Subject: [PATCH] Add a way to add a kind-value string pair to an attribute. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@187138 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/IR/Attributes.h | 2 ++ include/llvm/IR/Function.h | 5 +++++ lib/IR/Attributes.cpp | 7 +++++++ 3 files changed, 14 insertions(+) diff --git a/include/llvm/IR/Attributes.h b/include/llvm/IR/Attributes.h index 0bf59cf1f61..2183758fbcb 100644 --- a/include/llvm/IR/Attributes.h +++ b/include/llvm/IR/Attributes.h @@ -250,6 +250,8 @@ public: /// attribute sets are immutable, this returns a new set. AttributeSet addAttribute(LLVMContext &C, unsigned Index, StringRef Kind) const; + AttributeSet addAttribute(LLVMContext &C, unsigned Index, + StringRef Kind, StringRef Value) const; /// \brief Add attributes to the attribute set at the given index. Since /// attribute sets are immutable, this returns a new set. diff --git a/include/llvm/IR/Function.h b/include/llvm/IR/Function.h index 970e7f8fd12..0e51c6f7565 100644 --- a/include/llvm/IR/Function.h +++ b/include/llvm/IR/Function.h @@ -190,6 +190,11 @@ public: AttributeSets.addAttribute(getContext(), AttributeSet::FunctionIndex, Kind)); } + void addFnAttr(StringRef Kind, StringRef Value) { + setAttributes( + AttributeSets.addAttribute(getContext(), + AttributeSet::FunctionIndex, Kind, Value)); + } /// @brief Return true if the function has the attribute. bool hasFnAttribute(Attribute::AttrKind Kind) const { diff --git a/lib/IR/Attributes.cpp b/lib/IR/Attributes.cpp index 48743fae692..894ff7dda1f 100644 --- a/lib/IR/Attributes.cpp +++ b/lib/IR/Attributes.cpp @@ -645,6 +645,13 @@ AttributeSet AttributeSet::addAttribute(LLVMContext &C, unsigned Index, return addAttributes(C, Index, AttributeSet::get(C, Index, B)); } +AttributeSet AttributeSet::addAttribute(LLVMContext &C, unsigned Index, + StringRef Kind, StringRef Value) const { + llvm::AttrBuilder B; + B.addAttribute(Kind, Value); + return addAttributes(C, Index, AttributeSet::get(C, Index, B)); +} + AttributeSet AttributeSet::addAttributes(LLVMContext &C, unsigned Index, AttributeSet Attrs) const { if (!pImpl) return Attrs;