Skip to content

Commit 5990056

Browse files
[llvm] Use *Set::insert_range (NFC) (#132325)
DenseSet, SmallPtrSet, SmallSet, SetVector, and StringSet recently gained C++23-style insert_range. This patch replaces: Dest.insert(Src.begin(), Src.end()); with: Dest.insert_range(Src); This patch does not touch custom begin like succ_begin for now.
1 parent 13bb2f4 commit 5990056

25 files changed

+39
-42
lines changed

llvm/include/llvm/Analysis/IVDescriptors.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class RecurrenceDescriptor {
8787
Kind(K), FMF(FMF), ExactFPMathInst(ExactFP), RecurrenceType(RT),
8888
IsSigned(Signed), IsOrdered(Ordered),
8989
MinWidthCastToRecurrenceType(MinWidthCastToRecurTy) {
90-
CastInsts.insert(CI.begin(), CI.end());
90+
CastInsts.insert_range(CI);
9191
}
9292

9393
/// This POD struct holds information about a potential recurrence operation.

llvm/lib/Analysis/MemorySSA.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1573,7 +1573,7 @@ void MemorySSA::buildMemorySSA(BatchAAResults &BAA, IterT Blocks) {
15731573
// the loop, to limit the scope of the renaming.
15741574
SmallVector<BasicBlock *> ExitBlocks;
15751575
L->getExitBlocks(ExitBlocks);
1576-
Visited.insert(ExitBlocks.begin(), ExitBlocks.end());
1576+
Visited.insert_range(ExitBlocks);
15771577
renamePass(DT->getNode(L->getLoopPreheader()), LiveOnEntryDef.get(),
15781578
Visited);
15791579
} else {

llvm/lib/Analysis/PhiValues.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ void PhiValues::processPhi(const PHINode *Phi,
100100
if (OpDepthNumber != RootDepthNumber) {
101101
auto It = ReachableMap.find(OpDepthNumber);
102102
if (It != ReachableMap.end())
103-
Reachable.insert(It->second.begin(), It->second.end());
103+
Reachable.insert_range(It->second);
104104
}
105105
} else
106106
Reachable.insert(Op);

llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1170,7 +1170,7 @@ DIE *DwarfCompileUnit::createAndAddScopeChildren(LexicalScope *Scope,
11701170
// should be emitted for subprograms in this CU.
11711171
if (!includeMinimalInlineScopes() && !Scope->getInlinedAt()) {
11721172
auto &LocalDecls = DD->getLocalDeclsForScope(Scope->getScopeNode());
1173-
DeferredLocalDecls.insert(LocalDecls.begin(), LocalDecls.end());
1173+
DeferredLocalDecls.insert_range(LocalDecls);
11741174
}
11751175

11761176
// Emit inner lexical scopes.

llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -706,8 +706,7 @@ static void interpretValues(const MachineInstr *CurMI,
706706
getForwardingRegsDefinedByMI(*CurMI, FwdRegDefs);
707707
if (FwdRegDefs.empty()) {
708708
// Any definitions by this instruction will clobber earlier reg movements.
709-
ClobberedRegUnits.insert(NewClobberedRegUnits.begin(),
710-
NewClobberedRegUnits.end());
709+
ClobberedRegUnits.insert_range(NewClobberedRegUnits);
711710
return;
712711
}
713712

@@ -756,8 +755,7 @@ static void interpretValues(const MachineInstr *CurMI,
756755
ForwardedRegWorklist.erase(ParamFwdReg);
757756

758757
// Any definitions by this instruction will clobber earlier reg movements.
759-
ClobberedRegUnits.insert(NewClobberedRegUnits.begin(),
760-
NewClobberedRegUnits.end());
758+
ClobberedRegUnits.insert_range(NewClobberedRegUnits);
761759

762760
// Now that we are done handling this instruction, add items from the
763761
// temporary worklist to the real one.

llvm/lib/CodeGen/CodeGenPrepare.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7577,7 +7577,7 @@ bool CodeGenPrepare::optimizeSelectInst(SelectInst *SI) {
75777577
FalseBlock = StartBlock;
75787578

75797579
SmallPtrSet<const Instruction *, 2> INS;
7580-
INS.insert(ASI.begin(), ASI.end());
7580+
INS.insert_range(ASI);
75817581
// Use reverse iterator because later select may use the value of the
75827582
// earlier select, and we need to propagate value through earlier select
75837583
// to get the PHI operand.

llvm/lib/CodeGen/InlineSpiller.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1461,7 +1461,7 @@ void HoistSpillHelper::getVisitOrders(
14611461
// with BBs containing hoisted spills which will be inserted to
14621462
// SpillsToKeep later during hoisting.
14631463
SpillsToKeep[MDT[Block]] = Register();
1464-
WorkSet.insert(NodesOnPath.begin(), NodesOnPath.end());
1464+
WorkSet.insert_range(NodesOnPath);
14651465
}
14661466
NodesOnPath.clear();
14671467
}

llvm/lib/CodeGen/InterleavedAccessPass.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ bool InterleavedAccessImpl::lowerInterleavedLoad(
349349
return !Extracts.empty() || BinOpShuffleChanged;
350350
}
351351

352-
DeadInsts.insert(Shuffles.begin(), Shuffles.end());
352+
DeadInsts.insert_range(Shuffles);
353353

354354
DeadInsts.insert(LI);
355355
return true;
@@ -703,7 +703,7 @@ bool InterleavedAccessImpl::lowerDeinterleaveIntrinsic(
703703
return false;
704704
}
705705

706-
DeadInsts.insert(DeinterleaveDeadInsts.begin(), DeinterleaveDeadInsts.end());
706+
DeadInsts.insert_range(DeinterleaveDeadInsts);
707707
// We now have a target-specific load, so delete the old one.
708708
DeadInsts.insert(cast<Instruction>(LoadedVal));
709709
return true;
@@ -757,7 +757,7 @@ bool InterleavedAccessImpl::lowerInterleaveIntrinsic(
757757

758758
// We now have a target-specific store, so delete the old one.
759759
DeadInsts.insert(cast<Instruction>(StoredBy));
760-
DeadInsts.insert(InterleaveDeadInsts.begin(), InterleaveDeadInsts.end());
760+
DeadInsts.insert_range(InterleaveDeadInsts);
761761
return true;
762762
}
763763

llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -918,7 +918,7 @@ class TransferTracker {
918918

919919
// Move set of active variables from one location to another.
920920
auto MovingVars = ActiveMLocs[Src];
921-
ActiveMLocs[Dst].insert(MovingVars.begin(), MovingVars.end());
921+
ActiveMLocs[Dst].insert_range(MovingVars);
922922
VarLocs[Dst.asU64()] = VarLocs[Src.asU64()];
923923

924924
// For each variable based on Src; create a location at Dst.
@@ -2581,7 +2581,7 @@ void InstrRefBasedLDV::placeMLocPHIs(
25812581
continue;
25822582
}
25832583

2584-
RegUnitsToPHIUp.insert(FoundRegUnits.begin(), FoundRegUnits.end());
2584+
RegUnitsToPHIUp.insert_range(FoundRegUnits);
25852585
}
25862586

25872587
// Lambda to fetch PHIs for a given location, and write into the PHIBlocks
@@ -3087,7 +3087,7 @@ void InstrRefBasedLDV::getBlocksForScope(
30873087
// VarLoc LiveDebugValues tracks variable locations that are defined in
30883088
// blocks not in scope. This is something we could legitimately ignore, but
30893089
// lets allow it for now for the sake of coverage.
3090-
BlocksToExplore.insert(AssignBlocks.begin(), AssignBlocks.end());
3090+
BlocksToExplore.insert_range(AssignBlocks);
30913091

30923092
// Storage for artificial blocks we intend to add to BlocksToExplore.
30933093
DenseSet<const MachineBasicBlock *> ToAdd;
@@ -3137,7 +3137,7 @@ void InstrRefBasedLDV::getBlocksForScope(
31373137
}
31383138
};
31393139

3140-
BlocksToExplore.insert(ToAdd.begin(), ToAdd.end());
3140+
BlocksToExplore.insert_range(ToAdd);
31413141
}
31423142

31433143
void InstrRefBasedLDV::buildVLocValueMap(

llvm/lib/CodeGen/MachineCopyPropagation.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,8 @@ class CopyTracker {
173173

174174
auto Dest = TRI.regunits(CopyOperands->Destination->getReg().asMCReg());
175175
auto Src = TRI.regunits(CopyOperands->Source->getReg().asMCReg());
176-
RegUnitsToInvalidate.insert(Dest.begin(), Dest.end());
177-
RegUnitsToInvalidate.insert(Src.begin(), Src.end());
176+
RegUnitsToInvalidate.insert_range(Dest);
177+
RegUnitsToInvalidate.insert_range(Src);
178178
};
179179

180180
for (MCRegUnit Unit : TRI.regunits(Reg)) {

llvm/lib/CodeGen/MachinePipeliner.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2132,7 +2132,7 @@ void SwingSchedulerDAG::groupRemainingNodes(NodeSetType &NodeSets) {
21322132
if (!Path.empty())
21332133
I.insert(Path.begin(), Path.end());
21342134
}
2135-
NodesAdded.insert(I.begin(), I.end());
2135+
NodesAdded.insert_range(I);
21362136
}
21372137

21382138
// Create a new node set with the connected nodes of any successor of a node
@@ -2246,12 +2246,12 @@ void SwingSchedulerDAG::computeNodeOrder(NodeSetType &NodeSets) {
22462246
OrderKind Order;
22472247
SmallSetVector<SUnit *, 8> N;
22482248
if (pred_L(NodeOrder, N, DDG.get()) && llvm::set_is_subset(N, Nodes)) {
2249-
R.insert(N.begin(), N.end());
2249+
R.insert_range(N);
22502250
Order = BottomUp;
22512251
LLVM_DEBUG(dbgs() << " Bottom up (preds) ");
22522252
} else if (succ_L(NodeOrder, N, DDG.get()) &&
22532253
llvm::set_is_subset(N, Nodes)) {
2254-
R.insert(N.begin(), N.end());
2254+
R.insert_range(N);
22552255
Order = TopDown;
22562256
LLVM_DEBUG(dbgs() << " Top down (succs) ");
22572257
} else if (isIntersect(N, Nodes, R)) {
@@ -2330,7 +2330,7 @@ void SwingSchedulerDAG::computeNodeOrder(NodeSetType &NodeSets) {
23302330
LLVM_DEBUG(dbgs() << "\n Switching order to bottom up ");
23312331
SmallSetVector<SUnit *, 8> N;
23322332
if (pred_L(NodeOrder, N, DDG.get(), &Nodes))
2333-
R.insert(N.begin(), N.end());
2333+
R.insert_range(N);
23342334
} else {
23352335
// Choose the node with the maximum depth. If more than one, choose
23362336
// the node with the maximum ZeroLatencyDepth. If still more than one,
@@ -2385,7 +2385,7 @@ void SwingSchedulerDAG::computeNodeOrder(NodeSetType &NodeSets) {
23852385
LLVM_DEBUG(dbgs() << "\n Switching order to top down ");
23862386
SmallSetVector<SUnit *, 8> N;
23872387
if (succ_L(NodeOrder, N, DDG.get(), &Nodes))
2388-
R.insert(N.begin(), N.end());
2388+
R.insert_range(N);
23892389
}
23902390
}
23912391
LLVM_DEBUG(dbgs() << "\nDone with Nodeset\n");

llvm/lib/CodeGen/MachineVerifier.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3286,7 +3286,7 @@ void MachineVerifier::calcRegsPassed() {
32863286
VRegs.add(PredInfo.vregsPassed);
32873287
}
32883288
Info.vregsPassed.reserve(VRegs.size());
3289-
Info.vregsPassed.insert(VRegs.begin(), VRegs.end());
3289+
Info.vregsPassed.insert_range(VRegs);
32903290
}
32913291
}
32923292

llvm/lib/CodeGen/RDFGraph.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1419,7 +1419,7 @@ void DataFlowGraph::recordDefsForDF(BlockRefsMap &PhiM,
14191419
for (unsigned i = 0; i < IDF.size(); ++i) {
14201420
auto F = MDF.find(IDF[i]);
14211421
if (F != MDF.end())
1422-
IDF.insert(F->second.begin(), F->second.end());
1422+
IDF.insert_range(F->second);
14231423
}
14241424

14251425
// Finally, add the set of defs to each block in the iterated dominance

llvm/lib/CodeGen/RDFLiveness.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,7 @@ void Liveness::computeLiveIns() {
763763
for (unsigned i = 0; i < IDFB.size(); ++i) {
764764
auto F2 = MDF.find(IDFB[i]);
765765
if (F2 != MDF.end())
766-
IDFB.insert(F2->second.begin(), F2->second.end());
766+
IDFB.insert_range(F2->second);
767767
}
768768
// Add B to the IDF(B). This will put B in the IIDF(B).
769769
IDFB.insert(&B);

llvm/lib/CodeGen/TailDuplicator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -876,7 +876,7 @@ bool TailDuplicator::tailDuplicate(bool IsSimple, MachineBasicBlock *TailBB,
876876
bool Changed = false;
877877
SmallSetVector<MachineBasicBlock *, 8> Preds;
878878
if (CandidatePtr)
879-
Preds.insert(CandidatePtr->begin(), CandidatePtr->end());
879+
Preds.insert_range(*CandidatePtr);
880880
else
881881
Preds.insert(TailBB->pred_begin(), TailBB->pred_end());
882882

llvm/lib/IR/LegacyPassManager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,7 @@ PMTopLevelManager::setLastUser(ArrayRef<Pass*> AnalysisPasses, Pass *P) {
606606
auto &LastUsedByAP = InversedLastUser[AP];
607607
for (Pass *L : LastUsedByAP)
608608
LastUser[L] = P;
609-
InversedLastUser[P].insert(LastUsedByAP.begin(), LastUsedByAP.end());
609+
InversedLastUser[P].insert_range(LastUsedByAP);
610610
LastUsedByAP.clear();
611611
}
612612
}

llvm/lib/IR/Metadata.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1636,7 +1636,7 @@ void Instruction::dropUnknownNonDebugMetadata(ArrayRef<unsigned> KnownIDs) {
16361636
return; // Nothing to remove!
16371637

16381638
SmallSet<unsigned, 32> KnownSet;
1639-
KnownSet.insert(KnownIDs.begin(), KnownIDs.end());
1639+
KnownSet.insert_range(KnownIDs);
16401640

16411641
// A DIAssignID attachment is debug metadata, don't drop it.
16421642
KnownSet.insert(LLVMContext::MD_DIAssignID);

llvm/lib/IR/ReplaceConstant.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ bool convertUsersOfConstantsToInstructions(ArrayRef<Constant *> Consts,
105105
auto NewInsts = expandUser(BI, C);
106106
for (auto *NI : NewInsts)
107107
NI->setDebugLoc(Loc);
108-
InstructionWorklist.insert(NewInsts.begin(), NewInsts.end());
108+
InstructionWorklist.insert_range(NewInsts);
109109
U.set(NewInsts.back());
110110
}
111111
}

llvm/lib/IR/SafepointIRVerifier.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ class CFGDeadness {
171171
// Do not need to mark all in and out edges dead
172172
// because BB is marked dead and this is enough
173173
// to run further.
174-
DeadBlocks.insert(Dom.begin(), Dom.end());
174+
DeadBlocks.insert_range(Dom);
175175

176176
// Figure out the dominance-frontier(D).
177177
for (BasicBlock *B : Dom)
@@ -750,7 +750,7 @@ void GCPtrTracker::gatherDominatingDefs(const BasicBlock *BB,
750750
auto BBS = getBasicBlockState(DTN->getBlock());
751751
assert(BBS && "immediate dominator cannot be dead for a live block");
752752
const auto &Defs = BBS->Contribution;
753-
Result.insert(Defs.begin(), Defs.end());
753+
Result.insert_range(Defs);
754754
// If this block is 'Cleared', then nothing LiveIn to this block can be
755755
// available after this block completes. Note: This turns out to be
756756
// really important for reducing memory consuption of the initial available

llvm/lib/TableGen/SetTheory.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ struct SequenceOp : public SetTheory::Operator {
228228
Expr->getAsString());
229229
// Try to reevaluate Rec in case it is a set.
230230
if (const RecVec *Result = ST.expand(Rec))
231-
Elts.insert(Result->begin(), Result->end());
231+
Elts.insert_range(*Result);
232232
else
233233
Elts.insert(Rec);
234234

@@ -283,7 +283,7 @@ void SetTheory::evaluate(const Init *Expr, RecSet &Elts, ArrayRef<SMLoc> Loc) {
283283
// A def in a list can be a just an element, or it may expand.
284284
if (const auto *Def = dyn_cast<DefInit>(Expr)) {
285285
if (const RecVec *Result = expand(Def->getDef()))
286-
return Elts.insert(Result->begin(), Result->end());
286+
return Elts.insert_range(*Result);
287287
Elts.insert(Def->getDef());
288288
return;
289289
}

llvm/tools/llvm-exegesis/lib/Clustering.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ void BenchmarkClustering::clusterizeDbScan(const size_t MinPts) {
149149

150150
// Process P's neighbors.
151151
SetVector<size_t, std::deque<size_t>> ToProcess;
152-
ToProcess.insert(Neighbors.begin(), Neighbors.end());
152+
ToProcess.insert_range(Neighbors);
153153
while (!ToProcess.empty()) {
154154
// Retrieve a point from the set.
155155
const size_t Q = *ToProcess.begin();
@@ -170,7 +170,7 @@ void BenchmarkClustering::clusterizeDbScan(const size_t MinPts) {
170170
// And extend to the neighbors of Q if the region is dense enough.
171171
rangeQuery(Q, Neighbors);
172172
if (Neighbors.size() + 1 >= MinPts) {
173-
ToProcess.insert(Neighbors.begin(), Neighbors.end());
173+
ToProcess.insert_range(Neighbors);
174174
}
175175
}
176176
}

llvm/tools/llvm-objdump/llvm-objdump.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3743,7 +3743,7 @@ int llvm_objdump_main(int argc, char **argv, const llvm::ToolContext &) {
37433743
return 2;
37443744
}
37453745

3746-
DisasmSymbolSet.insert(DisassembleSymbols.begin(), DisassembleSymbols.end());
3746+
DisasmSymbolSet.insert_range(DisassembleSymbols);
37473747

37483748
llvm::for_each(InputFilenames, dumpInput);
37493749

llvm/tools/llvm-profgen/ProfiledBinary.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,7 @@ void ProfiledBinary::load() {
242242
loadSymbolsFromDWARF(*cast<ObjectFile>(&ExeBinary));
243243
}
244244

245-
DisassembleFunctionSet.insert(DisassembleFunctions.begin(),
246-
DisassembleFunctions.end());
245+
DisassembleFunctionSet.insert_range(DisassembleFunctions);
247246

248247
if (auto *ELFObj = dyn_cast<ELFObjectFileBase>(Obj)) {
249248
checkPseudoProbe(ELFObj);

llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3322,7 +3322,7 @@ void CodeGenDAGPatterns::ParsePatternFragments(bool OutFrags) {
33223322
// Copy the args so we can take StringRefs to them.
33233323
auto ArgsCopy = Args;
33243324
SmallDenseSet<StringRef, 4> OperandsSet;
3325-
OperandsSet.insert(ArgsCopy.begin(), ArgsCopy.end());
3325+
OperandsSet.insert_range(ArgsCopy);
33263326

33273327
if (OperandsSet.count(""))
33283328
P->error("Cannot have unnamed 'node' values in pattern fragment!");

llvm/utils/TableGen/OptionParserEmitter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ static void emitOptionParser(const RecordKeeper &Records, raw_ostream &OS) {
281281

282282
DenseSet<StringRef> PrefixesUnionSet;
283283
for (const auto &[Prefix, _] : Prefixes)
284-
PrefixesUnionSet.insert(Prefix.begin(), Prefix.end());
284+
PrefixesUnionSet.insert_range(Prefix);
285285
SmallVector<StringRef> PrefixesUnion(PrefixesUnionSet.begin(),
286286
PrefixesUnionSet.end());
287287
array_pod_sort(PrefixesUnion.begin(), PrefixesUnion.end());

0 commit comments

Comments
 (0)