Use the enum value of the attributes when adding them to the attributes builder.
authorBill Wendling <isanbard@gmail.com>
Tue, 9 Oct 2012 09:11:20 +0000 (09:11 +0000)
committerBill Wendling <isanbard@gmail.com>
Tue, 9 Oct 2012 09:11:20 +0000 (09:11 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@165494 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Attributes.h
include/llvm/AttributesImpl.h
lib/AsmParser/LLParser.cpp
lib/Transforms/IPO/PruneEH.cpp
lib/Transforms/Instrumentation/GCOVProfiling.cpp
lib/Transforms/Scalar/ObjCARC.cpp
lib/VMCore/Attributes.cpp

index eae384a4669cd7f3feac4441410a43f1e6e5fdbb..00eb325cacda98417c3934625c387c948421baec 100644 (file)
@@ -205,31 +205,8 @@ public:
 
     uint64_t getAlignment() const;
 
-    void addAddressSafetyAttr();
-    void addAlwaysInlineAttr();
-    void addByValAttr();
-    void addInlineHintAttr();
-    void addInRegAttr();
-    void addNakedAttr();
-    void addNestAttr();
-    void addNoAliasAttr();
-    void addNoCaptureAttr();
-    void addNoImplicitFloatAttr();
-    void addNoInlineAttr();
-    void addNonLazyBindAttr();
-    void addNoRedZoneAttr();
-    void addNoReturnAttr();
-    void addNoUnwindAttr();
-    void addOptimizeForSizeAttr();
-    void addReadNoneAttr();
-    void addReadOnlyAttr();
-    void addReturnsTwiceAttr();
-    void addSExtAttr();
-    void addStackProtectAttr();
-    void addStackProtectReqAttr();
-    void addStructRetAttr();
-    void addUWTableAttr();
-    void addZExtAttr();
+    void addAttribute(Attributes::AttrVal Val);
+    void removeAttribute(Attributes::AttrVal Val);
 
     void addAlignmentAttr(unsigned Align);
     void addStackAlignmentAttr(unsigned Align);
@@ -276,13 +253,16 @@ public:
     return hasAttribute(Attributes::StructRet);
   }
 
-  // Attribute query methods.
-  // FIXME: StackAlignment & Alignment attributes have no predicate methods.
+  /// @brief Return true if the attribute is present.
+  bool hasAttribute(AttrVal Val) const;
+
+  /// @brief Return true if attributes exist
   bool hasAttributes() const {
     return Attrs.hasAttributes();
   }
+
+  /// @brief Return true if the attributes are a non-null intersection.
   bool hasAttributes(const Attributes &A) const;
-  bool hasAttribute(AttrVal Val) const;
 
   /// This returns the alignment field of an attribute as a byte alignment
   /// value.
index 4f68cb4c3eec179b35e97ed6691748b1c5680641..eea11a7011a4f4acc5c254398d6768968cc38ceb 100644 (file)
@@ -25,7 +25,6 @@ class AttributesImpl : public FoldingSetNode {
   friend class Attributes;
   uint64_t Bits;                // FIXME: We will be expanding this.
 
-  uint64_t getAttrMask(uint64_t Val) const;
 public:
   AttributesImpl(uint64_t bits) : Bits(bits) {}
 
@@ -39,6 +38,8 @@ public:
 
   bool isEmptyOrSingleton() const;
 
+  static uint64_t getAttrMask(uint64_t Val);
+
   void Profile(FoldingSetNodeID &ID) const {
     Profile(ID, Bits);
   }
index d813d67e9543285e12ed21407a30b104a6709d44..76ac0f7b4a7a7fca919486e2e71d07c2f638a17f 100644 (file)
@@ -927,32 +927,32 @@ bool LLParser::ParseOptionalAttrs(Attributes::Builder &B, unsigned AttrKind) {
     switch (Token) {
     default:  // End of attributes.
       return HaveError;
-    case lltok::kw_zeroext:         B.addZExtAttr(); break;
-    case lltok::kw_signext:         B.addSExtAttr(); break;
-    case lltok::kw_inreg:           B.addInRegAttr(); break;
-    case lltok::kw_sret:            B.addStructRetAttr(); break;
-    case lltok::kw_noalias:         B.addNoAliasAttr(); break;
-    case lltok::kw_nocapture:       B.addNoCaptureAttr(); break;
-    case lltok::kw_byval:           B.addByValAttr(); break;
-    case lltok::kw_nest:            B.addNestAttr(); break;
-
-    case lltok::kw_noreturn:        B.addNoReturnAttr(); break;
-    case lltok::kw_nounwind:        B.addNoUnwindAttr(); break;
-    case lltok::kw_uwtable:         B.addUWTableAttr(); break;
-    case lltok::kw_returns_twice:   B.addReturnsTwiceAttr(); break;
-    case lltok::kw_noinline:        B.addNoInlineAttr(); break;
-    case lltok::kw_readnone:        B.addReadNoneAttr(); break;
-    case lltok::kw_readonly:        B.addReadOnlyAttr(); break;
-    case lltok::kw_inlinehint:      B.addInlineHintAttr(); break;
-    case lltok::kw_alwaysinline:    B.addAlwaysInlineAttr(); break;
-    case lltok::kw_optsize:         B.addOptimizeForSizeAttr(); break;
-    case lltok::kw_ssp:             B.addStackProtectAttr(); break;
-    case lltok::kw_sspreq:          B.addStackProtectReqAttr(); break;
-    case lltok::kw_noredzone:       B.addNoRedZoneAttr(); break;
-    case lltok::kw_noimplicitfloat: B.addNoImplicitFloatAttr(); break;
-    case lltok::kw_naked:           B.addNakedAttr(); break;
-    case lltok::kw_nonlazybind:     B.addNonLazyBindAttr(); break;
-    case lltok::kw_address_safety:  B.addAddressSafetyAttr(); break;
+    case lltok::kw_zeroext:         B.addAttribute(Attributes::ZExt); break;
+    case lltok::kw_signext:         B.addAttribute(Attributes::SExt); break;
+    case lltok::kw_inreg:           B.addAttribute(Attributes::InReg); break;
+    case lltok::kw_sret:            B.addAttribute(Attributes::StructRet); break;
+    case lltok::kw_noalias:         B.addAttribute(Attributes::NoAlias); break;
+    case lltok::kw_nocapture:       B.addAttribute(Attributes::NoCapture); break;
+    case lltok::kw_byval:           B.addAttribute(Attributes::ByVal); break;
+    case lltok::kw_nest:            B.addAttribute(Attributes::Nest); break;
+
+    case lltok::kw_noreturn:        B.addAttribute(Attributes::NoReturn); break;
+    case lltok::kw_nounwind:        B.addAttribute(Attributes::NoUnwind); break;
+    case lltok::kw_uwtable:         B.addAttribute(Attributes::UWTable); break;
+    case lltok::kw_returns_twice:   B.addAttribute(Attributes::ReturnsTwice); break;
+    case lltok::kw_noinline:        B.addAttribute(Attributes::NoInline); break;
+    case lltok::kw_readnone:        B.addAttribute(Attributes::ReadNone); break;
+    case lltok::kw_readonly:        B.addAttribute(Attributes::ReadOnly); break;
+    case lltok::kw_inlinehint:      B.addAttribute(Attributes::InlineHint); break;
+    case lltok::kw_alwaysinline:    B.addAttribute(Attributes::AlwaysInline); break;
+    case lltok::kw_optsize:         B.addAttribute(Attributes::OptimizeForSize); break;
+    case lltok::kw_ssp:             B.addAttribute(Attributes::StackProtect); break;
+    case lltok::kw_sspreq:          B.addAttribute(Attributes::StackProtectReq); break;
+    case lltok::kw_noredzone:       B.addAttribute(Attributes::NoRedZone); break;
+    case lltok::kw_noimplicitfloat: B.addAttribute(Attributes::NoImplicitFloat); break;
+    case lltok::kw_naked:           B.addAttribute(Attributes::Naked); break;
+    case lltok::kw_nonlazybind:     B.addAttribute(Attributes::NonLazyBind); break;
+    case lltok::kw_address_safety:  B.addAttribute(Attributes::AddressSafety); break;
 
     case lltok::kw_alignstack: {
       unsigned Alignment;
index 8ebf6ee1dd0c6186bbc7199ce54b0fe74baa6bee..3e598abfcf615ee07535c3234c071021f81e3767 100644 (file)
@@ -140,9 +140,9 @@ bool PruneEH::runOnSCC(CallGraphSCC &SCC) {
       Attributes::Builder NewAttributes;
 
       if (!SCCMightUnwind)
-        NewAttributes.addNoUnwindAttr();
+        NewAttributes.addAttribute(Attributes::NoUnwind);
       if (!SCCMightReturn)
-        NewAttributes.addNoReturnAttr();
+        NewAttributes.addAttribute(Attributes::NoReturn);
 
       Function *F = (*I)->getFunction();
       const AttrListPtr &PAL = F->getAttributes();
index 4c71fe3f4a92500de70312d4ffa828c42d87cea8..66d8570108bd82a6b63639716436e24a10f4b7e1 100644 (file)
@@ -683,7 +683,7 @@ void GCOVProfiler::insertCounterWriteout(
   F->setUnnamedAddr(true);
   F->setLinkage(GlobalValue::InternalLinkage);
   Attributes::Builder B;
-  B.addNoInlineAttr();
+  B.addAttribute(Attributes::NoInline);
   F->addFnAttr(Attributes::get(B));
 
   BB = BasicBlock::Create(*Ctx, "entry", F);
@@ -704,7 +704,7 @@ void GCOVProfiler::insertIndirectCounterIncrement() {
   Fn->setUnnamedAddr(true);
   Fn->setLinkage(GlobalValue::InternalLinkage);
   Attributes::Builder B;
-  B.addNoInlineAttr();
+  B.addAttribute(Attributes::NoInline);
   Fn->addFnAttr(Attributes::get(B));
 
   Type *Int32Ty = Type::getInt32Ty(*Ctx);
index dca6a72fb16b712b0e3ebbcfa843504f7b1ba544..629f9d2ff57a58a0ece61e72e84794e7a1ec07e1 100644 (file)
@@ -1789,7 +1789,7 @@ Constant *ObjCARCOpt::getRetainRVCallee(Module *M) {
     Type *Params[] = { I8X };
     FunctionType *FTy = FunctionType::get(I8X, Params, /*isVarArg=*/false);
     Attributes::Builder B;
-    B.addNoUnwindAttr();
+    B.addAttribute(Attributes::NoUnwind);
     AttrListPtr Attributes = AttrListPtr().addAttr(~0u, Attributes::get(B));
     RetainRVCallee =
       M->getOrInsertFunction("objc_retainAutoreleasedReturnValue", FTy,
@@ -1805,7 +1805,7 @@ Constant *ObjCARCOpt::getAutoreleaseRVCallee(Module *M) {
     Type *Params[] = { I8X };
     FunctionType *FTy = FunctionType::get(I8X, Params, /*isVarArg=*/false);
     Attributes::Builder B;
-    B.addNoUnwindAttr();
+    B.addAttribute(Attributes::NoUnwind);
     AttrListPtr Attributes = AttrListPtr().addAttr(~0u, Attributes::get(B));
     AutoreleaseRVCallee =
       M->getOrInsertFunction("objc_autoreleaseReturnValue", FTy,
@@ -1819,7 +1819,7 @@ Constant *ObjCARCOpt::getReleaseCallee(Module *M) {
     LLVMContext &C = M->getContext();
     Type *Params[] = { PointerType::getUnqual(Type::getInt8Ty(C)) };
     Attributes::Builder B;
-    B.addNoUnwindAttr();
+    B.addAttribute(Attributes::NoUnwind);
     AttrListPtr Attributes = AttrListPtr().addAttr(~0u, Attributes::get(B));
     ReleaseCallee =
       M->getOrInsertFunction(
@@ -1835,7 +1835,7 @@ Constant *ObjCARCOpt::getRetainCallee(Module *M) {
     LLVMContext &C = M->getContext();
     Type *Params[] = { PointerType::getUnqual(Type::getInt8Ty(C)) };
     Attributes::Builder B;
-    B.addNoUnwindAttr();
+    B.addAttribute(Attributes::NoUnwind);
     AttrListPtr Attributes = AttrListPtr().addAttr(~0u, Attributes::get(B));
     RetainCallee =
       M->getOrInsertFunction(
@@ -1866,7 +1866,7 @@ Constant *ObjCARCOpt::getAutoreleaseCallee(Module *M) {
     LLVMContext &C = M->getContext();
     Type *Params[] = { PointerType::getUnqual(Type::getInt8Ty(C)) };
     Attributes::Builder B;
-    B.addNoUnwindAttr();
+    B.addAttribute(Attributes::NoUnwind);
     AttrListPtr Attributes = AttrListPtr().addAttr(~0u, Attributes::get(B));
     AutoreleaseCallee =
       M->getOrInsertFunction(
@@ -3841,9 +3841,9 @@ Constant *ObjCARCContract::getStoreStrongCallee(Module *M) {
     Type *Params[] = { I8XX, I8X };
 
     Attributes::Builder BNoUnwind;
-    BNoUnwind.addNoUnwindAttr();
+    BNoUnwind.addAttribute(Attributes::NoUnwind);
     Attributes::Builder BNoCapture;
-    BNoCapture.addNoCaptureAttr();
+    BNoCapture.addAttribute(Attributes::NoCapture);
     AttrListPtr Attributes = AttrListPtr()
       .addAttr(~0u, Attributes::get(BNoUnwind))
       .addAttr(1, Attributes::get(BNoCapture));
@@ -3864,7 +3864,7 @@ Constant *ObjCARCContract::getRetainAutoreleaseCallee(Module *M) {
     Type *Params[] = { I8X };
     FunctionType *FTy = FunctionType::get(I8X, Params, /*isVarArg=*/false);
     Attributes::Builder B;
-    B.addNoUnwindAttr();
+    B.addAttribute(Attributes::NoUnwind);
     AttrListPtr Attributes = AttrListPtr().addAttr(~0u, Attributes::get(B));
     RetainAutoreleaseCallee =
       M->getOrInsertFunction("objc_retainAutorelease", FTy, Attributes);
@@ -3879,7 +3879,7 @@ Constant *ObjCARCContract::getRetainAutoreleaseRVCallee(Module *M) {
     Type *Params[] = { I8X };
     FunctionType *FTy = FunctionType::get(I8X, Params, /*isVarArg=*/false);
     Attributes::Builder B;
-    B.addNoUnwindAttr();
+    B.addAttribute(Attributes::NoUnwind);
     AttrListPtr Attributes = AttrListPtr().addAttr(~0u, Attributes::get(B));
     RetainAutoreleaseRVCallee =
       M->getOrInsertFunction("objc_retainAutoreleaseReturnValue", FTy,
index 4024410b42f6b58f04ad18285dfd23b53a09ea45..6e689736f30c2ac884ba969415cb9316d9fb0d82 100644 (file)
@@ -65,14 +65,14 @@ Attributes Attributes::get(LLVMContext &Context, Attributes::Builder &B) {
   return Attributes(PA);
 }
 
-bool Attributes::hasAttributes(const Attributes &A) const {
-  return Attrs.hasAttributes(A);
-}
-
 bool Attributes::hasAttribute(AttrVal Val) const {
   return Attrs.hasAttribute(Val);
 }
 
+bool Attributes::hasAttributes(const Attributes &A) const {
+  return Attrs.hasAttributes(A);
+}
+
 /// This returns the alignment field of an attribute as a byte alignment value.
 unsigned Attributes::getAlignment() const {
   if (!hasAttribute(Attributes::Alignment))
@@ -122,17 +122,17 @@ Attributes Attributes::typeIncompatible(Type *Ty) {
   
   if (!Ty->isIntegerTy()) {
     // Attributes that only apply to integers.
-    Incompatible.addSExtAttr();
-    Incompatible.addZExtAttr();
+    Incompatible.addAttribute(Attributes::SExt);
+    Incompatible.addAttribute(Attributes::ZExt);
   }
   
   if (!Ty->isPointerTy()) {
     // Attributes that only apply to pointers.
-    Incompatible.addByValAttr();
-    Incompatible.addNestAttr();
-    Incompatible.addNoAliasAttr();
-    Incompatible.addNoCaptureAttr();
-    Incompatible.addStructRetAttr();
+    Incompatible.addAttribute(Attributes::ByVal);
+    Incompatible.addAttribute(Attributes::Nest);
+    Incompatible.addAttribute(Attributes::NoAlias);
+    Incompatible.addAttribute(Attributes::NoCapture);
+    Incompatible.addAttribute(Attributes::StructRet);
   }
   
   return Attributes(Incompatible.Bits); // FIXME: Use Attributes::get().
@@ -210,80 +210,8 @@ std::string Attributes::getAsString() const {
 // Attributes::Builder Implementation
 //===----------------------------------------------------------------------===//
 
-void Attributes::Builder::addAddressSafetyAttr() {
-  Bits |= Attribute::AddressSafety_i;
-}
-void Attributes::Builder::addAlwaysInlineAttr() {
-  Bits |= Attribute::AlwaysInline_i;
-}
-void Attributes::Builder::addByValAttr() {
-  Bits |= Attribute::ByVal_i;
-}
-void Attributes::Builder::addInlineHintAttr() {
-  Bits |= Attribute::InlineHint_i;
-}
-void Attributes::Builder::addInRegAttr() {
-  Bits |= Attribute::InReg_i;
-}
-void Attributes::Builder::addNakedAttr() {
-  Bits |= Attribute::Naked_i;
-}
-void Attributes::Builder::addNestAttr() {
-  Bits |= Attribute::Nest_i;
-}
-void Attributes::Builder::addNoAliasAttr() {
-  Bits |= Attribute::NoAlias_i;
-}
-void Attributes::Builder::addNoCaptureAttr() {
-  Bits |= Attribute::NoCapture_i;
-}
-void Attributes::Builder::addNoImplicitFloatAttr() {
-  Bits |= Attribute::NoImplicitFloat_i;
-}
-void Attributes::Builder::addNoInlineAttr() {
-  Bits |= Attribute::NoInline_i;
-}
-void Attributes::Builder::addNonLazyBindAttr() {
-  Bits |= Attribute::NonLazyBind_i;
-}
-void Attributes::Builder::addNoRedZoneAttr() {
-  Bits |= Attribute::NoRedZone_i;
-}
-void Attributes::Builder::addNoReturnAttr() {
-  Bits |= Attribute::NoReturn_i;
-}
-void Attributes::Builder::addNoUnwindAttr() {
-  Bits |= Attribute::NoUnwind_i;
-}
-void Attributes::Builder::addOptimizeForSizeAttr() {
-  Bits |= Attribute::OptimizeForSize_i;
-}
-void Attributes::Builder::addReadNoneAttr() {
-  Bits |= Attribute::ReadNone_i;
-}
-void Attributes::Builder::addReadOnlyAttr() {
-  Bits |= Attribute::ReadOnly_i;
-}
-void Attributes::Builder::addReturnsTwiceAttr() {
-  Bits |= Attribute::ReturnsTwice_i;
-}
-void Attributes::Builder::addSExtAttr() {
-  Bits |= Attribute::SExt_i;
-}
-void Attributes::Builder::addStackProtectAttr() {
-  Bits |= Attribute::StackProtect_i;
-}
-void Attributes::Builder::addStackProtectReqAttr() {
-  Bits |= Attribute::StackProtectReq_i;
-}
-void Attributes::Builder::addStructRetAttr() {
-  Bits |= Attribute::StructRet_i;
-}
-void Attributes::Builder::addUWTableAttr() {
-  Bits |= Attribute::UWTable_i;
-}
-void Attributes::Builder::addZExtAttr() {
-  Bits |= Attribute::ZExt_i;
+void Attributes::Builder::addAttribute(Attributes::AttrVal Val) {
+  Bits |= AttributesImpl::getAttrMask(Val);
 }
 
 void Attributes::Builder::addAlignmentAttr(unsigned Align) {
@@ -300,6 +228,10 @@ void Attributes::Builder::addStackAlignmentAttr(unsigned Align) {
   Bits |= (Log2_32(Align) + 1) << 26;
 }
 
+void Attributes::Builder::removeAttribute(Attributes::AttrVal Val) {
+  Bits &= ~AttributesImpl::getAttrMask(Val);
+}
+
 void Attributes::Builder::removeAttributes(const Attributes &A) {
   Bits &= ~A.Raw();
 }
@@ -407,7 +339,7 @@ uint64_t Attributes::Builder::getAlignment() const {
 // AttributeImpl Definition
 //===----------------------------------------------------------------------===//
 
-uint64_t AttributesImpl::getAttrMask(uint64_t Val) const {
+uint64_t AttributesImpl::getAttrMask(uint64_t Val) {
   switch (Val) {
   case Attributes::None:            return 0;
   case Attributes::ZExt:            return 1 << 0;