diff options
author | serge-sans-paille <sguelton@redhat.com> | 2022-01-04 09:44:47 +0100 |
---|---|---|
committer | serge-sans-paille <sguelton@redhat.com> | 2022-01-04 15:37:46 +0100 |
commit | 9290ccc3c1a17a7874de020656db38183a20f6b0 (patch) | |
tree | 9c9a10a0fa164c01b7a109a9db5cb8a1014adaf2 /llvm/lib/IR/Attributes.cpp | |
parent | 2b1c38f737d490c09efc60e2c3e17b8568173097 (diff) | |
download | llvm-9290ccc3c1a17a7874de020656db38183a20f6b0.zip llvm-9290ccc3c1a17a7874de020656db38183a20f6b0.tar.gz llvm-9290ccc3c1a17a7874de020656db38183a20f6b0.tar.bz2 |
Introduce the AttributeMask class
This class is solely used as a lightweight and clean way to build a set of
attributes to be removed from an AttrBuilder. Previously AttrBuilder was used
both for building and removing, which introduced odd situation like creation of
Attribute with dummy value because the only relevant part was the attribute
kind.
Differential Revision: https://reviews.llvm.org/D116110
Diffstat (limited to 'llvm/lib/IR/Attributes.cpp')
-rw-r--r-- | llvm/lib/IR/Attributes.cpp | 72 |
1 files changed, 35 insertions, 37 deletions
diff --git a/llvm/lib/IR/Attributes.cpp b/llvm/lib/IR/Attributes.cpp index 2c917e4..c1b63c0 100644 --- a/llvm/lib/IR/Attributes.cpp +++ b/llvm/lib/IR/Attributes.cpp @@ -651,7 +651,7 @@ AttributeSet AttributeSet::removeAttribute(LLVMContext &C, } AttributeSet AttributeSet::removeAttributes(LLVMContext &C, - const AttrBuilder &Attrs) const { + const AttributeMask &Attrs) const { AttrBuilder B(*this); // If there is nothing to remove, directly return the original set. if (!B.overlaps(Attrs)) @@ -1314,9 +1314,8 @@ AttributeList AttributeList::removeAttributeAtIndex(LLVMContext &C, return getImpl(C, AttrSets); } -AttributeList -AttributeList::removeAttributesAtIndex(LLVMContext &C, unsigned Index, - const AttrBuilder &AttrsToRemove) const { +AttributeList AttributeList::removeAttributesAtIndex( + LLVMContext &C, unsigned Index, const AttributeMask &AttrsToRemove) const { AttributeSet Attrs = getAttributes(Index); AttributeSet NewAttrs = Attrs.removeAttributes(C, AttrsToRemove); // If nothing was removed, return the original list. @@ -1604,6 +1603,11 @@ AttrBuilder &AttrBuilder::addAttribute(StringRef A, StringRef V) { return *this; } +AttrBuilder &AttrBuilder::removeAttributes(AttributeList AL, uint64_t Index) { + remove(AttributeMask(AL.getAttributes(Index))); + return *this; +} + AttrBuilder &AttrBuilder::removeAttribute(Attribute::AttrKind Val) { assert((unsigned)Val < Attribute::EndAttrKinds && "Attribute out of range!"); Attrs[Val] = false; @@ -1616,11 +1620,6 @@ AttrBuilder &AttrBuilder::removeAttribute(Attribute::AttrKind Val) { return *this; } -AttrBuilder &AttrBuilder::removeAttributes(AttributeList A, uint64_t Index) { - remove(A.getAttributes(Index)); - return *this; -} - AttrBuilder &AttrBuilder::removeAttribute(StringRef A) { TargetDepAttrs.erase(A); return *this; @@ -1760,34 +1759,33 @@ AttrBuilder &AttrBuilder::merge(const AttrBuilder &B) { return *this; } -AttrBuilder &AttrBuilder::remove(const AttrBuilder &B) { +AttrBuilder &AttrBuilder::remove(const AttributeMask &AM) { // FIXME: What if both have an int/type attribute, but they don't match?! for (unsigned Index = 0; Index < Attribute::NumIntAttrKinds; ++Index) - if (B.IntAttrs[Index]) + if (AM.contains((Attribute::AttrKind)Index)) IntAttrs[Index] = 0; for (unsigned Index = 0; Index < Attribute::NumTypeAttrKinds; ++Index) - if (B.TypeAttrs[Index]) + if (AM.contains((Attribute::AttrKind)Index)) TypeAttrs[Index] = nullptr; - Attrs &= ~B.Attrs; + Attrs &= ~AM.attrs(); - for (const auto &I : B.td_attrs()) - TargetDepAttrs.erase(I.first); + for (const auto &I : AM.td_attrs()) + TargetDepAttrs.erase(I); return *this; } -bool AttrBuilder::overlaps(const AttrBuilder &B) const { +bool AttrBuilder::overlaps(const AttributeMask &AM) const { // First check if any of the target independent attributes overlap. - if ((Attrs & B.Attrs).any()) + if ((Attrs & AM.attrs()).any()) return true; // Then check if any target dependent ones do. for (const auto &I : td_attrs()) - if (B.contains(I.first)) + if (AM.contains(I.first)) return true; - return false; } @@ -1835,8 +1833,8 @@ bool AttrBuilder::operator==(const AttrBuilder &B) const { //===----------------------------------------------------------------------===// /// Which attributes cannot be applied to a type. -AttrBuilder AttributeFuncs::typeIncompatible(Type *Ty) { - AttrBuilder Incompatible; +AttributeMask AttributeFuncs::typeIncompatible(Type *Ty) { + AttributeMask Incompatible; if (!Ty->isIntegerTy()) // Attributes that only apply to integers. @@ -1852,18 +1850,18 @@ AttrBuilder AttributeFuncs::typeIncompatible(Type *Ty) { .addAttribute(Attribute::ReadNone) .addAttribute(Attribute::ReadOnly) .addAttribute(Attribute::SwiftError) - .addDereferenceableAttr(1) // the int here is ignored - .addDereferenceableOrNullAttr(1) // the int here is ignored - .addPreallocatedAttr(Ty) - .addInAllocaAttr(Ty) - .addByValAttr(Ty) - .addStructRetAttr(Ty) - .addByRefAttr(Ty) - .addTypeAttr(Attribute::ElementType, Ty); + .addAttribute(Attribute::Dereferenceable) + .addAttribute(Attribute::DereferenceableOrNull) + .addAttribute(Attribute::Preallocated) + .addAttribute(Attribute::InAlloca) + .addAttribute(Attribute::ByVal) + .addAttribute(Attribute::StructRet) + .addAttribute(Attribute::ByRef) + .addAttribute(Attribute::ElementType); if (!Ty->isPtrOrPtrVectorTy()) // Attributes that only apply to pointers or vectors of pointers. - Incompatible.addAlignmentAttr(1); // the int here is ignored + Incompatible.addAttribute(Attribute::Alignment); // Some attributes can apply to all "values" but there are no `void` values. if (Ty->isVoidTy()) @@ -1872,12 +1870,12 @@ AttrBuilder AttributeFuncs::typeIncompatible(Type *Ty) { return Incompatible; } -AttrBuilder AttributeFuncs::getUBImplyingAttributes() { - AttrBuilder B; - B.addAttribute(Attribute::NoUndef); - B.addDereferenceableAttr(1); - B.addDereferenceableOrNullAttr(1); - return B; +AttributeMask AttributeFuncs::getUBImplyingAttributes() { + AttributeMask AM; + AM.addAttribute(Attribute::NoUndef); + AM.addAttribute(Attribute::Dereferenceable); + AM.addAttribute(Attribute::DereferenceableOrNull); + return AM; } template<typename AttrClass> @@ -1916,7 +1914,7 @@ static void adjustCallerSSPLevel(Function &Caller, const Function &Callee) { // If upgrading the SSP attribute, clear out the old SSP Attributes first. // Having multiple SSP attributes doesn't actually hurt, but it adds useless // clutter to the IR. - AttrBuilder OldSSPAttr; + AttributeMask OldSSPAttr; OldSSPAttr.addAttribute(Attribute::StackProtect) .addAttribute(Attribute::StackProtectStrong) .addAttribute(Attribute::StackProtectReq); |