[rs4gc] Use loops instead of straightline code for attribute stripping [nfc]

Mostly because I'm about to add more attributes and the straightline copies get much uglier.  What's currently there isn't too bad.
This commit is contained in:
Philip Reames 2021-04-02 09:23:50 -07:00
parent 3f8c6f493b
commit 2c4548e18e
1 changed files with 9 additions and 10 deletions

View File

@ -1346,10 +1346,10 @@ static AttributeList legalizeCallAttributes(LLVMContext &Ctx,
// Remove the readonly, readnone, and statepoint function attributes. // Remove the readonly, readnone, and statepoint function attributes.
AttrBuilder FnAttrs = AL.getFnAttributes(); AttrBuilder FnAttrs = AL.getFnAttributes();
FnAttrs.removeAttribute(Attribute::ReadNone); for (auto Attr : {Attribute::ReadNone, Attribute::ReadOnly,
FnAttrs.removeAttribute(Attribute::ReadOnly); Attribute::NoSync, Attribute::NoFree})
FnAttrs.removeAttribute(Attribute::NoSync); FnAttrs.removeAttribute(Attr);
FnAttrs.removeAttribute(Attribute::NoFree);
for (Attribute A : AL.getFnAttributes()) { for (Attribute A : AL.getFnAttributes()) {
if (isStatepointDirectiveAttr(A)) if (isStatepointDirectiveAttr(A))
FnAttrs.remove(A); FnAttrs.remove(A);
@ -2587,10 +2587,9 @@ static void RemoveNonValidAttrAtIndex(LLVMContext &Ctx, AttrHolder &AH,
if (AH.getDereferenceableOrNullBytes(Index)) if (AH.getDereferenceableOrNullBytes(Index))
R.addAttribute(Attribute::get(Ctx, Attribute::DereferenceableOrNull, R.addAttribute(Attribute::get(Ctx, Attribute::DereferenceableOrNull,
AH.getDereferenceableOrNullBytes(Index))); AH.getDereferenceableOrNullBytes(Index)));
if (AH.getAttributes().hasAttribute(Index, Attribute::NoAlias)) for (auto Attr : {Attribute::NoAlias, Attribute::NoFree})
R.addAttribute(Attribute::NoAlias); if (AH.getAttributes().hasAttribute(Index, Attr))
if (AH.getAttributes().hasAttribute(Index, Attribute::NoFree)) R.addAttribute(Attr);
R.addAttribute(Attribute::NoFree);
if (!R.empty()) if (!R.empty())
AH.setAttributes(AH.getAttributes().removeAttributes(Ctx, Index, R)); AH.setAttributes(AH.getAttributes().removeAttributes(Ctx, Index, R));
@ -2607,8 +2606,8 @@ static void stripNonValidAttributesFromPrototype(Function &F) {
if (isa<PointerType>(F.getReturnType())) if (isa<PointerType>(F.getReturnType()))
RemoveNonValidAttrAtIndex(Ctx, F, AttributeList::ReturnIndex); RemoveNonValidAttrAtIndex(Ctx, F, AttributeList::ReturnIndex);
F.removeFnAttr(Attribute::NoSync); for (auto Attr : {Attribute::NoSync, Attribute::NoFree})
F.removeFnAttr(Attribute::NoFree); F.removeFnAttr(Attr);
} }
/// Certain metadata on instructions are invalid after running RS4GC. /// Certain metadata on instructions are invalid after running RS4GC.