Use the AttributeSet when removing multiple attributes. Use Attribute::AttrKind
authorBill Wendling <isanbard@gmail.com>
Wed, 23 Jan 2013 00:45:55 +0000 (00:45 +0000)
committerBill Wendling <isanbard@gmail.com>
Wed, 23 Jan 2013 00:45:55 +0000 (00:45 +0000)
when removing one attribute. This further encapsulates the use of the attributes.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@173214 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/IR/Attributes.h
include/llvm/IR/Function.h
lib/IR/Attributes.cpp
lib/IR/Core.cpp
lib/IR/Function.cpp
lib/IR/Instructions.cpp
lib/Transforms/IPO/FunctionAttrs.cpp
lib/Transforms/IPO/GlobalOpt.cpp
lib/Transforms/Instrumentation/MemorySanitizer.cpp

index 072b9cf43a3bbcf53b1b0fc211397f13f5f4a5a4..ab9891062951546d5a105ace1290bf8ca88a6d41 100644 (file)
@@ -217,6 +217,11 @@ private:
   /// list.
   AttributeSet addAttr(LLVMContext &C, unsigned Idx, Attribute Attrs) const;
 
+  /// \brief Remove the specified attribute at the specified index from this
+  /// attribute list.  Since attribute lists are immutable, this returns the new
+  /// list.
+  AttributeSet removeAttr(LLVMContext &C, unsigned Idx, Attribute Attrs) const;
+
   explicit AttributeSet(AttributeSetImpl *LI) : AttrList(LI) {}
 public:
   AttributeSet() : AttrList(0) {}
@@ -254,9 +259,16 @@ public:
   }
 
   /// \brief Remove the specified attribute at the specified index from this
-  /// attribute list.  Since attribute lists are immutable, this returns the new
+  /// attribute list. Since attribute lists are immutable, this returns the new
   /// list.
-  AttributeSet removeAttr(LLVMContext &C, unsigned Idx, Attribute Attrs) const;
+  AttributeSet removeAttribute(LLVMContext &C, unsigned Idx, 
+                               Attribute::AttrKind Attr) const;
+
+  /// \brief Remove the specified attributes at the specified index from this
+  /// attribute list. Since attribute lists are immutable, this returns the new
+  /// list.
+  AttributeSet removeAttributes(LLVMContext &C, unsigned Idx, 
+                                AttributeSet Attrs) const;
 
   //===--------------------------------------------------------------------===//
   // Attribute List Accessors
index 46feb8ba2824404afb004783f037908e7c2f13bd..fe27d9b75d4b4304c0eaa8f858d89e0c5b6b52b8 100644 (file)
@@ -189,7 +189,7 @@ public:
   void addAttributes(unsigned i, AttributeSet attrs);
 
   /// @brief removes the attributes from the list of attributes.
-  void removeAttribute(unsigned i, Attribute attr);
+  void removeAttributes(unsigned i, AttributeSet attr);
 
   /// @brief Extract the alignment for a call or parameter (0=unknown).
   unsigned getParamAlignment(unsigned i) const {
index c67b1f3eee69c373a567912ff83bf85c78be9b89..a3abd36fc0dde0387e7b6d72c7c562dd025897a3 100644 (file)
@@ -730,6 +730,16 @@ AttributeSet AttributeSet::addAttr(LLVMContext &C, unsigned Idx,
   return get(C, NewAttrList);
 }
 
+AttributeSet AttributeSet::removeAttribute(LLVMContext &C, unsigned Idx,
+                                           Attribute::AttrKind Attr) const {
+  return removeAttr(C, Idx, Attribute::get(C, Attr));
+}
+
+AttributeSet AttributeSet::removeAttributes(LLVMContext &C, unsigned Idx,
+                                            AttributeSet Attrs) const {
+  return removeAttr(C, Idx, Attrs.getAttributes(Idx));
+}
+
 AttributeSet AttributeSet::removeAttr(LLVMContext &C, unsigned Idx,
                                       Attribute Attrs) const {
 #ifndef NDEBUG
index e72eb699824844cdf9d6df80c65501c38d962c50..0e4253678975e32c0edf26f8353314042f6dd79b 100644 (file)
@@ -1394,8 +1394,9 @@ void LLVMRemoveFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA) {
   const AttributeSet PAL = Func->getAttributes();
   AttrBuilder B(PA);
   const AttributeSet PALnew =
-    PAL.removeAttr(Func->getContext(), AttributeSet::FunctionIndex,
-                   Attribute::get(Func->getContext(), B));
+    PAL.removeAttributes(Func->getContext(), AttributeSet::FunctionIndex,
+                         AttributeSet::get(Func->getContext(),
+                                           AttributeSet::FunctionIndex, B));
   Func->setAttributes(PALnew);
 }
 
@@ -1686,9 +1687,10 @@ void LLVMRemoveInstrAttribute(LLVMValueRef Instr, unsigned index,
                               LLVMAttribute PA) {
   CallSite Call = CallSite(unwrap<Instruction>(Instr));
   AttrBuilder B(PA);
-  Call.setAttributes(
-    Call.getAttributes().removeAttr(Call->getContext(), index,
-                                    Attribute::get(Call->getContext(), B)));
+  Call.setAttributes(Call.getAttributes()
+                       .removeAttributes(Call->getContext(), index,
+                                         AttributeSet::get(Call->getContext(),
+                                                           index, B)));
 }
 
 void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index, 
index 4d047f6443cabc8702240497ee5216a466673665..f2f3ec9aab4482f69c3973f36623c5426412d8ff 100644 (file)
@@ -133,7 +133,10 @@ void Argument::addAttr(Attribute attr) {
 
 /// removeAttr - Remove a Attribute from an argument
 void Argument::removeAttr(Attribute attr) {
-  getParent()->removeAttribute(getArgNo() + 1, attr);
+  AttrBuilder B(attr);
+  getParent()->removeAttributes(getArgNo() + 1,
+                                AttributeSet::get(getParent()->getContext(),
+                                                  getArgNo() + 1, B));
 }
 
 
@@ -263,9 +266,9 @@ void Function::addAttributes(unsigned i, AttributeSet attrs) {
   setAttributes(PAL);
 }
 
-void Function::removeAttribute(unsigned i, Attribute attrs) {
+void Function::removeAttributes(unsigned i, AttributeSet attrs) {
   AttributeSet PAL = getAttributes();
-  PAL = PAL.removeAttr(getContext(), i, attrs);
+  PAL = PAL.removeAttributes(getContext(), i, attrs);
   setAttributes(PAL);
 }
 
index 8597d5c45242b98603c0affacf10ac5d9058fa7d..8a0a465a96bbc77b8aefa641c985bc8fef7b624f 100644 (file)
@@ -334,14 +334,18 @@ CallInst::CallInst(const CallInst &CI)
 void CallInst::addAttribute(unsigned i, Attribute attr) {
   AttributeSet PAL = getAttributes();
   AttrBuilder B(attr);
-  PAL = PAL.addAttributes(getContext(), i,
-                          AttributeSet::get(getContext(), i, B));
+  LLVMContext &Context = getContext();
+  PAL = PAL.addAttributes(Context, i,
+                          AttributeSet::get(Context, i, B));
   setAttributes(PAL);
 }
 
 void CallInst::removeAttribute(unsigned i, Attribute attr) {
   AttributeSet PAL = getAttributes();
-  PAL = PAL.removeAttr(getContext(), i, attr);
+  AttrBuilder B(attr);
+  LLVMContext &Context = getContext();
+  PAL = PAL.removeAttributes(Context, i,
+                             AttributeSet::get(Context, i, B));
   setAttributes(PAL);
 }
 
@@ -599,7 +603,9 @@ void InvokeInst::addAttribute(unsigned i, Attribute attr) {
 
 void InvokeInst::removeAttribute(unsigned i, Attribute attr) {
   AttributeSet PAL = getAttributes();
-  PAL = PAL.removeAttr(getContext(), i, attr);
+  AttrBuilder B(attr);
+  PAL = PAL.removeAttributes(getContext(), i,
+                             AttributeSet::get(getContext(), i, B));
   setAttributes(PAL);
 }
 
index c267097c4a580b91eb1bb14e9c70701750830503..7e46dcb4296369067bfa1b0af48fab2ce0da5a6d 100644 (file)
@@ -215,8 +215,9 @@ bool FunctionAttrs::AddReadAttrs(const CallGraphSCC &SCC) {
     AttrBuilder B;
     B.addAttribute(Attribute::ReadOnly)
       .addAttribute(Attribute::ReadNone);
-    F->removeAttribute(AttributeSet::FunctionIndex,
-                       Attribute::get(F->getContext(), B));
+    F->removeAttributes(AttributeSet::FunctionIndex,
+                        AttributeSet::get(F->getContext(),
+                                          AttributeSet::FunctionIndex, B));
 
     // Add in the new attribute.
     F->addAttribute(AttributeSet::FunctionIndex,
index efec788162bda7144aa9f7131367f0362d0c4416..6fe4316d3bb2ffb070891fe6998d86aa3a479105 100644 (file)
@@ -2072,8 +2072,7 @@ static AttributeSet StripNest(LLVMContext &C, const AttributeSet &Attrs) {
       continue;
 
     // There can be only one.
-    return Attrs.removeAttr(C, Attrs.getSlot(i).Index,
-                            Attribute::get(C, Attribute::Nest));
+    return Attrs.removeAttribute(C, Attrs.getSlot(i).Index, Attribute::Nest);
   }
 
   return Attrs;
index 20b6de2506dc03bc0909bf15167a059a2c5189c8..40f0ebb8cf3a6072e8eaeef2e3c1d2ea4303974b 100644 (file)
@@ -1461,8 +1461,10 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
         AttrBuilder B;
         B.addAttribute(Attribute::ReadOnly)
           .addAttribute(Attribute::ReadNone);
-        Func->removeAttribute(AttributeSet::FunctionIndex,
-                              Attribute::get(Func->getContext(), B));
+        Func->removeAttributes(AttributeSet::FunctionIndex,
+                               AttributeSet::get(Func->getContext(),
+                                                 AttributeSet::FunctionIndex,
+                                                 B));
       }
     }
     IRBuilder<> IRB(&I);
@@ -1853,8 +1855,9 @@ bool MemorySanitizer::runOnFunction(Function &F) {
   AttrBuilder B;
   B.addAttribute(Attribute::ReadOnly)
     .addAttribute(Attribute::ReadNone);
-  F.removeAttribute(AttributeSet::FunctionIndex,
-                    Attribute::get(F.getContext(), B));
+  F.removeAttributes(AttributeSet::FunctionIndex,
+                     AttributeSet::get(F.getContext(),
+                                       AttributeSet::FunctionIndex, B));
 
   return Visitor.runOnFunction();
 }