Use the Attributes::get method which takes an AttrVal value directly to simplify...
authorBill Wendling <isanbard@gmail.com>
Tue, 16 Oct 2012 05:23:31 +0000 (05:23 +0000)
committerBill Wendling <isanbard@gmail.com>
Tue, 16 Oct 2012 05:23:31 +0000 (05:23 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@166009 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Function.h
include/llvm/Instructions.h
lib/Transforms/IPO/GlobalOpt.cpp
lib/Transforms/Scalar/ObjCARC.cpp
lib/Transforms/Scalar/SimplifyLibCalls.cpp

index 26b148d848ab1c4ec5b67b922bf3ea028eaa14c6..e211e9ab52a871b7ba9a8e29c037beeec614143b 100644 (file)
@@ -178,9 +178,7 @@ public:
   ///
   void addFnAttr(Attributes::AttrVal N) { 
     // Function Attributes are stored at ~0 index 
-    AttrBuilder B;
-    B.addAttribute(N);
-    addAttribute(~0U, Attributes::get(getContext(), B));
+    addAttribute(AttrListPtr::FunctionIndex, Attributes::get(getContext(), N));
   }
 
   /// removeFnAttr - Remove function attributes from this function.
@@ -278,9 +276,7 @@ public:
     return getParamAttributes(n).hasAttribute(Attributes::NoAlias);
   }
   void setDoesNotAlias(unsigned n) {
-    AttrBuilder B;
-    B.addAttribute(Attributes::NoAlias);
-    addAttribute(n, Attributes::get(getContext(), B));
+    addAttribute(n, Attributes::get(getContext(), Attributes::NoAlias));
   }
 
   /// @brief Determine if the parameter can be captured.
@@ -289,9 +285,7 @@ public:
     return getParamAttributes(n).hasAttribute(Attributes::NoCapture);
   }
   void setDoesNotCapture(unsigned n) {
-    AttrBuilder B;
-    B.addAttribute(Attributes::NoCapture);
-    addAttribute(n, Attributes::get(getContext(), B));
+    addAttribute(n, Attributes::get(getContext(), Attributes::NoCapture));
   }
 
   /// copyAttributesFrom - copy all additional attributes (those not needed to
index 97612b6f8506cfe62589f519775d01d5273d0e97..40dbbaabe69a45a010dcbe57c5151826fc7d1714 100644 (file)
@@ -1281,9 +1281,8 @@ public:
   /// @brief Return true if the call should not be inlined.
   bool isNoInline() const { return hasFnAttr(Attributes::NoInline); }
   void setIsNoInline() {
-    AttrBuilder B;
-    B.addAttribute(Attributes::NoInline);
-    addAttribute(AttrListPtr::FunctionIndex, Attributes::get(getContext(), B));
+    addAttribute(AttrListPtr::FunctionIndex,
+                 Attributes::get(getContext(), Attributes::NoInline));
   }
 
   /// @brief Return true if the call can return twice
@@ -1291,9 +1290,8 @@ public:
     return hasFnAttr(Attributes::ReturnsTwice);
   }
   void setCanReturnTwice() {
-    AttrBuilder B;
-    B.addAttribute(Attributes::ReturnsTwice);
-    addAttribute(AttrListPtr::FunctionIndex, Attributes::get(getContext(), B));
+    addAttribute(AttrListPtr::FunctionIndex,
+                 Attributes::get(getContext(), Attributes::ReturnsTwice));
   }
 
   /// @brief Determine if the call does not access memory.
@@ -1301,9 +1299,8 @@ public:
     return hasFnAttr(Attributes::ReadNone);
   }
   void setDoesNotAccessMemory() {
-    AttrBuilder B;
-    B.addAttribute(Attributes::ReadNone);
-    addAttribute(AttrListPtr::FunctionIndex, Attributes::get(getContext(), B));
+    addAttribute(AttrListPtr::FunctionIndex,
+                 Attributes::get(getContext(), Attributes::ReadNone));
   }
 
   /// @brief Determine if the call does not access or only reads memory.
@@ -1311,25 +1308,22 @@ public:
     return doesNotAccessMemory() || hasFnAttr(Attributes::ReadOnly);
   }
   void setOnlyReadsMemory() {
-    AttrBuilder B;
-    B.addAttribute(Attributes::ReadOnly);
-    addAttribute(AttrListPtr::FunctionIndex, Attributes::get(getContext(), B));
+    addAttribute(AttrListPtr::FunctionIndex,
+                 Attributes::get(getContext(), Attributes::ReadOnly));
   }
 
   /// @brief Determine if the call cannot return.
   bool doesNotReturn() const { return hasFnAttr(Attributes::NoReturn); }
   void setDoesNotReturn() {
-    AttrBuilder B;
-    B.addAttribute(Attributes::NoReturn);
-    addAttribute(AttrListPtr::FunctionIndex, Attributes::get(getContext(), B));
+    addAttribute(AttrListPtr::FunctionIndex,
+                 Attributes::get(getContext(), Attributes::NoReturn));
   }
 
   /// @brief Determine if the call cannot unwind.
   bool doesNotThrow() const { return hasFnAttr(Attributes::NoUnwind); }
   void setDoesNotThrow() {
-    AttrBuilder B;
-    B.addAttribute(Attributes::NoUnwind);
-    addAttribute(AttrListPtr::FunctionIndex, Attributes::get(getContext(), B));
+    addAttribute(AttrListPtr::FunctionIndex,
+                 Attributes::get(getContext(), Attributes::NoUnwind));
   }
 
   /// @brief Determine if the call returns a structure through first
@@ -3036,9 +3030,8 @@ public:
   /// @brief Return true if the call should not be inlined.
   bool isNoInline() const { return hasFnAttr(Attributes::NoInline); }
   void setIsNoInline() {
-    AttrBuilder B;
-    B.addAttribute(Attributes::NoInline);
-    addAttribute(AttrListPtr::FunctionIndex, Attributes::get(getContext(), B));
+    addAttribute(AttrListPtr::FunctionIndex,
+                 Attributes::get(getContext(), Attributes::NoInline));
   }
 
   /// @brief Determine if the call does not access memory.
@@ -3046,9 +3039,8 @@ public:
     return hasFnAttr(Attributes::ReadNone);
   }
   void setDoesNotAccessMemory() {
-    AttrBuilder B;
-    B.addAttribute(Attributes::ReadNone);
-    addAttribute(AttrListPtr::FunctionIndex, Attributes::get(getContext(), B));
+    addAttribute(AttrListPtr::FunctionIndex,
+                 Attributes::get(getContext(), Attributes::ReadNone));
   }
 
   /// @brief Determine if the call does not access or only reads memory.
@@ -3056,25 +3048,22 @@ public:
     return doesNotAccessMemory() || hasFnAttr(Attributes::ReadOnly);
   }
   void setOnlyReadsMemory() {
-    AttrBuilder B;
-    B.addAttribute(Attributes::ReadOnly);
-    addAttribute(AttrListPtr::FunctionIndex, Attributes::get(getContext(), B));
+    addAttribute(AttrListPtr::FunctionIndex,
+                 Attributes::get(getContext(), Attributes::ReadOnly));
   }
 
   /// @brief Determine if the call cannot return.
   bool doesNotReturn() const { return hasFnAttr(Attributes::NoReturn); }
   void setDoesNotReturn() {
-    AttrBuilder B;
-    B.addAttribute(Attributes::NoReturn);
-    addAttribute(AttrListPtr::FunctionIndex, Attributes::get(getContext(), B));
+    addAttribute(AttrListPtr::FunctionIndex,
+                 Attributes::get(getContext(), Attributes::NoReturn));
   }
 
   /// @brief Determine if the call cannot unwind.
   bool doesNotThrow() const { return hasFnAttr(Attributes::NoUnwind); }
   void setDoesNotThrow() {
-    AttrBuilder B;
-    B.addAttribute(Attributes::NoUnwind);
-    addAttribute(AttrListPtr::FunctionIndex, Attributes::get(getContext(), B));
+    addAttribute(AttrListPtr::FunctionIndex,
+                 Attributes::get(getContext(), Attributes::NoUnwind));
   }
 
   /// @brief Determine if the call returns a structure through first
index 6468ff3276ed82acb46e4ded35701d0b09eae4f4..678189b3d6c0601162c77fd07ae6095007bb5467 100644 (file)
@@ -2062,15 +2062,13 @@ static void ChangeCalleesToFastCall(Function *F) {
 }
 
 static AttrListPtr StripNest(LLVMContext &C, const AttrListPtr &Attrs) {
-  AttrBuilder B;
-  B.addAttribute(Attributes::Nest);
-
   for (unsigned i = 0, e = Attrs.getNumSlots(); i != e; ++i) {
     if (!Attrs.getSlot(i).Attrs.hasAttribute(Attributes::Nest))
       continue;
 
     // There can be only one.
-    return Attrs.removeAttr(C, Attrs.getSlot(i).Index, Attributes::get(C, B));
+    return Attrs.removeAttr(C, Attrs.getSlot(i).Index,
+                            Attributes::get(C, Attributes::Nest));
   }
 
   return Attrs;
index e18208d4a57802f3005cc8edb685aeece30dd054..dfdf50549da4d41da6906dbcf71c16f54433a30a 100644 (file)
@@ -1788,11 +1788,9 @@ Constant *ObjCARCOpt::getRetainRVCallee(Module *M) {
     Type *I8X = PointerType::getUnqual(Type::getInt8Ty(C));
     Type *Params[] = { I8X };
     FunctionType *FTy = FunctionType::get(I8X, Params, /*isVarArg=*/false);
-    AttrBuilder B;
-    B.addAttribute(Attributes::NoUnwind);
     AttrListPtr Attributes =
       AttrListPtr().addAttr(M->getContext(), AttrListPtr::FunctionIndex,
-                            Attributes::get(M->getContext(), B));
+                            Attributes::get(C, Attributes::NoUnwind));
     RetainRVCallee =
       M->getOrInsertFunction("objc_retainAutoreleasedReturnValue", FTy,
                              Attributes);
@@ -1806,11 +1804,9 @@ Constant *ObjCARCOpt::getAutoreleaseRVCallee(Module *M) {
     Type *I8X = PointerType::getUnqual(Type::getInt8Ty(C));
     Type *Params[] = { I8X };
     FunctionType *FTy = FunctionType::get(I8X, Params, /*isVarArg=*/false);
-    AttrBuilder B;
-    B.addAttribute(Attributes::NoUnwind);
     AttrListPtr Attributes =
       AttrListPtr().addAttr(M->getContext(), AttrListPtr::FunctionIndex,
-                            Attributes::get(C, B));
+                            Attributes::get(C, Attributes::NoUnwind));
     AutoreleaseRVCallee =
       M->getOrInsertFunction("objc_autoreleaseReturnValue", FTy,
                              Attributes);
@@ -1822,11 +1818,9 @@ Constant *ObjCARCOpt::getReleaseCallee(Module *M) {
   if (!ReleaseCallee) {
     LLVMContext &C = M->getContext();
     Type *Params[] = { PointerType::getUnqual(Type::getInt8Ty(C)) };
-    AttrBuilder B;
-    B.addAttribute(Attributes::NoUnwind);
     AttrListPtr Attributes =
       AttrListPtr().addAttr(M->getContext(), AttrListPtr::FunctionIndex,
-                            Attributes::get(C, B));
+                            Attributes::get(C, Attributes::NoUnwind));
     ReleaseCallee =
       M->getOrInsertFunction(
         "objc_release",
@@ -1840,11 +1834,9 @@ Constant *ObjCARCOpt::getRetainCallee(Module *M) {
   if (!RetainCallee) {
     LLVMContext &C = M->getContext();
     Type *Params[] = { PointerType::getUnqual(Type::getInt8Ty(C)) };
-    AttrBuilder B;
-    B.addAttribute(Attributes::NoUnwind);
     AttrListPtr Attributes =
       AttrListPtr().addAttr(M->getContext(), AttrListPtr::FunctionIndex,
-                            Attributes::get(C, B));
+                            Attributes::get(C, Attributes::NoUnwind));
     RetainCallee =
       M->getOrInsertFunction(
         "objc_retain",
@@ -1873,11 +1865,9 @@ Constant *ObjCARCOpt::getAutoreleaseCallee(Module *M) {
   if (!AutoreleaseCallee) {
     LLVMContext &C = M->getContext();
     Type *Params[] = { PointerType::getUnqual(Type::getInt8Ty(C)) };
-    AttrBuilder B;
-    B.addAttribute(Attributes::NoUnwind);
     AttrListPtr Attributes =
       AttrListPtr().addAttr(M->getContext(), AttrListPtr::FunctionIndex,
-                            Attributes::get(C, B));
+                            Attributes::get(C, Attributes::NoUnwind));
     AutoreleaseCallee =
       M->getOrInsertFunction(
         "objc_autorelease",
@@ -3850,14 +3840,10 @@ Constant *ObjCARCContract::getStoreStrongCallee(Module *M) {
     Type *I8XX = PointerType::getUnqual(I8X);
     Type *Params[] = { I8XX, I8X };
 
-    AttrBuilder BNoUnwind;
-    BNoUnwind.addAttribute(Attributes::NoUnwind);
-    AttrBuilder BNoCapture;
-    BNoCapture.addAttribute(Attributes::NoCapture);
     AttrListPtr Attributes = AttrListPtr()
       .addAttr(M->getContext(), AttrListPtr::FunctionIndex,
-               Attributes::get(C, BNoUnwind))
-      .addAttr(M->getContext(), 1, Attributes::get(C, BNoCapture));
+               Attributes::get(C, Attributes::NoUnwind))
+      .addAttr(M->getContext(), 1, Attributes::get(C, Attributes::NoCapture));
 
     StoreStrongCallee =
       M->getOrInsertFunction(
@@ -3874,11 +3860,9 @@ Constant *ObjCARCContract::getRetainAutoreleaseCallee(Module *M) {
     Type *I8X = PointerType::getUnqual(Type::getInt8Ty(C));
     Type *Params[] = { I8X };
     FunctionType *FTy = FunctionType::get(I8X, Params, /*isVarArg=*/false);
-    AttrBuilder B;
-    B.addAttribute(Attributes::NoUnwind);
     AttrListPtr Attributes =
       AttrListPtr().addAttr(M->getContext(), AttrListPtr::FunctionIndex,
-                            Attributes::get(C, B));
+                            Attributes::get(C, Attributes::NoUnwind));
     RetainAutoreleaseCallee =
       M->getOrInsertFunction("objc_retainAutorelease", FTy, Attributes);
   }
@@ -3891,11 +3875,9 @@ Constant *ObjCARCContract::getRetainAutoreleaseRVCallee(Module *M) {
     Type *I8X = PointerType::getUnqual(Type::getInt8Ty(C));
     Type *Params[] = { I8X };
     FunctionType *FTy = FunctionType::get(I8X, Params, /*isVarArg=*/false);
-    AttrBuilder B;
-    B.addAttribute(Attributes::NoUnwind);
     AttrListPtr Attributes =
       AttrListPtr().addAttr(M->getContext(), AttrListPtr::FunctionIndex,
-                            Attributes::get(C, B));
+                            Attributes::get(C, Attributes::NoUnwind));
     RetainAutoreleaseRVCallee =
       M->getOrInsertFunction("objc_retainAutoreleaseReturnValue", FTy,
                              Attributes);
index 0223d39ab3bc28cc0115df107b9b8bc325c0ea8c..d86c4cbc9f6d102b099cccd8bbb5ecfee5bee68e 100644 (file)
@@ -348,9 +348,8 @@ struct StrToOpt : public LibCallOptimization {
     if (isa<ConstantPointerNull>(EndPtr)) {
       // With a null EndPtr, this function won't capture the main argument.
       // It would be readonly too, except that it still may write to errno.
-      AttrBuilder B;
-      B.addAttribute(Attributes::NoCapture);
-      CI->addAttribute(1, Attributes::get(Callee->getContext(), B));
+      CI->addAttribute(1, Attributes::get(Callee->getContext(),
+                                          Attributes::NoCapture));
     }
 
     return 0;