Skip to content

[llvm] Use range constructors of *Set (NFC) #137552

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions llvm/lib/Analysis/MemorySSAUpdater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<BasicBlock *, 4> NewPhiBBPreds(pred_begin(NewPhiBB),
pred_end(NewPhiBB));
SmallPtrSet<BasicBlock *, 4> 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);
Expand Down
12 changes: 6 additions & 6 deletions llvm/lib/CodeGen/MachineBlockPlacement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1024,8 +1024,8 @@ bool MachineBlockPlacement::isTrellis(
if (BB->succ_size() != 2 || ViableSuccs.size() != 2)
return false;

SmallPtrSet<const MachineBasicBlock *, 2> Successors(BB->succ_begin(),
BB->succ_end());
SmallPtrSet<const MachineBasicBlock *, 2> Successors(llvm::from_range,
BB->successors());
// To avoid reviewing the same predecessors twice.
SmallPtrSet<const MachineBasicBlock *, 8> SeenPreds;

Expand Down Expand Up @@ -1117,8 +1117,8 @@ MachineBlockPlacement::getBestTrellisSuccessor(
const BlockFilterSet *BlockFilter) {

BlockAndTailDupResult Result = {nullptr, false};
SmallPtrSet<const MachineBasicBlock *, 4> Successors(BB->succ_begin(),
BB->succ_end());
SmallPtrSet<const MachineBasicBlock *, 4> 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
Expand Down Expand Up @@ -1209,8 +1209,8 @@ bool MachineBlockPlacement::canTailDuplicateUnplacedPreds(
unsigned int NumDup = 0;

// For CFG checking.
SmallPtrSet<const MachineBasicBlock *, 4> Successors(BB->succ_begin(),
BB->succ_end());
SmallPtrSet<const MachineBasicBlock *, 4> Successors(llvm::from_range,
BB->successors());
for (MachineBasicBlock *Pred : Succ->predecessors()) {
// Make sure all unplaced and unfiltered predecessors can be
// tail-duplicated into.
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/CodeGen/TailDuplicator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -751,8 +751,8 @@ bool TailDuplicator::canCompletelyDuplicateBB(MachineBasicBlock &BB) {
bool TailDuplicator::duplicateSimpleBB(
MachineBasicBlock *TailBB, SmallVectorImpl<MachineBasicBlock *> &TDBBs,
const DenseSet<Register> &UsedByPhi) {
SmallPtrSet<MachineBasicBlock *, 8> Succs(TailBB->succ_begin(),
TailBB->succ_end());
SmallPtrSet<MachineBasicBlock *, 8> Succs(llvm::from_range,
TailBB->successors());
SmallVector<MachineBasicBlock *, 8> Preds(TailBB->predecessors());
bool Changed = false;
for (MachineBasicBlock *PredBB : Preds) {
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/CodeGen/TargetInstrInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Register, 32> ReductionChain(Chain.begin(), Chain.end());
SmallSet<Register, 32> ReductionChain(llvm::from_range, Chain);
for (const auto &I : MBB) {
if (I.getOpcode() == Opc &&
!ReductionChain.contains(I.getOperand(0).getReg()))
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/CodeGen/UnreachableBlockElim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,8 @@ bool UnreachableMachineBlockElim::run(MachineFunction &F) {
// Cleanup PHI nodes.
for (MachineBasicBlock &BB : F) {
// Prune unneeded PHI entries.
SmallPtrSet<MachineBasicBlock*, 8> preds(BB.pred_begin(),
BB.pred_end());
SmallPtrSet<MachineBasicBlock *, 8> 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())) {
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/Hexagon/HexagonExpandCondsets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ void HexagonExpandCondsets::updateDeadsInRange(Register Reg, LaneBitmask LM,
return true;
}
MachineBasicBlock *Entry = &Dest->getParent()->front();
SetVector<MachineBasicBlock*> Work(Dest->pred_begin(), Dest->pred_end());
SetVector<MachineBasicBlock *> Work(llvm::from_range, Dest->predecessors());
for (unsigned i = 0; i < Work.size(); ++i) {
MachineBasicBlock *B = Work[i];
if (Defs.count(B))
Expand Down
6 changes: 2 additions & 4 deletions llvm/lib/Transforms/Scalar/ADCE.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<BasicBlock *, 16> BWDT{
BlocksWithDeadTerminators.begin(),
BlocksWithDeadTerminators.end()
};
const SmallPtrSet<BasicBlock *, 16> BWDT(llvm::from_range,
BlocksWithDeadTerminators);
SmallVector<BasicBlock *, 32> IDFBlocks;
ReverseIDFCalculator IDFs(PDT);
IDFs.setDefiningBlocks(NewLiveBlocks);
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<BasicBlock *, 8> SeenSuccs;
SmallPtrSet<BasicBlock *, 2> SuccsOfPredBB(succ_begin(PredBB),
succ_end(PredBB));
SmallPtrSet<BasicBlock *, 2> 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
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Transforms/Utils/FlattenCFG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ bool FlattenCFGOpt::FlattenParallelAndOr(BasicBlock *BB, IRBuilder<> &Builder) {
int Idx = -1;

// Check predecessors of \param BB.
SmallPtrSet<BasicBlock *, 16> Preds(pred_begin(BB), pred_end(BB));
SmallPtrSet<BasicBlock *, 16> Preds(llvm::from_range, predecessors(BB));
for (BasicBlock *Pred : Preds) {
BranchInst *PBI = dyn_cast<BranchInst>(Pred->getTerminator());

Expand Down
5 changes: 3 additions & 2 deletions llvm/lib/Transforms/Utils/Local.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1158,7 +1158,7 @@ bool llvm::TryToSimplifyUncondBranchFromEmptyBlock(BasicBlock *BB,
if (BB == Succ)
return false;

SmallPtrSet<BasicBlock *, 16> BBPreds(pred_begin(BB), pred_end(BB));
SmallPtrSet<BasicBlock *, 16> BBPreds(llvm::from_range, predecessors(BB));

// The single common predecessor of BB and Succ when BB cannot be killed
BasicBlock *CommonPred = nullptr;
Expand Down Expand Up @@ -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<BasicBlock *, 16> SuccPreds(pred_begin(Succ), pred_end(Succ));
SmallPtrSet<BasicBlock *, 16> 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))
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Transforms/Utils/SimplifyCFG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ safeToMergeTerminators(Instruction *SI1, Instruction *SI2,
BasicBlock *SI1BB = SI1->getParent();
BasicBlock *SI2BB = SI2->getParent();

SmallPtrSet<BasicBlock *, 16> SI1Succs(succ_begin(SI1BB), succ_end(SI1BB));
SmallPtrSet<BasicBlock *, 16> SI1Succs(llvm::from_range, successors(SI1BB));
bool Fail = false;
for (BasicBlock *Succ : successors(SI2BB)) {
if (!SI1Succs.count(Succ))
Expand Down Expand Up @@ -1332,7 +1332,7 @@ bool SimplifyCFGOpt::performValueComparisonIntoPredecessorFolding(
// successors.
SmallPtrSet<BasicBlock *, 2> 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<BasicBlock *, int /*Num*/> &NewSuccessor :
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<BasicBlock *>(pred_begin(BB), pred_end(BB))) {
SetVector<BasicBlock *>(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;
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10107,7 +10107,7 @@ void BoUpSLP::buildTreeRec(ArrayRef<Value *> VL, unsigned Depth,

BlockScheduling &BS = *BSRef;

SetVector<Value *> UniqueValues(VL.begin(), VL.end());
SetVector<Value *> UniqueValues(llvm::from_range, VL);
std::optional<ScheduleBundle *> BundlePtr =
BS.tryScheduleBundle(UniqueValues.getArrayRef(), this, S);
#ifdef EXPENSIVE_CHECKS
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ createScalarIVSteps(VPlan &Plan, InductionDescriptor::InductionKind Kind,
}

static SmallVector<VPUser *> collectUsersRecursively(VPValue *V) {
SetVector<VPUser *> Users(V->user_begin(), V->user_end());
SetVector<VPUser *> Users(llvm::from_range, V->users());
for (unsigned I = 0; I != Users.size(); ++I) {
VPRecipeBase *Cur = cast<VPRecipeBase>(Users[I]);
if (isa<VPHeaderPHIRecipe>(Cur))
Expand Down
Loading