[NFC] Use newly introduced *AtIndex methods

Introduced in D108788. These are clearer.
This commit is contained in:
Arthur Eubanks 2021-08-20 10:49:36 -07:00
parent 12de296d84
commit 52e6d70c40
8 changed files with 42 additions and 36 deletions

View File

@ -591,7 +591,7 @@ struct IRPosition {
LLVMContext &Ctx = getAnchorValue().getContext(); LLVMContext &Ctx = getAnchorValue().getContext();
for (Attribute::AttrKind AK : AKs) for (Attribute::AttrKind AK : AKs)
AttrList = AttrList.removeAttribute(Ctx, getAttrIdx(), AK); AttrList = AttrList.removeAttributeAtIndex(Ctx, getAttrIdx(), AK);
if (CB) if (CB)
CB->setAttributes(AttrList); CB->setAttributes(AttrList);

View File

@ -73,7 +73,7 @@ void CallLowering::addArgFlagsFromAttributes(ISD::ArgFlagsTy &Flags,
const AttributeList &Attrs, const AttributeList &Attrs,
unsigned OpIdx) const { unsigned OpIdx) const {
addFlagsUsingAttrFn(Flags, [&Attrs, &OpIdx](Attribute::AttrKind Attr) { addFlagsUsingAttrFn(Flags, [&Attrs, &OpIdx](Attribute::AttrKind Attr) {
return Attrs.hasAttribute(OpIdx, Attr); return Attrs.hasAttributeAtIndex(OpIdx, Attr);
}); });
} }
@ -168,7 +168,8 @@ void CallLowering::setArgFlags(CallLowering::ArgInfo &Arg, unsigned OpIdx,
assert(OpIdx >= AttributeList::FirstArgIndex); assert(OpIdx >= AttributeList::FirstArgIndex);
Type *ElementTy = PtrTy->getElementType(); Type *ElementTy = PtrTy->getElementType();
auto Ty = Attrs.getAttribute(OpIdx, Attribute::ByVal).getValueAsType(); auto Ty =
Attrs.getAttributeAtIndex(OpIdx, Attribute::ByVal).getValueAsType();
Flags.setByValSize(DL.getTypeAllocSize(Ty ? Ty : ElementTy)); Flags.setByValSize(DL.getTypeAllocSize(Ty ? Ty : ElementTy));
// For ByVal, alignment should be passed from FE. BE will guess if // For ByVal, alignment should be passed from FE. BE will guess if

View File

@ -2460,7 +2460,7 @@ void LLVMSetGC(LLVMValueRef Fn, const char *GC) {
void LLVMAddAttributeAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx, void LLVMAddAttributeAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx,
LLVMAttributeRef A) { LLVMAttributeRef A) {
unwrap<Function>(F)->addAttribute(Idx, unwrap(A)); unwrap<Function>(F)->addAttributeAtIndex(Idx, unwrap(A));
} }
unsigned LLVMGetAttributeCountAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx) { unsigned LLVMGetAttributeCountAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx) {
@ -2478,24 +2478,25 @@ void LLVMGetAttributesAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx,
LLVMAttributeRef LLVMGetEnumAttributeAtIndex(LLVMValueRef F, LLVMAttributeRef LLVMGetEnumAttributeAtIndex(LLVMValueRef F,
LLVMAttributeIndex Idx, LLVMAttributeIndex Idx,
unsigned KindID) { unsigned KindID) {
return wrap(unwrap<Function>(F)->getAttribute(Idx, return wrap(unwrap<Function>(F)->getAttributeAtIndex(
(Attribute::AttrKind)KindID)); Idx, (Attribute::AttrKind)KindID));
} }
LLVMAttributeRef LLVMGetStringAttributeAtIndex(LLVMValueRef F, LLVMAttributeRef LLVMGetStringAttributeAtIndex(LLVMValueRef F,
LLVMAttributeIndex Idx, LLVMAttributeIndex Idx,
const char *K, unsigned KLen) { const char *K, unsigned KLen) {
return wrap(unwrap<Function>(F)->getAttribute(Idx, StringRef(K, KLen))); return wrap(
unwrap<Function>(F)->getAttributeAtIndex(Idx, StringRef(K, KLen)));
} }
void LLVMRemoveEnumAttributeAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx, void LLVMRemoveEnumAttributeAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx,
unsigned KindID) { unsigned KindID) {
unwrap<Function>(F)->removeAttribute(Idx, (Attribute::AttrKind)KindID); unwrap<Function>(F)->removeAttributeAtIndex(Idx, (Attribute::AttrKind)KindID);
} }
void LLVMRemoveStringAttributeAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx, void LLVMRemoveStringAttributeAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx,
const char *K, unsigned KLen) { const char *K, unsigned KLen) {
unwrap<Function>(F)->removeAttribute(Idx, StringRef(K, KLen)); unwrap<Function>(F)->removeAttributeAtIndex(Idx, StringRef(K, KLen));
} }
void LLVMAddTargetDependentFunctionAttr(LLVMValueRef Fn, const char *A, void LLVMAddTargetDependentFunctionAttr(LLVMValueRef Fn, const char *A,
@ -2862,12 +2863,12 @@ void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index,
auto *Call = unwrap<CallBase>(Instr); auto *Call = unwrap<CallBase>(Instr);
Attribute AlignAttr = Attribute AlignAttr =
Attribute::getWithAlignment(Call->getContext(), Align(align)); Attribute::getWithAlignment(Call->getContext(), Align(align));
Call->addAttribute(index, AlignAttr); Call->addAttributeAtIndex(index, AlignAttr);
} }
void LLVMAddCallSiteAttribute(LLVMValueRef C, LLVMAttributeIndex Idx, void LLVMAddCallSiteAttribute(LLVMValueRef C, LLVMAttributeIndex Idx,
LLVMAttributeRef A) { LLVMAttributeRef A) {
unwrap<CallBase>(C)->addAttribute(Idx, unwrap(A)); unwrap<CallBase>(C)->addAttributeAtIndex(Idx, unwrap(A));
} }
unsigned LLVMGetCallSiteAttributeCount(LLVMValueRef C, unsigned LLVMGetCallSiteAttributeCount(LLVMValueRef C,
@ -2888,24 +2889,25 @@ void LLVMGetCallSiteAttributes(LLVMValueRef C, LLVMAttributeIndex Idx,
LLVMAttributeRef LLVMGetCallSiteEnumAttribute(LLVMValueRef C, LLVMAttributeRef LLVMGetCallSiteEnumAttribute(LLVMValueRef C,
LLVMAttributeIndex Idx, LLVMAttributeIndex Idx,
unsigned KindID) { unsigned KindID) {
return wrap( return wrap(unwrap<CallBase>(C)->getAttributeAtIndex(
unwrap<CallBase>(C)->getAttribute(Idx, (Attribute::AttrKind)KindID)); Idx, (Attribute::AttrKind)KindID));
} }
LLVMAttributeRef LLVMGetCallSiteStringAttribute(LLVMValueRef C, LLVMAttributeRef LLVMGetCallSiteStringAttribute(LLVMValueRef C,
LLVMAttributeIndex Idx, LLVMAttributeIndex Idx,
const char *K, unsigned KLen) { const char *K, unsigned KLen) {
return wrap(unwrap<CallBase>(C)->getAttribute(Idx, StringRef(K, KLen))); return wrap(
unwrap<CallBase>(C)->getAttributeAtIndex(Idx, StringRef(K, KLen)));
} }
void LLVMRemoveCallSiteEnumAttribute(LLVMValueRef C, LLVMAttributeIndex Idx, void LLVMRemoveCallSiteEnumAttribute(LLVMValueRef C, LLVMAttributeIndex Idx,
unsigned KindID) { unsigned KindID) {
unwrap<CallBase>(C)->removeAttribute(Idx, (Attribute::AttrKind)KindID); unwrap<CallBase>(C)->removeAttributeAtIndex(Idx, (Attribute::AttrKind)KindID);
} }
void LLVMRemoveCallSiteStringAttribute(LLVMValueRef C, LLVMAttributeIndex Idx, void LLVMRemoveCallSiteStringAttribute(LLVMValueRef C, LLVMAttributeIndex Idx,
const char *K, unsigned KLen) { const char *K, unsigned KLen) {
unwrap<CallBase>(C)->removeAttribute(Idx, StringRef(K, KLen)); unwrap<CallBase>(C)->removeAttributeAtIndex(Idx, StringRef(K, KLen));
} }
LLVMValueRef LLVMGetCalledValue(LLVMValueRef Instr) { LLVMValueRef LLVMGetCalledValue(LLVMValueRef Instr) {

View File

@ -652,9 +652,11 @@ AttributeList IRLinker::mapAttributeTypes(LLVMContext &C, AttributeList Attrs) {
for (Attribute::AttrKind TypedAttr : for (Attribute::AttrKind TypedAttr :
{Attribute::ByVal, Attribute::StructRet, Attribute::ByRef, {Attribute::ByVal, Attribute::StructRet, Attribute::ByRef,
Attribute::InAlloca}) { Attribute::InAlloca}) {
if (Attrs.hasAttribute(i, TypedAttr)) { if (Attrs.hasAttributeAtIndex(i, TypedAttr)) {
if (Type *Ty = Attrs.getAttribute(i, TypedAttr).getValueAsType()) { if (Type *Ty =
Attrs = Attrs.replaceAttributeType(C, i, TypedAttr, TypeMap.get(Ty)); Attrs.getAttributeAtIndex(i, TypedAttr).getValueAsType()) {
Attrs = Attrs.replaceAttributeTypeAtIndex(C, i, TypedAttr,
TypeMap.get(Ty));
break; break;
} }
} }

View File

@ -382,30 +382,30 @@ static bool addIfNotExistent(LLVMContext &Ctx, const Attribute &Attr,
if (Attr.isEnumAttribute()) { if (Attr.isEnumAttribute()) {
Attribute::AttrKind Kind = Attr.getKindAsEnum(); Attribute::AttrKind Kind = Attr.getKindAsEnum();
if (Attrs.hasAttribute(AttrIdx, Kind)) if (Attrs.hasAttributeAtIndex(AttrIdx, Kind))
if (!ForceReplace && if (!ForceReplace &&
isEqualOrWorse(Attr, Attrs.getAttribute(AttrIdx, Kind))) isEqualOrWorse(Attr, Attrs.getAttributeAtIndex(AttrIdx, Kind)))
return false; return false;
Attrs = Attrs.addAttribute(Ctx, AttrIdx, Attr); Attrs = Attrs.addAttributeAtIndex(Ctx, AttrIdx, Attr);
return true; return true;
} }
if (Attr.isStringAttribute()) { if (Attr.isStringAttribute()) {
StringRef Kind = Attr.getKindAsString(); StringRef Kind = Attr.getKindAsString();
if (Attrs.hasAttribute(AttrIdx, Kind)) if (Attrs.hasAttributeAtIndex(AttrIdx, Kind))
if (!ForceReplace && if (!ForceReplace &&
isEqualOrWorse(Attr, Attrs.getAttribute(AttrIdx, Kind))) isEqualOrWorse(Attr, Attrs.getAttributeAtIndex(AttrIdx, Kind)))
return false; return false;
Attrs = Attrs.addAttribute(Ctx, AttrIdx, Attr); Attrs = Attrs.addAttributeAtIndex(Ctx, AttrIdx, Attr);
return true; return true;
} }
if (Attr.isIntAttribute()) { if (Attr.isIntAttribute()) {
Attribute::AttrKind Kind = Attr.getKindAsEnum(); Attribute::AttrKind Kind = Attr.getKindAsEnum();
if (Attrs.hasAttribute(AttrIdx, Kind)) if (Attrs.hasAttributeAtIndex(AttrIdx, Kind))
if (!ForceReplace && if (!ForceReplace &&
isEqualOrWorse(Attr, Attrs.getAttribute(AttrIdx, Kind))) isEqualOrWorse(Attr, Attrs.getAttributeAtIndex(AttrIdx, Kind)))
return false; return false;
Attrs = Attrs.removeAttribute(Ctx, AttrIdx, Kind); Attrs = Attrs.removeAttributeAtIndex(Ctx, AttrIdx, Kind);
Attrs = Attrs.addAttribute(Ctx, AttrIdx, Attr); Attrs = Attrs.addAttributeAtIndex(Ctx, AttrIdx, Attr);
return true; return true;
} }
@ -658,9 +658,9 @@ bool IRPosition::getAttrsFromIRAttr(Attribute::AttrKind AK,
else else
AttrList = getAssociatedFunction()->getAttributes(); AttrList = getAssociatedFunction()->getAttributes();
bool HasAttr = AttrList.hasAttribute(getAttrIdx(), AK); bool HasAttr = AttrList.hasAttributeAtIndex(getAttrIdx(), AK);
if (HasAttr) if (HasAttr)
Attrs.push_back(AttrList.getAttribute(getAttrIdx(), AK)); Attrs.push_back(AttrList.getAttributeAtIndex(getAttrIdx(), AK));
return HasAttr; return HasAttr;
} }

View File

@ -1705,7 +1705,7 @@ static AttributeList StripAttr(LLVMContext &C, AttributeList Attrs,
Attribute::AttrKind A) { Attribute::AttrKind A) {
unsigned AttrIndex; unsigned AttrIndex;
if (Attrs.hasAttrSomewhere(A, &AttrIndex)) if (Attrs.hasAttrSomewhere(A, &AttrIndex))
return Attrs.removeAttribute(C, AttrIndex, A); return Attrs.removeAttributeAtIndex(C, AttrIndex, A);
return Attrs; return Attrs;
} }

View File

@ -2667,7 +2667,7 @@ static void RemoveNonValidAttrAtIndex(LLVMContext &Ctx, AttrHolder &AH,
R.addAttribute(Attr); R.addAttribute(Attr);
if (!R.empty()) if (!R.empty())
AH.setAttributes(AH.getAttributes().removeAttributes(Ctx, Index, R)); AH.setAttributes(AH.getAttributes().removeAttributesAtIndex(Ctx, Index, R));
} }
static void stripNonValidAttributesFromPrototype(Function &F) { static void stripNonValidAttributesFromPrototype(Function &F) {

View File

@ -947,9 +947,10 @@ void Mapper::remapInstruction(Instruction *I) {
for (Attribute::AttrKind TypedAttr : for (Attribute::AttrKind TypedAttr :
{Attribute::ByVal, Attribute::StructRet, Attribute::ByRef, {Attribute::ByVal, Attribute::StructRet, Attribute::ByRef,
Attribute::InAlloca}) { Attribute::InAlloca}) {
if (Type *Ty = Attrs.getAttribute(i, TypedAttr).getValueAsType()) { if (Type *Ty =
Attrs = Attrs.replaceAttributeType(C, i, TypedAttr, Attrs.getAttributeAtIndex(i, TypedAttr).getValueAsType()) {
TypeMapper->remapType(Ty)); Attrs = Attrs.replaceAttributeTypeAtIndex(C, i, TypedAttr,
TypeMapper->remapType(Ty));
break; break;
} }
} }