diff --git a/llvm/include/llvm/IR/Attributes.h b/llvm/include/llvm/IR/Attributes.h --- a/llvm/include/llvm/IR/Attributes.h +++ b/llvm/include/llvm/IR/Attributes.h @@ -108,7 +108,12 @@ //===--------------------------------------------------------------------===// /// Return a uniquified Attribute object. - static Attribute get(LLVMContext &Context, AttrKind Kind, uint64_t Val = 0); + /// Val has a default value of zero which implies the AttrKind is enum. + /// If ConsiderZeroValueForIntAttr is true, then Val (even if zero) is + /// considered as the value for the attribute, which should be an Int + /// attribute. + static Attribute get(LLVMContext &Context, AttrKind Kind, + uint64_t Val = 0, bool ConsiderZeroValueForIntAttr = false); static Attribute get(LLVMContext &Context, StringRef Kind, StringRef Val = StringRef()); static Attribute get(LLVMContext &Context, AttrKind Kind, Type *Ty); diff --git a/llvm/lib/IR/Attributes.cpp b/llvm/lib/IR/Attributes.cpp --- a/llvm/lib/IR/Attributes.cpp +++ b/llvm/lib/IR/Attributes.cpp @@ -89,8 +89,9 @@ } Attribute Attribute::get(LLVMContext &Context, Attribute::AttrKind Kind, - uint64_t Val) { - if (Val) + uint64_t Val, bool ConsiderZeroValueForIntAttr) { + const bool isIntAttr = Val || ConsiderZeroValueForIntAttr; + if (isIntAttr) assert(Attribute::isIntAttrKind(Kind) && "Not an int attribute"); else assert(Attribute::isEnumAttrKind(Kind) && "Not an enum attribute"); @@ -98,7 +99,7 @@ LLVMContextImpl *pImpl = Context.pImpl; FoldingSetNodeID ID; ID.AddInteger(Kind); - if (Val) ID.AddInteger(Val); + if (isIntAttr) ID.AddInteger(Val); void *InsertPoint; AttributeImpl *PA = pImpl->AttrsSet.FindNodeOrInsertPos(ID, InsertPoint); @@ -106,7 +107,7 @@ if (!PA) { // If we didn't find any existing attributes of the same shape then create a // new one and insert it. - if (!Val) + if (!isIntAttr) PA = new (pImpl->Alloc) EnumAttributeImpl(Kind); else PA = new (pImpl->Alloc) IntAttributeImpl(Kind, Val);