Skip to content

Commit 52e6d70

Browse files
committed
[NFC] Use newly introduced *AtIndex methods
Introduced in D108788. These are clearer.
1 parent 12de296 commit 52e6d70

File tree

8 files changed

+42
-36
lines changed

8 files changed

+42
-36
lines changed

llvm/include/llvm/Transforms/IPO/Attributor.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ struct IRPosition {
591591

592592
LLVMContext &Ctx = getAnchorValue().getContext();
593593
for (Attribute::AttrKind AK : AKs)
594-
AttrList = AttrList.removeAttribute(Ctx, getAttrIdx(), AK);
594+
AttrList = AttrList.removeAttributeAtIndex(Ctx, getAttrIdx(), AK);
595595

596596
if (CB)
597597
CB->setAttributes(AttrList);

llvm/lib/CodeGen/GlobalISel/CallLowering.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ void CallLowering::addArgFlagsFromAttributes(ISD::ArgFlagsTy &Flags,
7373
const AttributeList &Attrs,
7474
unsigned OpIdx) const {
7575
addFlagsUsingAttrFn(Flags, [&Attrs, &OpIdx](Attribute::AttrKind Attr) {
76-
return Attrs.hasAttribute(OpIdx, Attr);
76+
return Attrs.hasAttributeAtIndex(OpIdx, Attr);
7777
});
7878
}
7979

@@ -168,7 +168,8 @@ void CallLowering::setArgFlags(CallLowering::ArgInfo &Arg, unsigned OpIdx,
168168
assert(OpIdx >= AttributeList::FirstArgIndex);
169169
Type *ElementTy = PtrTy->getElementType();
170170

171-
auto Ty = Attrs.getAttribute(OpIdx, Attribute::ByVal).getValueAsType();
171+
auto Ty =
172+
Attrs.getAttributeAtIndex(OpIdx, Attribute::ByVal).getValueAsType();
172173
Flags.setByValSize(DL.getTypeAllocSize(Ty ? Ty : ElementTy));
173174

174175
// For ByVal, alignment should be passed from FE. BE will guess if

llvm/lib/IR/Core.cpp

+15-13
Original file line numberDiff line numberDiff line change
@@ -2460,7 +2460,7 @@ void LLVMSetGC(LLVMValueRef Fn, const char *GC) {
24602460

24612461
void LLVMAddAttributeAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx,
24622462
LLVMAttributeRef A) {
2463-
unwrap<Function>(F)->addAttribute(Idx, unwrap(A));
2463+
unwrap<Function>(F)->addAttributeAtIndex(Idx, unwrap(A));
24642464
}
24652465

24662466
unsigned LLVMGetAttributeCountAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx) {
@@ -2478,24 +2478,25 @@ void LLVMGetAttributesAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx,
24782478
LLVMAttributeRef LLVMGetEnumAttributeAtIndex(LLVMValueRef F,
24792479
LLVMAttributeIndex Idx,
24802480
unsigned KindID) {
2481-
return wrap(unwrap<Function>(F)->getAttribute(Idx,
2482-
(Attribute::AttrKind)KindID));
2481+
return wrap(unwrap<Function>(F)->getAttributeAtIndex(
2482+
Idx, (Attribute::AttrKind)KindID));
24832483
}
24842484

24852485
LLVMAttributeRef LLVMGetStringAttributeAtIndex(LLVMValueRef F,
24862486
LLVMAttributeIndex Idx,
24872487
const char *K, unsigned KLen) {
2488-
return wrap(unwrap<Function>(F)->getAttribute(Idx, StringRef(K, KLen)));
2488+
return wrap(
2489+
unwrap<Function>(F)->getAttributeAtIndex(Idx, StringRef(K, KLen)));
24892490
}
24902491

24912492
void LLVMRemoveEnumAttributeAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx,
24922493
unsigned KindID) {
2493-
unwrap<Function>(F)->removeAttribute(Idx, (Attribute::AttrKind)KindID);
2494+
unwrap<Function>(F)->removeAttributeAtIndex(Idx, (Attribute::AttrKind)KindID);
24942495
}
24952496

24962497
void LLVMRemoveStringAttributeAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx,
24972498
const char *K, unsigned KLen) {
2498-
unwrap<Function>(F)->removeAttribute(Idx, StringRef(K, KLen));
2499+
unwrap<Function>(F)->removeAttributeAtIndex(Idx, StringRef(K, KLen));
24992500
}
25002501

25012502
void LLVMAddTargetDependentFunctionAttr(LLVMValueRef Fn, const char *A,
@@ -2862,12 +2863,12 @@ void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index,
28622863
auto *Call = unwrap<CallBase>(Instr);
28632864
Attribute AlignAttr =
28642865
Attribute::getWithAlignment(Call->getContext(), Align(align));
2865-
Call->addAttribute(index, AlignAttr);
2866+
Call->addAttributeAtIndex(index, AlignAttr);
28662867
}
28672868

28682869
void LLVMAddCallSiteAttribute(LLVMValueRef C, LLVMAttributeIndex Idx,
28692870
LLVMAttributeRef A) {
2870-
unwrap<CallBase>(C)->addAttribute(Idx, unwrap(A));
2871+
unwrap<CallBase>(C)->addAttributeAtIndex(Idx, unwrap(A));
28712872
}
28722873

28732874
unsigned LLVMGetCallSiteAttributeCount(LLVMValueRef C,
@@ -2888,24 +2889,25 @@ void LLVMGetCallSiteAttributes(LLVMValueRef C, LLVMAttributeIndex Idx,
28882889
LLVMAttributeRef LLVMGetCallSiteEnumAttribute(LLVMValueRef C,
28892890
LLVMAttributeIndex Idx,
28902891
unsigned KindID) {
2891-
return wrap(
2892-
unwrap<CallBase>(C)->getAttribute(Idx, (Attribute::AttrKind)KindID));
2892+
return wrap(unwrap<CallBase>(C)->getAttributeAtIndex(
2893+
Idx, (Attribute::AttrKind)KindID));
28932894
}
28942895

28952896
LLVMAttributeRef LLVMGetCallSiteStringAttribute(LLVMValueRef C,
28962897
LLVMAttributeIndex Idx,
28972898
const char *K, unsigned KLen) {
2898-
return wrap(unwrap<CallBase>(C)->getAttribute(Idx, StringRef(K, KLen)));
2899+
return wrap(
2900+
unwrap<CallBase>(C)->getAttributeAtIndex(Idx, StringRef(K, KLen)));
28992901
}
29002902

29012903
void LLVMRemoveCallSiteEnumAttribute(LLVMValueRef C, LLVMAttributeIndex Idx,
29022904
unsigned KindID) {
2903-
unwrap<CallBase>(C)->removeAttribute(Idx, (Attribute::AttrKind)KindID);
2905+
unwrap<CallBase>(C)->removeAttributeAtIndex(Idx, (Attribute::AttrKind)KindID);
29042906
}
29052907

29062908
void LLVMRemoveCallSiteStringAttribute(LLVMValueRef C, LLVMAttributeIndex Idx,
29072909
const char *K, unsigned KLen) {
2908-
unwrap<CallBase>(C)->removeAttribute(Idx, StringRef(K, KLen));
2910+
unwrap<CallBase>(C)->removeAttributeAtIndex(Idx, StringRef(K, KLen));
29092911
}
29102912

29112913
LLVMValueRef LLVMGetCalledValue(LLVMValueRef Instr) {

llvm/lib/Linker/IRMover.cpp

+5-3
Original file line numberDiff line numberDiff line change
@@ -652,9 +652,11 @@ AttributeList IRLinker::mapAttributeTypes(LLVMContext &C, AttributeList Attrs) {
652652
for (Attribute::AttrKind TypedAttr :
653653
{Attribute::ByVal, Attribute::StructRet, Attribute::ByRef,
654654
Attribute::InAlloca}) {
655-
if (Attrs.hasAttribute(i, TypedAttr)) {
656-
if (Type *Ty = Attrs.getAttribute(i, TypedAttr).getValueAsType()) {
657-
Attrs = Attrs.replaceAttributeType(C, i, TypedAttr, TypeMap.get(Ty));
655+
if (Attrs.hasAttributeAtIndex(i, TypedAttr)) {
656+
if (Type *Ty =
657+
Attrs.getAttributeAtIndex(i, TypedAttr).getValueAsType()) {
658+
Attrs = Attrs.replaceAttributeTypeAtIndex(C, i, TypedAttr,
659+
TypeMap.get(Ty));
658660
break;
659661
}
660662
}

llvm/lib/Transforms/IPO/Attributor.cpp

+12-12
Original file line numberDiff line numberDiff line change
@@ -382,30 +382,30 @@ static bool addIfNotExistent(LLVMContext &Ctx, const Attribute &Attr,
382382

383383
if (Attr.isEnumAttribute()) {
384384
Attribute::AttrKind Kind = Attr.getKindAsEnum();
385-
if (Attrs.hasAttribute(AttrIdx, Kind))
385+
if (Attrs.hasAttributeAtIndex(AttrIdx, Kind))
386386
if (!ForceReplace &&
387-
isEqualOrWorse(Attr, Attrs.getAttribute(AttrIdx, Kind)))
387+
isEqualOrWorse(Attr, Attrs.getAttributeAtIndex(AttrIdx, Kind)))
388388
return false;
389-
Attrs = Attrs.addAttribute(Ctx, AttrIdx, Attr);
389+
Attrs = Attrs.addAttributeAtIndex(Ctx, AttrIdx, Attr);
390390
return true;
391391
}
392392
if (Attr.isStringAttribute()) {
393393
StringRef Kind = Attr.getKindAsString();
394-
if (Attrs.hasAttribute(AttrIdx, Kind))
394+
if (Attrs.hasAttributeAtIndex(AttrIdx, Kind))
395395
if (!ForceReplace &&
396-
isEqualOrWorse(Attr, Attrs.getAttribute(AttrIdx, Kind)))
396+
isEqualOrWorse(Attr, Attrs.getAttributeAtIndex(AttrIdx, Kind)))
397397
return false;
398-
Attrs = Attrs.addAttribute(Ctx, AttrIdx, Attr);
398+
Attrs = Attrs.addAttributeAtIndex(Ctx, AttrIdx, Attr);
399399
return true;
400400
}
401401
if (Attr.isIntAttribute()) {
402402
Attribute::AttrKind Kind = Attr.getKindAsEnum();
403-
if (Attrs.hasAttribute(AttrIdx, Kind))
403+
if (Attrs.hasAttributeAtIndex(AttrIdx, Kind))
404404
if (!ForceReplace &&
405-
isEqualOrWorse(Attr, Attrs.getAttribute(AttrIdx, Kind)))
405+
isEqualOrWorse(Attr, Attrs.getAttributeAtIndex(AttrIdx, Kind)))
406406
return false;
407-
Attrs = Attrs.removeAttribute(Ctx, AttrIdx, Kind);
408-
Attrs = Attrs.addAttribute(Ctx, AttrIdx, Attr);
407+
Attrs = Attrs.removeAttributeAtIndex(Ctx, AttrIdx, Kind);
408+
Attrs = Attrs.addAttributeAtIndex(Ctx, AttrIdx, Attr);
409409
return true;
410410
}
411411

@@ -658,9 +658,9 @@ bool IRPosition::getAttrsFromIRAttr(Attribute::AttrKind AK,
658658
else
659659
AttrList = getAssociatedFunction()->getAttributes();
660660

661-
bool HasAttr = AttrList.hasAttribute(getAttrIdx(), AK);
661+
bool HasAttr = AttrList.hasAttributeAtIndex(getAttrIdx(), AK);
662662
if (HasAttr)
663-
Attrs.push_back(AttrList.getAttribute(getAttrIdx(), AK));
663+
Attrs.push_back(AttrList.getAttributeAtIndex(getAttrIdx(), AK));
664664
return HasAttr;
665665
}
666666

llvm/lib/Transforms/IPO/GlobalOpt.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1705,7 +1705,7 @@ static AttributeList StripAttr(LLVMContext &C, AttributeList Attrs,
17051705
Attribute::AttrKind A) {
17061706
unsigned AttrIndex;
17071707
if (Attrs.hasAttrSomewhere(A, &AttrIndex))
1708-
return Attrs.removeAttribute(C, AttrIndex, A);
1708+
return Attrs.removeAttributeAtIndex(C, AttrIndex, A);
17091709
return Attrs;
17101710
}
17111711

llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -2667,7 +2667,7 @@ static void RemoveNonValidAttrAtIndex(LLVMContext &Ctx, AttrHolder &AH,
26672667
R.addAttribute(Attr);
26682668

26692669
if (!R.empty())
2670-
AH.setAttributes(AH.getAttributes().removeAttributes(Ctx, Index, R));
2670+
AH.setAttributes(AH.getAttributes().removeAttributesAtIndex(Ctx, Index, R));
26712671
}
26722672

26732673
static void stripNonValidAttributesFromPrototype(Function &F) {

llvm/lib/Transforms/Utils/ValueMapper.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -947,9 +947,10 @@ void Mapper::remapInstruction(Instruction *I) {
947947
for (Attribute::AttrKind TypedAttr :
948948
{Attribute::ByVal, Attribute::StructRet, Attribute::ByRef,
949949
Attribute::InAlloca}) {
950-
if (Type *Ty = Attrs.getAttribute(i, TypedAttr).getValueAsType()) {
951-
Attrs = Attrs.replaceAttributeType(C, i, TypedAttr,
952-
TypeMapper->remapType(Ty));
950+
if (Type *Ty =
951+
Attrs.getAttributeAtIndex(i, TypedAttr).getValueAsType()) {
952+
Attrs = Attrs.replaceAttributeTypeAtIndex(C, i, TypedAttr,
953+
TypeMapper->remapType(Ty));
953954
break;
954955
}
955956
}

0 commit comments

Comments
 (0)