Skip to content

Commit 673f470

Browse files
[llvm] Use *Set::insert_range (NFC) (#133353)
We can use *Set::insert_range to collapse: for (auto Elem : Range) Set.insert(E.first); down to: Set.insert_range(llvm::make_first_range(Range)); In some cases, we can further fold that into the set declaration.
1 parent c9197b2 commit 673f470

File tree

10 files changed

+17
-33
lines changed

10 files changed

+17
-33
lines changed

llvm/lib/CodeGen/CodeGenPrepare.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4370,8 +4370,7 @@ class AddressingModeCombiner {
43704370
// If it does not match, collect all Phi nodes from matcher.
43714371
// if we end up with no match, them all these Phi nodes will not match
43724372
// later.
4373-
for (auto M : Matched)
4374-
WillNotMatch.insert(M.first);
4373+
WillNotMatch.insert_range(llvm::make_first_range(Matched));
43754374
Matched.clear();
43764375
}
43774376
if (IsMatched) {

llvm/lib/CodeGen/FixupStatepointCallerSaved.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,7 @@ class FrameIndexesCache {
242242
ReservedSlots.clear();
243243
if (EHPad)
244244
if (auto It = GlobalIndices.find(EHPad); It != GlobalIndices.end())
245-
for (auto &RSP : It->second)
246-
ReservedSlots.insert(RSP.second);
245+
ReservedSlots.insert_range(llvm::make_second_range(It->second));
247246
}
248247

249248
// Get frame index to spill the register.

llvm/lib/IR/SafepointIRVerifier.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -612,11 +612,10 @@ void GCPtrTracker::verifyFunction(GCPtrTracker &&Tracker,
612612
}
613613

614614
void GCPtrTracker::recalculateBBsStates() {
615-
SetVector<const BasicBlock *> Worklist;
616615
// TODO: This order is suboptimal, it's better to replace it with priority
617616
// queue where priority is RPO number of BB.
618-
for (auto &BBI : BlockMap)
619-
Worklist.insert(BBI.first);
617+
SetVector<const BasicBlock *> Worklist(llvm::from_range,
618+
llvm::make_first_range(BlockMap));
620619

621620
// This loop iterates the AvailableIn/Out sets until it converges.
622621
// The AvailableIn and AvailableOut sets decrease as we iterate.

llvm/lib/ProfileData/SampleProf.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,7 @@ const FunctionSamples *FunctionSamples::findFunctionSamples(
267267
void FunctionSamples::findAllNames(DenseSet<FunctionId> &NameSet) const {
268268
NameSet.insert(getFunction());
269269
for (const auto &BS : BodySamples)
270-
for (const auto &TS : BS.second.getCallTargets())
271-
NameSet.insert(TS.first);
270+
NameSet.insert_range(llvm::make_first_range(BS.second.getCallTargets()));
272271

273272
for (const auto &CS : CallsiteSamples) {
274273
for (const auto &NameFS : CS.second) {

llvm/lib/Transforms/Scalar/JumpThreading.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -524,9 +524,7 @@ static unsigned getJumpThreadDuplicationCost(const TargetTransformInfo *TTI,
524524
void JumpThreadingPass::findLoopHeaders(Function &F) {
525525
SmallVector<std::pair<const BasicBlock*,const BasicBlock*>, 32> Edges;
526526
FindFunctionBackedges(F, Edges);
527-
528-
for (const auto &Edge : Edges)
529-
LoopHeaders.insert(Edge.second);
527+
LoopHeaders.insert_range(llvm::make_second_range(Edges));
530528
}
531529

532530
/// getKnownConstant - Helper method to determine if we can thread over a
@@ -1379,10 +1377,8 @@ bool JumpThreadingPass::simplifyPartiallyRedundantLoad(LoadInst *LoadI) {
13791377
// Otherwise, we had multiple unavailable predecessors or we had a critical
13801378
// edge from the one.
13811379
SmallVector<BasicBlock*, 8> PredsToSplit;
1382-
SmallPtrSet<BasicBlock*, 8> AvailablePredSet;
1383-
1384-
for (const auto &AvailablePred : AvailablePreds)
1385-
AvailablePredSet.insert(AvailablePred.first);
1380+
SmallPtrSet<BasicBlock *, 8> AvailablePredSet(
1381+
llvm::from_range, llvm::make_first_range(AvailablePreds));
13861382

13871383
// Add all the unavailable predecessors to the PredsToSplit list.
13881384
for (BasicBlock *P : predecessors(LoadBB)) {

llvm/lib/Transforms/Scalar/StructurizeCFG.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -819,8 +819,7 @@ void StructurizeCFG::setPhiValues() {
819819

820820
// Get the undefined blocks shared by all the phi nodes.
821821
if (!BlkPhis.empty()) {
822-
for (const auto &VI : BlkPhis.front().second)
823-
Incomings.insert(VI.first);
822+
Incomings.insert_range(llvm::make_first_range(BlkPhis.front().second));
824823
findUndefBlocks(To, Incomings, UndefBlks);
825824
}
826825

llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6896,8 +6896,7 @@ void BoUpSLP::reorderBottomToTop(bool IgnoreReorder) {
68966896
SmallVector<TreeEntry *> GatherOps;
68976897
if (!canReorderOperands(Data.first, Data.second, NonVectorized,
68986898
GatherOps)) {
6899-
for (const std::pair<unsigned, TreeEntry *> &Op : Data.second)
6900-
Visited.insert(Op.second);
6899+
Visited.insert_range(llvm::make_second_range(Data.second));
69016900
continue;
69026901
}
69036902
// All operands are reordered and used only in this node - propagate the
@@ -7073,8 +7072,7 @@ void BoUpSLP::reorderBottomToTop(bool IgnoreReorder) {
70737072
}
70747073
}
70757074
if (OrdersUses.empty()) {
7076-
for (const std::pair<unsigned, TreeEntry *> &Op : Data.second)
7077-
Visited.insert(Op.second);
7075+
Visited.insert_range(llvm::make_second_range(Data.second));
70787076
continue;
70797077
}
70807078
// Choose the most used order.
@@ -7103,8 +7101,7 @@ void BoUpSLP::reorderBottomToTop(bool IgnoreReorder) {
71037101
}
71047102
// Set order of the user node.
71057103
if (isIdentityOrder(BestOrder)) {
7106-
for (const std::pair<unsigned, TreeEntry *> &Op : Data.second)
7107-
Visited.insert(Op.second);
7104+
Visited.insert_range(llvm::make_second_range(Data.second));
71087105
continue;
71097106
}
71107107
fixupOrderingIndices(BestOrder);

llvm/lib/Transforms/Vectorize/VPlanSLP.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,9 @@ class VPInterleavedAccessInfo {
5050
VPInterleavedAccessInfo(VPlan &Plan, InterleavedAccessInfo &IAI);
5151

5252
~VPInterleavedAccessInfo() {
53-
SmallPtrSet<InterleaveGroup<VPInstruction> *, 4> DelSet;
5453
// Avoid releasing a pointer twice.
55-
for (auto &I : InterleaveGroupMap)
56-
DelSet.insert(I.second);
54+
SmallPtrSet<InterleaveGroup<VPInstruction> *, 4> DelSet(
55+
llvm::from_range, llvm::make_second_range(InterleaveGroupMap));
5756
for (auto *Ptr : DelSet)
5857
delete Ptr;
5958
}

llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,10 +217,8 @@ bool TypeSetByHwMode::operator==(const TypeSetByHwMode &VTS) const {
217217
return false;
218218

219219
SmallSet<unsigned, 4> Modes;
220-
for (auto &I : *this)
221-
Modes.insert(I.first);
222-
for (const auto &I : VTS)
223-
Modes.insert(I.first);
220+
Modes.insert_range(llvm::make_first_range(*this));
221+
Modes.insert_range(llvm::make_first_range(VTS));
224222

225223
if (HaveDefault) {
226224
// Both sets have default mode.

llvm/utils/TableGen/Common/CodeGenRegisters.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -598,8 +598,7 @@ void CodeGenRegister::addSubRegsPreOrder(
598598
SR->addSubRegsPreOrder(OSet, RegBank);
599599
}
600600
// Add any secondary sub-registers that weren't part of the explicit tree.
601-
for (auto SubReg : SubRegs)
602-
OSet.insert(SubReg.second);
601+
OSet.insert_range(llvm::make_second_range(SubRegs));
603602
}
604603

605604
// Get the sum of this register's unit weights.

0 commit comments

Comments
 (0)