From 52e6d70c40cd57709bfe8788461db35e3a8a3a6f Mon Sep 17 00:00:00 2001 From: Arthur Eubanks Date: Fri, 20 Aug 2021 10:49:36 -0700 Subject: [PATCH] [NFC] Use newly introduced *AtIndex methods Introduced in D108788. These are clearer. --- llvm/include/llvm/Transforms/IPO/Attributor.h | 2 +- llvm/lib/CodeGen/GlobalISel/CallLowering.cpp | 5 ++-- llvm/lib/IR/Core.cpp | 28 ++++++++++++---------- llvm/lib/Linker/IRMover.cpp | 8 ++++--- llvm/lib/Transforms/IPO/Attributor.cpp | 24 +++++++++---------- llvm/lib/Transforms/IPO/GlobalOpt.cpp | 2 +- .../Transforms/Scalar/RewriteStatepointsForGC.cpp | 2 +- llvm/lib/Transforms/Utils/ValueMapper.cpp | 7 +++--- 8 files changed, 42 insertions(+), 36 deletions(-) diff --git a/llvm/include/llvm/Transforms/IPO/Attributor.h b/llvm/include/llvm/Transforms/IPO/Attributor.h index b05ab69..97458a9 100644 --- a/llvm/include/llvm/Transforms/IPO/Attributor.h +++ b/llvm/include/llvm/Transforms/IPO/Attributor.h @@ -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); diff --git a/llvm/lib/CodeGen/GlobalISel/CallLowering.cpp b/llvm/lib/CodeGen/GlobalISel/CallLowering.cpp index d3105d3..0498d7e 100644 --- a/llvm/lib/CodeGen/GlobalISel/CallLowering.cpp +++ b/llvm/lib/CodeGen/GlobalISel/CallLowering.cpp @@ -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 diff --git a/llvm/lib/IR/Core.cpp b/llvm/lib/IR/Core.cpp index f171066..c9b9cdc 100644 --- a/llvm/lib/IR/Core.cpp +++ b/llvm/lib/IR/Core.cpp @@ -2460,7 +2460,7 @@ void LLVMSetGC(LLVMValueRef Fn, const char *GC) { void LLVMAddAttributeAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx, LLVMAttributeRef A) { - unwrap(F)->addAttribute(Idx, unwrap(A)); + unwrap(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(F)->getAttribute(Idx, - (Attribute::AttrKind)KindID)); + return wrap(unwrap(F)->getAttributeAtIndex( + Idx, (Attribute::AttrKind)KindID)); } LLVMAttributeRef LLVMGetStringAttributeAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx, const char *K, unsigned KLen) { - return wrap(unwrap(F)->getAttribute(Idx, StringRef(K, KLen))); + return wrap( + unwrap(F)->getAttributeAtIndex(Idx, StringRef(K, KLen))); } void LLVMRemoveEnumAttributeAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx, unsigned KindID) { - unwrap(F)->removeAttribute(Idx, (Attribute::AttrKind)KindID); + unwrap(F)->removeAttributeAtIndex(Idx, (Attribute::AttrKind)KindID); } void LLVMRemoveStringAttributeAtIndex(LLVMValueRef F, LLVMAttributeIndex Idx, const char *K, unsigned KLen) { - unwrap(F)->removeAttribute(Idx, StringRef(K, KLen)); + unwrap(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(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(C)->addAttribute(Idx, unwrap(A)); + unwrap(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(C)->getAttribute(Idx, (Attribute::AttrKind)KindID)); + return wrap(unwrap(C)->getAttributeAtIndex( + Idx, (Attribute::AttrKind)KindID)); } LLVMAttributeRef LLVMGetCallSiteStringAttribute(LLVMValueRef C, LLVMAttributeIndex Idx, const char *K, unsigned KLen) { - return wrap(unwrap(C)->getAttribute(Idx, StringRef(K, KLen))); + return wrap( + unwrap(C)->getAttributeAtIndex(Idx, StringRef(K, KLen))); } void LLVMRemoveCallSiteEnumAttribute(LLVMValueRef C, LLVMAttributeIndex Idx, unsigned KindID) { - unwrap(C)->removeAttribute(Idx, (Attribute::AttrKind)KindID); + unwrap(C)->removeAttributeAtIndex(Idx, (Attribute::AttrKind)KindID); } void LLVMRemoveCallSiteStringAttribute(LLVMValueRef C, LLVMAttributeIndex Idx, const char *K, unsigned KLen) { - unwrap(C)->removeAttribute(Idx, StringRef(K, KLen)); + unwrap(C)->removeAttributeAtIndex(Idx, StringRef(K, KLen)); } LLVMValueRef LLVMGetCalledValue(LLVMValueRef Instr) { diff --git a/llvm/lib/Linker/IRMover.cpp b/llvm/lib/Linker/IRMover.cpp index 0e75854..316d9b6 100644 --- a/llvm/lib/Linker/IRMover.cpp +++ b/llvm/lib/Linker/IRMover.cpp @@ -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; } } diff --git a/llvm/lib/Transforms/IPO/Attributor.cpp b/llvm/lib/Transforms/IPO/Attributor.cpp index 9bbe494..34abe7d 100644 --- a/llvm/lib/Transforms/IPO/Attributor.cpp +++ b/llvm/lib/Transforms/IPO/Attributor.cpp @@ -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; } diff --git a/llvm/lib/Transforms/IPO/GlobalOpt.cpp b/llvm/lib/Transforms/IPO/GlobalOpt.cpp index 68b6fba..2c5fec9 100644 --- a/llvm/lib/Transforms/IPO/GlobalOpt.cpp +++ b/llvm/lib/Transforms/IPO/GlobalOpt.cpp @@ -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; } diff --git a/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp b/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp index f0b85c1..095c70f 100644 --- a/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp +++ b/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp @@ -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) { diff --git a/llvm/lib/Transforms/Utils/ValueMapper.cpp b/llvm/lib/Transforms/Utils/ValueMapper.cpp index f3afd42..c3093be 100644 --- a/llvm/lib/Transforms/Utils/ValueMapper.cpp +++ b/llvm/lib/Transforms/Utils/ValueMapper.cpp @@ -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; } } -- 2.7.4