From a415d255ae9473f3fc4f5ddd513b1d3f987edd5c Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Sun, 13 Apr 2025 17:28:00 -0700 Subject: [PATCH] [llvm] Use range constructors of *Set (NFC) --- llvm/lib/Analysis/MemorySSAUpdater.cpp | 4 ++-- llvm/lib/CodeGen/MachineBlockPlacement.cpp | 12 ++++++------ llvm/lib/CodeGen/TailDuplicator.cpp | 4 ++-- llvm/lib/CodeGen/TargetInstrInfo.cpp | 2 +- llvm/lib/CodeGen/UnreachableBlockElim.cpp | 4 ++-- llvm/lib/Target/Hexagon/HexagonExpandCondsets.cpp | 2 +- llvm/lib/Transforms/Scalar/ADCE.cpp | 6 ++---- llvm/lib/Transforms/Utils/BasicBlockUtils.cpp | 4 ++-- llvm/lib/Transforms/Utils/FlattenCFG.cpp | 2 +- llvm/lib/Transforms/Utils/Local.cpp | 5 +++-- llvm/lib/Transforms/Utils/SimplifyCFG.cpp | 4 ++-- llvm/lib/Transforms/Vectorize/LoopVectorize.cpp | 2 +- llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp | 2 +- llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp | 2 +- 14 files changed, 27 insertions(+), 28 deletions(-) diff --git a/llvm/lib/Analysis/MemorySSAUpdater.cpp b/llvm/lib/Analysis/MemorySSAUpdater.cpp index 5e4477ee43f27..aa9f0b6e100c4 100644 --- a/llvm/lib/Analysis/MemorySSAUpdater.cpp +++ b/llvm/lib/Analysis/MemorySSAUpdater.cpp @@ -679,8 +679,8 @@ void MemorySSAUpdater::updateForClonedLoop(const LoopBlocksRPO &LoopBlocks, auto FixPhiIncomingValues = [&](MemoryPhi *Phi, MemoryPhi *NewPhi) { assert(Phi && NewPhi && "Invalid Phi nodes."); BasicBlock *NewPhiBB = NewPhi->getBlock(); - SmallPtrSet NewPhiBBPreds(pred_begin(NewPhiBB), - pred_end(NewPhiBB)); + SmallPtrSet NewPhiBBPreds(llvm::from_range, + predecessors(NewPhiBB)); for (unsigned It = 0, E = Phi->getNumIncomingValues(); It < E; ++It) { MemoryAccess *IncomingAccess = Phi->getIncomingValue(It); BasicBlock *IncBB = Phi->getIncomingBlock(It); diff --git a/llvm/lib/CodeGen/MachineBlockPlacement.cpp b/llvm/lib/CodeGen/MachineBlockPlacement.cpp index bd777db0791b7..08fe3d47e2ff5 100644 --- a/llvm/lib/CodeGen/MachineBlockPlacement.cpp +++ b/llvm/lib/CodeGen/MachineBlockPlacement.cpp @@ -1024,8 +1024,8 @@ bool MachineBlockPlacement::isTrellis( if (BB->succ_size() != 2 || ViableSuccs.size() != 2) return false; - SmallPtrSet Successors(BB->succ_begin(), - BB->succ_end()); + SmallPtrSet Successors(llvm::from_range, + BB->successors()); // To avoid reviewing the same predecessors twice. SmallPtrSet SeenPreds; @@ -1117,8 +1117,8 @@ MachineBlockPlacement::getBestTrellisSuccessor( const BlockFilterSet *BlockFilter) { BlockAndTailDupResult Result = {nullptr, false}; - SmallPtrSet Successors(BB->succ_begin(), - BB->succ_end()); + SmallPtrSet Successors(llvm::from_range, + BB->successors()); // We assume size 2 because it's common. For general n, we would have to do // the Hungarian algorithm, but it's not worth the complexity because more @@ -1209,8 +1209,8 @@ bool MachineBlockPlacement::canTailDuplicateUnplacedPreds( unsigned int NumDup = 0; // For CFG checking. - SmallPtrSet Successors(BB->succ_begin(), - BB->succ_end()); + SmallPtrSet Successors(llvm::from_range, + BB->successors()); for (MachineBasicBlock *Pred : Succ->predecessors()) { // Make sure all unplaced and unfiltered predecessors can be // tail-duplicated into. diff --git a/llvm/lib/CodeGen/TailDuplicator.cpp b/llvm/lib/CodeGen/TailDuplicator.cpp index ba476c88948a2..b69b8227b1674 100644 --- a/llvm/lib/CodeGen/TailDuplicator.cpp +++ b/llvm/lib/CodeGen/TailDuplicator.cpp @@ -751,8 +751,8 @@ bool TailDuplicator::canCompletelyDuplicateBB(MachineBasicBlock &BB) { bool TailDuplicator::duplicateSimpleBB( MachineBasicBlock *TailBB, SmallVectorImpl &TDBBs, const DenseSet &UsedByPhi) { - SmallPtrSet Succs(TailBB->succ_begin(), - TailBB->succ_end()); + SmallPtrSet Succs(llvm::from_range, + TailBB->successors()); SmallVector Preds(TailBB->predecessors()); bool Changed = false; for (MachineBasicBlock *PredBB : Preds) { diff --git a/llvm/lib/CodeGen/TargetInstrInfo.cpp b/llvm/lib/CodeGen/TargetInstrInfo.cpp index 6aaeed39bc81d..3e29f62005478 100644 --- a/llvm/lib/CodeGen/TargetInstrInfo.cpp +++ b/llvm/lib/CodeGen/TargetInstrInfo.cpp @@ -1043,7 +1043,7 @@ bool TargetInstrInfo::getAccumulatorReassociationPatterns( // Check if the MBB this instruction is a part of contains any other chains. // If so, don't apply it. - SmallSet ReductionChain(Chain.begin(), Chain.end()); + SmallSet ReductionChain(llvm::from_range, Chain); for (const auto &I : MBB) { if (I.getOpcode() == Opc && !ReductionChain.contains(I.getOperand(0).getReg())) diff --git a/llvm/lib/CodeGen/UnreachableBlockElim.cpp b/llvm/lib/CodeGen/UnreachableBlockElim.cpp index f9f7b47160b6c..512e83db40a5a 100644 --- a/llvm/lib/CodeGen/UnreachableBlockElim.cpp +++ b/llvm/lib/CodeGen/UnreachableBlockElim.cpp @@ -185,8 +185,8 @@ bool UnreachableMachineBlockElim::run(MachineFunction &F) { // Cleanup PHI nodes. for (MachineBasicBlock &BB : F) { // Prune unneeded PHI entries. - SmallPtrSet preds(BB.pred_begin(), - BB.pred_end()); + SmallPtrSet preds(llvm::from_range, + BB.predecessors()); for (MachineInstr &Phi : make_early_inc_range(BB.phis())) { for (unsigned i = Phi.getNumOperands() - 1; i >= 2; i -= 2) { if (!preds.count(Phi.getOperand(i).getMBB())) { diff --git a/llvm/lib/Target/Hexagon/HexagonExpandCondsets.cpp b/llvm/lib/Target/Hexagon/HexagonExpandCondsets.cpp index d09213d774cb4..35153c7b16c0f 100644 --- a/llvm/lib/Target/Hexagon/HexagonExpandCondsets.cpp +++ b/llvm/lib/Target/Hexagon/HexagonExpandCondsets.cpp @@ -382,7 +382,7 @@ void HexagonExpandCondsets::updateDeadsInRange(Register Reg, LaneBitmask LM, return true; } MachineBasicBlock *Entry = &Dest->getParent()->front(); - SetVector Work(Dest->pred_begin(), Dest->pred_end()); + SetVector Work(llvm::from_range, Dest->predecessors()); for (unsigned i = 0; i < Work.size(); ++i) { MachineBasicBlock *B = Work[i]; if (Defs.count(B)) diff --git a/llvm/lib/Transforms/Scalar/ADCE.cpp b/llvm/lib/Transforms/Scalar/ADCE.cpp index 5f0a9b22c3ee7..ea907af96edd9 100644 --- a/llvm/lib/Transforms/Scalar/ADCE.cpp +++ b/llvm/lib/Transforms/Scalar/ADCE.cpp @@ -485,10 +485,8 @@ void AggressiveDeadCodeElimination::markLiveBranchesFromControlDependences() { // which currently have dead terminators that are control // dependence sources of a block which is in NewLiveBlocks. - const SmallPtrSet BWDT{ - BlocksWithDeadTerminators.begin(), - BlocksWithDeadTerminators.end() - }; + const SmallPtrSet BWDT(llvm::from_range, + BlocksWithDeadTerminators); SmallVector IDFBlocks; ReverseIDFCalculator IDFs(PDT); IDFs.setDefiningBlocks(NewLiveBlocks); diff --git a/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp b/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp index 9ed8b06c22fde..429037ab9da47 100644 --- a/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp +++ b/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp @@ -249,8 +249,8 @@ bool llvm::MergeBlockIntoPredecessor(BasicBlock *BB, DomTreeUpdater *DTU, assert(!DT && "cannot use both DT and DTU for updates"); // To avoid processing the same predecessor more than once. SmallPtrSet SeenSuccs; - SmallPtrSet SuccsOfPredBB(succ_begin(PredBB), - succ_end(PredBB)); + SmallPtrSet SuccsOfPredBB(llvm::from_range, + successors(PredBB)); Updates.reserve(Updates.size() + 2 * succ_size(BB) + 1); // Add insert edges first. Experimentally, for the particular case of two // blocks that can be merged, with a single successor and single predecessor diff --git a/llvm/lib/Transforms/Utils/FlattenCFG.cpp b/llvm/lib/Transforms/Utils/FlattenCFG.cpp index 7e6ab4c76a882..1d9408d6db433 100644 --- a/llvm/lib/Transforms/Utils/FlattenCFG.cpp +++ b/llvm/lib/Transforms/Utils/FlattenCFG.cpp @@ -144,7 +144,7 @@ bool FlattenCFGOpt::FlattenParallelAndOr(BasicBlock *BB, IRBuilder<> &Builder) { int Idx = -1; // Check predecessors of \param BB. - SmallPtrSet Preds(pred_begin(BB), pred_end(BB)); + SmallPtrSet Preds(llvm::from_range, predecessors(BB)); for (BasicBlock *Pred : Preds) { BranchInst *PBI = dyn_cast(Pred->getTerminator()); diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp index 414011259fcf1..809a0d7ebeea6 100644 --- a/llvm/lib/Transforms/Utils/Local.cpp +++ b/llvm/lib/Transforms/Utils/Local.cpp @@ -1158,7 +1158,7 @@ bool llvm::TryToSimplifyUncondBranchFromEmptyBlock(BasicBlock *BB, if (BB == Succ) return false; - SmallPtrSet BBPreds(pred_begin(BB), pred_end(BB)); + SmallPtrSet BBPreds(llvm::from_range, predecessors(BB)); // The single common predecessor of BB and Succ when BB cannot be killed BasicBlock *CommonPred = nullptr; @@ -1293,7 +1293,8 @@ bool llvm::TryToSimplifyUncondBranchFromEmptyBlock(BasicBlock *BB, // All predecessors of BB (except the common predecessor) will be moved to // Succ. Updates.reserve(Updates.size() + 2 * pred_size(BB) + 1); - SmallPtrSet SuccPreds(pred_begin(Succ), pred_end(Succ)); + SmallPtrSet SuccPreds(llvm::from_range, + predecessors(Succ)); for (auto *PredOfBB : predecessors(BB)) { // Do not modify those common predecessors of BB and Succ if (!SuccPreds.contains(PredOfBB)) diff --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp index 6bf4ea37e2f96..8094697cdd13a 100644 --- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp +++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp @@ -367,7 +367,7 @@ safeToMergeTerminators(Instruction *SI1, Instruction *SI2, BasicBlock *SI1BB = SI1->getParent(); BasicBlock *SI2BB = SI2->getParent(); - SmallPtrSet SI1Succs(succ_begin(SI1BB), succ_end(SI1BB)); + SmallPtrSet SI1Succs(llvm::from_range, successors(SI1BB)); bool Fail = false; for (BasicBlock *Succ : successors(SI2BB)) { if (!SI1Succs.count(Succ)) @@ -1332,7 +1332,7 @@ bool SimplifyCFGOpt::performValueComparisonIntoPredecessorFolding( // successors. SmallPtrSet SuccsOfPred; if (DTU) { - SuccsOfPred = {succ_begin(Pred), succ_end(Pred)}; + SuccsOfPred = {llvm::from_range, successors(Pred)}; Updates.reserve(Updates.size() + NewSuccessors.size()); } for (const std::pair &NewSuccessor : diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp index 6f1c7aafe2dcc..d73ba07ad350e 100644 --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -8425,7 +8425,7 @@ void VPRecipeBuilder::createBlockInMask(BasicBlock *BB) { VPValue *BlockMask = nullptr; // This is the block mask. We OR all unique incoming edges. for (auto *Predecessor : - SetVector(pred_begin(BB), pred_end(BB))) { + SetVector(llvm::from_range, predecessors(BB))) { VPValue *EdgeMask = createEdgeMask(Predecessor, BB); if (!EdgeMask) { // Mask of predecessor is all-one so mask of block is too. BlockMaskCache[BB] = EdgeMask; diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index c222053377f5e..30d73d8352c42 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -10107,7 +10107,7 @@ void BoUpSLP::buildTreeRec(ArrayRef VL, unsigned Depth, BlockScheduling &BS = *BSRef; - SetVector UniqueValues(VL.begin(), VL.end()); + SetVector UniqueValues(llvm::from_range, VL); std::optional BundlePtr = BS.tryScheduleBundle(UniqueValues.getArrayRef(), this, S); #ifdef EXPENSIVE_CHECKS diff --git a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp index fa16a64ebd80a..d0128ecd491dc 100644 --- a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp +++ b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp @@ -597,7 +597,7 @@ createScalarIVSteps(VPlan &Plan, InductionDescriptor::InductionKind Kind, } static SmallVector collectUsersRecursively(VPValue *V) { - SetVector Users(V->user_begin(), V->user_end()); + SetVector Users(llvm::from_range, V->users()); for (unsigned I = 0; I != Users.size(); ++I) { VPRecipeBase *Cur = cast(Users[I]); if (isa(Cur))