attributes helper functions - please review

Reed Kotler rkotler at mips.com
Tue Mar 12 23:28:26 PDT 2013


These were requested by Bill Wendling to simplify a Mips 16 clang change.

The test is in the code in Clang which uses these for mips 16
-------------- next part --------------
Index: include/llvm/IR/Function.h
===================================================================
--- include/llvm/IR/Function.h	(revision 176874)
+++ include/llvm/IR/Function.h	(working copy)
@@ -181,6 +181,14 @@
                                              AttributeSet::FunctionIndex, N));
   }
 
+  /// addFnAttr - Add function attributes to this function.
+  ///
+  void addFnAttr(StringRef Kind) {
+    setAttributes(
+      AttributeSets.addAttribute(getContext(),
+                                 AttributeSet::FunctionIndex, Kind));
+  }
+
   /// \brief Return true if the function has the attribute.
   bool hasFnAttribute(Attribute::AttrKind Kind) const {
     return AttributeSets.hasAttribute(AttributeSet::FunctionIndex, Kind);
Index: include/llvm/IR/Attributes.h
===================================================================
--- include/llvm/IR/Attributes.h	(revision 176874)
+++ include/llvm/IR/Attributes.h	(working copy)
@@ -247,6 +247,11 @@
   AttributeSet addAttribute(LLVMContext &C, unsigned Idx,
                             Attribute::AttrKind Attr) const;
 
+  /// \brief Add an attribute to the attribute set at the given index. Since
+  /// attribute sets are immutable, this returns a new set.
+  AttributeSet addAttribute(LLVMContext &C, unsigned Idx,
+                             StringRef Kind) const;
+
   /// \brief Add attributes to the attribute set at the given index. Since
   /// attribute sets are immutable, this returns a new set.
   AttributeSet addAttributes(LLVMContext &C, unsigned Idx,
Index: lib/IR/Attributes.cpp
===================================================================
--- lib/IR/Attributes.cpp	(revision 176874)
+++ lib/IR/Attributes.cpp	(working copy)
@@ -649,6 +649,13 @@
   return addAttributes(C, Idx, AttributeSet::get(C, Idx, Attr));
 }
 
+AttributeSet AttributeSet::addAttribute(LLVMContext &C, unsigned Idx,
+                           StringRef Kind) const {
+  llvm::AttrBuilder B;
+  B.addAttribute(Kind);
+  return  addAttributes(C, Idx, AttributeSet::get(C, Idx, B));
+}
+
 AttributeSet AttributeSet::addAttributes(LLVMContext &C, unsigned Idx,
                                          AttributeSet Attrs) const {
   if (!pImpl) return Attrs;


More information about the llvm-commits mailing list