Use the enum value of the attributes when adding them to the attributes builder.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@165494 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/llvm/Attributes.h b/include/llvm/Attributes.h
index eae384a..00eb325 100644
--- a/include/llvm/Attributes.h
+++ b/include/llvm/Attributes.h
@@ -205,31 +205,8 @@
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 @@
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.
diff --git a/include/llvm/AttributesImpl.h b/include/llvm/AttributesImpl.h
index 4f68cb4..eea11a7 100644
--- a/include/llvm/AttributesImpl.h
+++ b/include/llvm/AttributesImpl.h
@@ -25,7 +25,6 @@
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 @@
bool isEmptyOrSingleton() const;
+ static uint64_t getAttrMask(uint64_t Val);
+
void Profile(FoldingSetNodeID &ID) const {
Profile(ID, Bits);
}
diff --git a/lib/AsmParser/LLParser.cpp b/lib/AsmParser/LLParser.cpp
index d813d67..76ac0f7 100644
--- a/lib/AsmParser/LLParser.cpp
+++ b/lib/AsmParser/LLParser.cpp
@@ -927,32 +927,32 @@
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_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.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_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;
diff --git a/lib/Transforms/IPO/PruneEH.cpp b/lib/Transforms/IPO/PruneEH.cpp
index 8ebf6ee..3e598ab 100644
--- a/lib/Transforms/IPO/PruneEH.cpp
+++ b/lib/Transforms/IPO/PruneEH.cpp
@@ -140,9 +140,9 @@
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();
diff --git a/lib/Transforms/Instrumentation/GCOVProfiling.cpp b/lib/Transforms/Instrumentation/GCOVProfiling.cpp
index 4c71fe3..66d8570 100644
--- a/lib/Transforms/Instrumentation/GCOVProfiling.cpp
+++ b/lib/Transforms/Instrumentation/GCOVProfiling.cpp
@@ -683,7 +683,7 @@
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 @@
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);
diff --git a/lib/Transforms/Scalar/ObjCARC.cpp b/lib/Transforms/Scalar/ObjCARC.cpp
index dca6a72..629f9d2 100644
--- a/lib/Transforms/Scalar/ObjCARC.cpp
+++ b/lib/Transforms/Scalar/ObjCARC.cpp
@@ -1789,7 +1789,7 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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,
diff --git a/lib/VMCore/Attributes.cpp b/lib/VMCore/Attributes.cpp
index 4024410..6e68973 100644
--- a/lib/VMCore/Attributes.cpp
+++ b/lib/VMCore/Attributes.cpp
@@ -65,14 +65,14 @@
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 @@
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 @@
// 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 @@
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 @@
// 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;