[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();
for (Attribute::AttrKind AK : AKs)
AttrList = AttrList.removeAttribute(Ctx, getAttrIdx(), AK);
AttrList = AttrList.removeAttributeAtIndex(Ctx, getAttrIdx(), AK);
if (CB)
CB->setAttributes(AttrList);

View File

@ -73,7 +73,7 @@ void CallLowering::addArgFlagsFromAttributes(ISD::ArgFlagsTy &Flags,
const AttributeList &Attrs,
unsigned OpIdx) const {
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);
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));
// 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,
LLVMAttributeRef A) {
unwrap<Function>(F)->addAttribute(Idx, unwrap(A));
unwrap<Function>(F)->addAttributeAtIndex(Idx, unwrap(A));
}
unsigned LLVMGetAttributeCountAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx) {
@ -2478,24 +2478,25 @@ void LLVMGetAttributesAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx,
LLVMAttributeRef LLVMGetEnumAttributeAtIndex(LLVMValueRef F,
LLVMAttributeIndex Idx,
unsigned KindID) {
return wrap(unwrap<Function>(F)->getAttribute(Idx,
(Attribute::AttrKind)KindID));
return wrap(unwrap<Function>(F)->getAttributeAtIndex(
Idx, (Attribute::AttrKind)KindID));
}
LLVMAttributeRef LLVMGetStringAttributeAtIndex(LLVMValueRef F,
LLVMAttributeIndex Idx,
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,
unsigned KindID) {
unwrap<Function>(F)->removeAttribute(Idx, (Attribute::AttrKind)KindID);
unwrap<Function>(F)->removeAttributeAtIndex(Idx, (Attribute::AttrKind)KindID);
}
void LLVMRemoveStringAttributeAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx,
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,
@ -2862,12 +2863,12 @@ void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index,
auto *Call = unwrap<CallBase>(Instr);
Attribute AlignAttr =
Attribute::getWithAlignment(Call->getContext(), Align(align));
Call->addAttribute(index, AlignAttr);
Call->addAttributeAtIndex(index, AlignAttr);
}
void LLVMAddCallSiteAttribute(LLVMValueRef C, LLVMAttributeIndex Idx,
LLVMAttributeRef A) {
unwrap<CallBase>(C)->addAttribute(Idx, unwrap(A));
unwrap<CallBase>(C)->addAttributeAtIndex(Idx, unwrap(A));
}
unsigned LLVMGetCallSiteAttributeCount(LLVMValueRef C,
@ -2888,24 +2889,25 @@ void LLVMGetCallSiteAttributes(LLVMValueRef C, LLVMAttributeIndex Idx,
LLVMAttributeRef LLVMGetCallSiteEnumAttribute(LLVMValueRef C,
LLVMAttributeIndex Idx,
unsigned KindID) {
return wrap(
unwrap<CallBase>(C)->getAttribute(Idx, (Attribute::AttrKind)KindID));
return wrap(unwrap<CallBase>(C)->getAttributeAtIndex(
Idx, (Attribute::AttrKind)KindID));
}
LLVMAttributeRef LLVMGetCallSiteStringAttribute(LLVMValueRef C,
LLVMAttributeIndex Idx,
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,
unsigned KindID) {
unwrap<CallBase>(C)->removeAttribute(Idx, (Attribute::AttrKind)KindID);
unwrap<CallBase>(C)->removeAttributeAtIndex(Idx, (Attribute::AttrKind)KindID);
}
void LLVMRemoveCallSiteStringAttribute(LLVMValueRef C, LLVMAttributeIndex Idx,
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) {

View File

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

View File

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

View File

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

View File

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

View File

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