Attribute::InaccessibleMemOrArgMemOnly,
Attribute::NoSync, Attribute::NoFree};
-// List of all parameter and return attributes which must be stripped when
-// lowering from the abstract machine model. Note that we list attributes
-// here which aren't valid as return attributes, that is okay. There are
-// also some additional attributes with arguments which are handled
-// explicitly and are not in this list.
-static constexpr Attribute::AttrKind ParamAttrsToStrip[] =
- {Attribute::ReadNone, Attribute::ReadOnly, Attribute::WriteOnly,
- Attribute::NoAlias, Attribute::NoFree};
-
-
// Create new attribute set containing only attributes which can be transferred
// from original call to the safepoint.
static AttributeList legalizeCallAttributes(LLVMContext &Ctx,
return !Records.empty();
}
-// Handles both return values and arguments for Functions and calls.
-template <typename AttrHolder>
-static void RemoveNonValidAttrAtIndex(LLVMContext &Ctx, AttrHolder &AH,
- unsigned Index) {
+// List of all parameter and return attributes which must be stripped when
+// lowering from the abstract machine model. Note that we list attributes
+// here which aren't valid as return attributes, that is okay.
+static AttrBuilder getParamAndReturnAttributesToRemove() {
AttrBuilder R;
- AttributeSet AS = AH.getAttributes().getAttributes(Index);
- if (AS.getDereferenceableBytes())
- R.addAttribute(Attribute::get(Ctx, Attribute::Dereferenceable,
- AS.getDereferenceableBytes()));
- if (AS.getDereferenceableOrNullBytes())
- R.addAttribute(Attribute::get(Ctx, Attribute::DereferenceableOrNull,
- AS.getDereferenceableOrNullBytes()));
- for (auto Attr : ParamAttrsToStrip)
- if (AS.hasAttribute(Attr))
- R.addAttribute(Attr);
-
- if (!R.empty())
- AH.setAttributes(AH.getAttributes().removeAttributesAtIndex(Ctx, Index, R));
+ R.addDereferenceableAttr(1);
+ R.addDereferenceableOrNullAttr(1);
+ R.addAttribute(Attribute::ReadNone);
+ R.addAttribute(Attribute::ReadOnly);
+ R.addAttribute(Attribute::WriteOnly);
+ R.addAttribute(Attribute::NoAlias);
+ R.addAttribute(Attribute::NoFree);
+ return R;
}
static void stripNonValidAttributesFromPrototype(Function &F) {
return;
}
+ AttrBuilder R = getParamAndReturnAttributesToRemove();
for (Argument &A : F.args())
if (isa<PointerType>(A.getType()))
- RemoveNonValidAttrAtIndex(Ctx, F,
- A.getArgNo() + AttributeList::FirstArgIndex);
+ F.removeParamAttrs(A.getArgNo(), R);
if (isa<PointerType>(F.getReturnType()))
- RemoveNonValidAttrAtIndex(Ctx, F, AttributeList::ReturnIndex);
+ F.removeRetAttrs(R);
for (auto Attr : FnAttrsToStrip)
F.removeFnAttr(Attr);
stripInvalidMetadataFromInstruction(I);
+ AttrBuilder R = getParamAndReturnAttributesToRemove();
if (auto *Call = dyn_cast<CallBase>(&I)) {
for (int i = 0, e = Call->arg_size(); i != e; i++)
if (isa<PointerType>(Call->getArgOperand(i)->getType()))
- RemoveNonValidAttrAtIndex(Ctx, *Call,
- i + AttributeList::FirstArgIndex);
+ Call->removeParamAttrs(i, R);
if (isa<PointerType>(Call->getType()))
- RemoveNonValidAttrAtIndex(Ctx, *Call, AttributeList::ReturnIndex);
+ Call->removeRetAttrs(R);
}
}