From 89d0775f1aa7976d505ae9d433f81c5447c360ee Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Sat, 3 Aug 2024 15:33:08 -0700 Subject: [PATCH] [Transforms] Construct SmallVector with ArrayRef (NFC) (#101851) --- llvm/include/llvm/Transforms/IPO/Attributor.h | 2 +- llvm/lib/Transforms/Coroutines/CoroSplit.cpp | 2 +- llvm/lib/Transforms/IPO/PartialInlining.cpp | 9 ++++----- .../ControlHeightReduction.cpp | 3 +-- .../lib/Transforms/Scalar/LoopInterchange.cpp | 2 +- .../Scalar/LowerMatrixIntrinsics.cpp | 2 +- .../Transforms/Utils/LoopUnrollRuntime.cpp | 3 +-- llvm/lib/Transforms/Utils/LoopVersioning.cpp | 6 ++---- .../Transforms/Vectorize/LoopVectorize.cpp | 2 +- .../Transforms/Vectorize/SLPVectorizer.cpp | 19 ++++++++----------- .../Transforms/Vectorize/VectorCombine.cpp | 6 +++--- 11 files changed, 24 insertions(+), 32 deletions(-) diff --git a/llvm/include/llvm/Transforms/IPO/Attributor.h b/llvm/include/llvm/Transforms/IPO/Attributor.h index 34557238ecb23ce..ad3c6426efd2fe2 100644 --- a/llvm/include/llvm/Transforms/IPO/Attributor.h +++ b/llvm/include/llvm/Transforms/IPO/Attributor.h @@ -2247,7 +2247,7 @@ struct Attributor { CalleeRepairCBTy &&CalleeRepairCB, ACSRepairCBTy &&ACSRepairCB) : A(A), ReplacedFn(*Arg.getParent()), ReplacedArg(Arg), - ReplacementTypes(ReplacementTypes.begin(), ReplacementTypes.end()), + ReplacementTypes(ReplacementTypes), CalleeRepairCB(std::move(CalleeRepairCB)), ACSRepairCB(std::move(ACSRepairCB)) {} diff --git a/llvm/lib/Transforms/Coroutines/CoroSplit.cpp b/llvm/lib/Transforms/Coroutines/CoroSplit.cpp index 9e4da5f8ca96158..8eceaef59a1e1f0 100644 --- a/llvm/lib/Transforms/Coroutines/CoroSplit.cpp +++ b/llvm/lib/Transforms/Coroutines/CoroSplit.cpp @@ -1605,7 +1605,7 @@ struct SwitchCoroutineSplitter { ArrayRef Fns) { // This only works under the switch-lowering ABI because coro elision // only works on the switch-lowering ABI. - SmallVector Args(Fns.begin(), Fns.end()); + SmallVector Args(Fns); assert(!Args.empty()); Function *Part = *Fns.begin(); Module *M = Part->getParent(); diff --git a/llvm/lib/Transforms/IPO/PartialInlining.cpp b/llvm/lib/Transforms/IPO/PartialInlining.cpp index 3ca095e1520f3bf..28c81465a094896 100644 --- a/llvm/lib/Transforms/IPO/PartialInlining.cpp +++ b/llvm/lib/Transforms/IPO/PartialInlining.cpp @@ -170,11 +170,10 @@ struct FunctionOutliningMultiRegionInfo { // Container for outline regions struct OutlineRegionInfo { - OutlineRegionInfo(ArrayRef Region, - BasicBlock *EntryBlock, BasicBlock *ExitBlock, - BasicBlock *ReturnBlock) - : Region(Region.begin(), Region.end()), EntryBlock(EntryBlock), - ExitBlock(ExitBlock), ReturnBlock(ReturnBlock) {} + OutlineRegionInfo(ArrayRef Region, BasicBlock *EntryBlock, + BasicBlock *ExitBlock, BasicBlock *ReturnBlock) + : Region(Region), EntryBlock(EntryBlock), ExitBlock(ExitBlock), + ReturnBlock(ReturnBlock) {} SmallVector Region; BasicBlock *EntryBlock; BasicBlock *ExitBlock; diff --git a/llvm/lib/Transforms/Instrumentation/ControlHeightReduction.cpp b/llvm/lib/Transforms/Instrumentation/ControlHeightReduction.cpp index c2affafa49e519d..810cbbda66085a6 100644 --- a/llvm/lib/Transforms/Instrumentation/ControlHeightReduction.cpp +++ b/llvm/lib/Transforms/Instrumentation/ControlHeightReduction.cpp @@ -281,8 +281,7 @@ class CHRScope { private: CHRScope(ArrayRef RegInfosIn, ArrayRef SubsIn) - : RegInfos(RegInfosIn.begin(), RegInfosIn.end()), - Subs(SubsIn.begin(), SubsIn.end()), BranchInsertPoint(nullptr) {} + : RegInfos(RegInfosIn), Subs(SubsIn), BranchInsertPoint(nullptr) {} }; class CHR { diff --git a/llvm/lib/Transforms/Scalar/LoopInterchange.cpp b/llvm/lib/Transforms/Scalar/LoopInterchange.cpp index 400973fd9fc9159..949296c3db0de23 100644 --- a/llvm/lib/Transforms/Scalar/LoopInterchange.cpp +++ b/llvm/lib/Transforms/Scalar/LoopInterchange.cpp @@ -383,7 +383,7 @@ struct LoopInterchange { } bool run(LoopNest &LN) { - SmallVector LoopList(LN.getLoops().begin(), LN.getLoops().end()); + SmallVector LoopList(LN.getLoops()); for (unsigned I = 1; I < LoopList.size(); ++I) if (LoopList[I]->getParentLoop() != LoopList[I - 1]) return false; diff --git a/llvm/lib/Transforms/Scalar/LowerMatrixIntrinsics.cpp b/llvm/lib/Transforms/Scalar/LowerMatrixIntrinsics.cpp index 6a681fd93397172..d0a83a8242ddc0c 100644 --- a/llvm/lib/Transforms/Scalar/LowerMatrixIntrinsics.cpp +++ b/llvm/lib/Transforms/Scalar/LowerMatrixIntrinsics.cpp @@ -362,7 +362,7 @@ class LowerMatrixIntrinsics { public: MatrixTy() : IsColumnMajor(MatrixLayout == MatrixLayoutTy::ColumnMajor) {} MatrixTy(ArrayRef Vectors) - : Vectors(Vectors.begin(), Vectors.end()), + : Vectors(Vectors), IsColumnMajor(MatrixLayout == MatrixLayoutTy::ColumnMajor) {} MatrixTy(unsigned NumRows, unsigned NumColumns, Type *EltTy) : IsColumnMajor(MatrixLayout == MatrixLayoutTy::ColumnMajor) { diff --git a/llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp b/llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp index 56aa96e550d9c3c..2d74b2b8d1d2fd9 100644 --- a/llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp +++ b/llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp @@ -971,8 +971,7 @@ bool llvm::UnrollRuntimeLoopRemainder( // (e.g. breakLoopBackedgeAndSimplify) and reused in loop-deletion. BasicBlock *RemainderLatch = remainderLoop->getLoopLatch(); assert(RemainderLatch); - SmallVector RemainderBlocks(remainderLoop->getBlocks().begin(), - remainderLoop->getBlocks().end()); + SmallVector RemainderBlocks(remainderLoop->getBlocks()); breakLoopBackedge(remainderLoop, *DT, *SE, *LI, nullptr); remainderLoop = nullptr; diff --git a/llvm/lib/Transforms/Utils/LoopVersioning.cpp b/llvm/lib/Transforms/Utils/LoopVersioning.cpp index c43c92a6b4d5d3f..af2ed6240f72204 100644 --- a/llvm/lib/Transforms/Utils/LoopVersioning.cpp +++ b/llvm/lib/Transforms/Utils/LoopVersioning.cpp @@ -42,10 +42,8 @@ LoopVersioning::LoopVersioning(const LoopAccessInfo &LAI, ArrayRef Checks, Loop *L, LoopInfo *LI, DominatorTree *DT, ScalarEvolution *SE) - : VersionedLoop(L), AliasChecks(Checks.begin(), Checks.end()), - Preds(LAI.getPSE().getPredicate()), LAI(LAI), LI(LI), DT(DT), - SE(SE) { -} + : VersionedLoop(L), AliasChecks(Checks), Preds(LAI.getPSE().getPredicate()), + LAI(LAI), LI(LI), DT(DT), SE(SE) {} void LoopVersioning::versionLoop( const SmallVectorImpl &DefsUsedOutside) { diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp index 6daa8043a3fbf90..40d10395de17d4b 100644 --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -8219,7 +8219,7 @@ VPWidenRecipe *VPRecipeBuilder::tryToWiden(Instruction *I, // If not provably safe, use a select to form a safe divisor before widening the // div/rem operation itself. Otherwise fall through to general handling below. if (CM.isPredicatedInst(I)) { - SmallVector Ops(Operands.begin(), Operands.end()); + SmallVector Ops(Operands); VPValue *Mask = getBlockInMask(I->getParent()); VPValue *One = Plan.getOrAddLiveIn(ConstantInt::get(I->getType(), 1u, false)); diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index cd273429e6e67e5..305efb732d8f7e7 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -1575,7 +1575,7 @@ class BoUpSLP { if (I1 && I2) { if (I1->getParent() != I2->getParent()) return CheckSameEntryOrFail(); - SmallVector Ops(MainAltOps.begin(), MainAltOps.end()); + SmallVector Ops(MainAltOps); Ops.push_back(I1); Ops.push_back(I2); InstructionsState S = getSameOpcode(Ops, TLI); @@ -5236,7 +5236,7 @@ void BoUpSLP::reorderNodeWithReuses(TreeEntry &TE, ArrayRef Mask) const { TE.ReorderIndices.clear(); // Try to improve gathered nodes with clustered reuses, if possible. ArrayRef Slice = ArrayRef(NewMask).slice(0, Sz); - SmallVector NewOrder(Slice.begin(), Slice.end()); + SmallVector NewOrder(Slice); inversePermutation(NewOrder, NewMask); reorderScalars(TE.Scalars, NewMask); // Fill the reuses mask with the identity submasks. @@ -7916,8 +7916,7 @@ class BaseShuffleAnalysis { } break; } - SmallVector ShuffleMask(SV->getShuffleMask().begin(), - SV->getShuffleMask().end()); + SmallVector ShuffleMask(SV->getShuffleMask()); combineMasks(LocalVF, ShuffleMask, Mask); Mask.swap(ShuffleMask); if (IsOp2Undef) @@ -8017,15 +8016,13 @@ class BaseShuffleAnalysis { isUndefVector(SV2->getOperand(1), UseMask2).all()) { Op1 = SV1->getOperand(0); Op2 = SV2->getOperand(0); - SmallVector ShuffleMask1(SV1->getShuffleMask().begin(), - SV1->getShuffleMask().end()); + SmallVector ShuffleMask1(SV1->getShuffleMask()); int LocalVF = ShuffleMask1.size(); if (auto *FTy = dyn_cast(Op1->getType())) LocalVF = FTy->getNumElements(); combineMasks(LocalVF, ShuffleMask1, CombinedMask1); CombinedMask1.swap(ShuffleMask1); - SmallVector ShuffleMask2(SV2->getShuffleMask().begin(), - SV2->getShuffleMask().end()); + SmallVector ShuffleMask2(SV2->getShuffleMask()); LocalVF = ShuffleMask2.size(); if (auto *FTy = dyn_cast(Op2->getType())) LocalVF = FTy->getNumElements(); @@ -8062,7 +8059,7 @@ class BaseShuffleAnalysis { if (isa(V1)) return Builder.createPoison( cast(V1->getType())->getElementType(), Mask.size()); - SmallVector NewMask(Mask.begin(), Mask.end()); + SmallVector NewMask(Mask); bool IsIdentity = peekThroughShuffles(V1, NewMask, /*SinglePermute=*/true); assert(V1 && "Expected non-null value after looking through shuffles."); @@ -8290,7 +8287,7 @@ class BoUpSLP::ShuffleCostEstimator : public BaseShuffleAnalysis { return TTI::TCC_Free; auto *VecTy = getWidenedType(ScalarTy, VL.size()); InstructionCost GatherCost = 0; - SmallVector Gathers(VL.begin(), VL.end()); + SmallVector Gathers(VL); // Improve gather cost for gather of loads, if we can group some of the // loads into vector loads. InstructionsState S = getSameOpcode(VL, *R.TLI); @@ -8725,7 +8722,7 @@ class BoUpSLP::ShuffleCostEstimator : public BaseShuffleAnalysis { const PointerUnion &P2, ArrayRef Mask) { ShuffleCostBuilder Builder(TTI); - SmallVector CommonMask(Mask.begin(), Mask.end()); + SmallVector CommonMask(Mask); Value *V1 = P1.dyn_cast(), *V2 = P2.dyn_cast(); unsigned CommonVF = Mask.size(); InstructionCost ExtraCost = 0; diff --git a/llvm/lib/Transforms/Vectorize/VectorCombine.cpp b/llvm/lib/Transforms/Vectorize/VectorCombine.cpp index 444598520c981a1..d81c747684f07ad 100644 --- a/llvm/lib/Transforms/Vectorize/VectorCombine.cpp +++ b/llvm/lib/Transforms/Vectorize/VectorCombine.cpp @@ -1434,7 +1434,7 @@ bool VectorCombine::foldShuffleOfBinops(Instruction &I) { M -= NumSrcElts; }; - SmallVector NewMask0(OldMask.begin(), OldMask.end()); + SmallVector NewMask0(OldMask); TargetTransformInfo::ShuffleKind SK0 = TargetTransformInfo::SK_PermuteTwoSrc; if (X == Z) { llvm::for_each(NewMask0, ConvertToUnary); @@ -1442,7 +1442,7 @@ bool VectorCombine::foldShuffleOfBinops(Instruction &I) { Z = PoisonValue::get(BinOpTy); } - SmallVector NewMask1(OldMask.begin(), OldMask.end()); + SmallVector NewMask1(OldMask); TargetTransformInfo::ShuffleKind SK1 = TargetTransformInfo::SK_PermuteTwoSrc; if (Y == W) { llvm::for_each(NewMask1, ConvertToUnary); @@ -1624,7 +1624,7 @@ bool VectorCombine::foldShuffleOfShuffles(Instruction &I) { return false; // Merge shuffles - replace index to the RHS poison arg with PoisonMaskElem, - SmallVector NewMask(OuterMask.begin(), OuterMask.end()); + SmallVector NewMask(OuterMask); for (int &M : NewMask) { if (0 <= M && M < (int)NumImmElts) { M = (InnerMask0[M] >= (int)NumSrcElts) ? PoisonMaskElem : InnerMask0[M];