Skip to content

Commit 0dcc201

Browse files
[Transforms] Use *Set::insert_range (NFC) (#132056)
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 5ac8c52 commit 0dcc201

29 files changed

+69
-81
lines changed

llvm/lib/Transforms/IPO/Attributor.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -583,9 +583,9 @@ static bool getPotentialCopiesOfMemoryValue(
583583
UsedAssumedInformation = true;
584584
A.recordDependence(*PI, QueryingAA, DepClassTy::OPTIONAL);
585585
}
586-
PotentialCopies.insert(NewCopies.begin(), NewCopies.end());
586+
PotentialCopies.insert_range(NewCopies);
587587
if (PotentialValueOrigins)
588-
PotentialValueOrigins->insert(NewCopyOrigins.begin(), NewCopyOrigins.end());
588+
PotentialValueOrigins->insert_range(NewCopyOrigins);
589589

590590
return true;
591591
}
@@ -2123,7 +2123,7 @@ void Attributor::runTillFixpoint() {
21232123

21242124
SmallVector<AbstractAttribute *, 32> ChangedAAs;
21252125
SetVector<AbstractAttribute *> Worklist, InvalidAAs;
2126-
Worklist.insert(DG.SyntheticRoot.begin(), DG.SyntheticRoot.end());
2126+
Worklist.insert_range(DG.SyntheticRoot);
21272127

21282128
do {
21292129
// Remember the size to determine new attributes.
@@ -2200,9 +2200,8 @@ void Attributor::runTillFixpoint() {
22002200
// Reset the work list and repopulate with the changed abstract attributes.
22012201
// Note that dependent ones are added above.
22022202
Worklist.clear();
2203-
Worklist.insert(ChangedAAs.begin(), ChangedAAs.end());
2204-
Worklist.insert(QueryAAsAwaitingUpdate.begin(),
2205-
QueryAAsAwaitingUpdate.end());
2203+
Worklist.insert_range(ChangedAAs);
2204+
Worklist.insert_range(QueryAAsAwaitingUpdate);
22062205
QueryAAsAwaitingUpdate.clear();
22072206

22082207
} while (!Worklist.empty() && (IterationCounter++ < MaxIterations));

llvm/lib/Transforms/IPO/AttributorAttributes.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3735,7 +3735,7 @@ struct AAIntraFnReachabilityFunction final
37353735
}
37363736
}
37373737

3738-
DeadEdges.insert(LocalDeadEdges.begin(), LocalDeadEdges.end());
3738+
DeadEdges.insert_range(LocalDeadEdges);
37393739
return rememberResult(A, RQITy::Reachable::No, RQI, UsedExclusionSet,
37403740
IsTemporaryRQI);
37413741
}
@@ -12221,8 +12221,7 @@ struct AAIndirectCallInfoCallSite : public AAIndirectCallInfo {
1222112221
} else if (A.isClosedWorldModule()) {
1222212222
ArrayRef<Function *> IndirectlyCallableFunctions =
1222312223
A.getInfoCache().getIndirectlyCallableFunctions(A);
12224-
PotentialCallees.insert(IndirectlyCallableFunctions.begin(),
12225-
IndirectlyCallableFunctions.end());
12224+
PotentialCallees.insert_range(IndirectlyCallableFunctions);
1222612225
}
1222712226

1222812227
if (PotentialCallees.empty())

llvm/lib/Transforms/IPO/FunctionImport.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1239,7 +1239,7 @@ void llvm::ComputeCrossModuleImport(
12391239
else
12401240
++EI;
12411241
}
1242-
ELI.second.insert(NewExports.begin(), NewExports.end());
1242+
ELI.second.insert_range(NewExports);
12431243
}
12441244

12451245
assert(checkVariableImport(Index, ImportLists, ExportLists));

llvm/lib/Transforms/IPO/GlobalDCE.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ void GlobalDCEPass::ComputeDependencies(Value *V,
7373
for (User *CEUser : CE->users())
7474
ComputeDependencies(CEUser, LocalDeps);
7575
}
76-
Deps.insert(LocalDeps.begin(), LocalDeps.end());
76+
Deps.insert_range(LocalDeps);
7777
}
7878
}
7979

llvm/lib/Transforms/IPO/HotColdSplitting.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -733,7 +733,7 @@ bool HotColdSplitting::outlineColdRegions(Function &F, bool HasProfileSummary) {
733733
none_of(SubRegion, [&](BasicBlock *Block) {
734734
return ColdBlocks.contains(Block);
735735
})) {
736-
ColdBlocks.insert(SubRegion.begin(), SubRegion.end());
736+
ColdBlocks.insert_range(SubRegion);
737737

738738
LLVM_DEBUG({
739739
for (auto *Block : SubRegion)

llvm/lib/Transforms/IPO/MemProfContextDisambiguation.cpp

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -360,8 +360,7 @@ class CallsiteContextGraph {
360360
? CallerEdges
361361
: std::vector<std::shared_ptr<ContextEdge>>());
362362
for (const auto &Edge : Edges)
363-
ContextIds.insert(Edge->getContextIds().begin(),
364-
Edge->getContextIds().end());
363+
ContextIds.insert_range(Edge->getContextIds());
365364
return ContextIds;
366365
}
367366

@@ -1372,7 +1371,7 @@ void CallsiteContextGraph<DerivedCCG, FuncTy, CallTy>::
13721371
for (auto Id : ContextIds)
13731372
if (auto NewId = OldToNewContextIds.find(Id);
13741373
NewId != OldToNewContextIds.end())
1375-
NewIds.insert(NewId->second.begin(), NewId->second.end());
1374+
NewIds.insert_range(NewId->second);
13761375
return NewIds;
13771376
};
13781377

@@ -1389,7 +1388,7 @@ void CallsiteContextGraph<DerivedCCG, FuncTy, CallTy>::
13891388
// Only need to recursively iterate to NextNode via this caller edge if
13901389
// it resulted in any added ids to NextNode.
13911390
if (!NewIdsToAdd.empty()) {
1392-
Edge->getContextIds().insert(NewIdsToAdd.begin(), NewIdsToAdd.end());
1391+
Edge->getContextIds().insert_range(NewIdsToAdd);
13931392
UpdateCallers(NextNode, Visited, UpdateCallers);
13941393
}
13951394
}
@@ -2534,8 +2533,7 @@ bool CallsiteContextGraph<DerivedCCG, FuncTy, CallTy>::calleesMatch(
25342533
// If there is already an edge between these nodes, simply update it and
25352534
// return.
25362535
if (CurEdge) {
2537-
CurEdge->ContextIds.insert(Edge->ContextIds.begin(),
2538-
Edge->ContextIds.end());
2536+
CurEdge->ContextIds.insert_range(Edge->ContextIds);
25392537
CurEdge->AllocTypes |= Edge->AllocTypes;
25402538
return;
25412539
}
@@ -3281,8 +3279,7 @@ void CallsiteContextGraph<DerivedCCG, FuncTy, CallTy>::
32813279
if (ExistingEdgeToNewCallee) {
32823280
// Since we already have an edge to NewCallee, simply move the ids
32833281
// onto it, and remove the existing Edge.
3284-
ExistingEdgeToNewCallee->getContextIds().insert(ContextIdsToMove.begin(),
3285-
ContextIdsToMove.end());
3282+
ExistingEdgeToNewCallee->getContextIds().insert_range(ContextIdsToMove);
32863283
ExistingEdgeToNewCallee->AllocTypes |= Edge->AllocTypes;
32873284
assert(Edge->ContextIds == ContextIdsToMove);
32883285
removeEdgeFromGraph(Edge.get());
@@ -3302,8 +3299,7 @@ void CallsiteContextGraph<DerivedCCG, FuncTy, CallTy>::
33023299
if (ExistingEdgeToNewCallee) {
33033300
// Since we already have an edge to NewCallee, simply move the ids
33043301
// onto it.
3305-
ExistingEdgeToNewCallee->getContextIds().insert(ContextIdsToMove.begin(),
3306-
ContextIdsToMove.end());
3302+
ExistingEdgeToNewCallee->getContextIds().insert_range(ContextIdsToMove);
33073303
ExistingEdgeToNewCallee->AllocTypes |= CallerEdgeAllocType;
33083304
} else {
33093305
// Otherwise, create a new edge to NewCallee for the ids being moved.
@@ -3350,8 +3346,7 @@ void CallsiteContextGraph<DerivedCCG, FuncTy, CallTy>::
33503346
// removed none type edges after creating the clone. If we can't find
33513347
// a corresponding edge there, fall through to the cloning below.
33523348
if (auto *NewCalleeEdge = NewCallee->findEdgeFromCallee(CalleeToUse)) {
3353-
NewCalleeEdge->getContextIds().insert(EdgeContextIdsToMove.begin(),
3354-
EdgeContextIdsToMove.end());
3349+
NewCalleeEdge->getContextIds().insert_range(EdgeContextIdsToMove);
33553350
NewCalleeEdge->AllocTypes |= computeAllocType(EdgeContextIdsToMove);
33563351
continue;
33573352
}
@@ -3402,8 +3397,8 @@ void CallsiteContextGraph<DerivedCCG, FuncTy, CallTy>::
34023397
if (ExistingEdgeToNewCaller) {
34033398
// Since we already have an edge to NewCaller, simply move the ids
34043399
// onto it, and remove the existing Edge.
3405-
ExistingEdgeToNewCaller->getContextIds().insert(
3406-
Edge->getContextIds().begin(), Edge->getContextIds().end());
3400+
ExistingEdgeToNewCaller->getContextIds().insert_range(
3401+
Edge->getContextIds());
34073402
ExistingEdgeToNewCaller->AllocTypes |= Edge->AllocTypes;
34083403
Edge->ContextIds.clear();
34093404
Edge->AllocTypes = (uint8_t)AllocationType::None;
@@ -3465,8 +3460,7 @@ void CallsiteContextGraph<DerivedCCG, FuncTy, CallTy>::
34653460
// edge, this may not hold true when recursive handling enabled.
34663461
assert(IsNewNode || ExistingCallerEdge || AllowRecursiveCallsites);
34673462
if (ExistingCallerEdge) {
3468-
ExistingCallerEdge->getContextIds().insert(EdgeContextIdsToMove.begin(),
3469-
EdgeContextIdsToMove.end());
3463+
ExistingCallerEdge->getContextIds().insert_range(EdgeContextIdsToMove);
34703464
ExistingCallerEdge->AllocTypes |=
34713465
computeAllocType(EdgeContextIdsToMove);
34723466
continue;

llvm/lib/Transforms/IPO/MergeFunctions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ bool MergeFunctionsPass::runOnModule(Module &M) {
321321
SmallVector<GlobalValue *, 4> UsedV;
322322
collectUsedGlobalVariables(M, UsedV, /*CompilerUsed=*/false);
323323
collectUsedGlobalVariables(M, UsedV, /*CompilerUsed=*/true);
324-
MF.getUsed().insert(UsedV.begin(), UsedV.end());
324+
MF.getUsed().insert_range(UsedV);
325325
return MF.run(M);
326326
}
327327

llvm/lib/Transforms/IPO/OpenMPOpt.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,7 @@ struct BooleanStateWithSetVector : public BooleanState {
675675
/// "Clamp" this state with \p RHS.
676676
BooleanStateWithSetVector &operator^=(const BooleanStateWithSetVector &RHS) {
677677
BooleanState::operator^=(RHS);
678-
Set.insert(RHS.Set.begin(), RHS.Set.end());
678+
Set.insert_range(RHS.Set);
679679
return *this;
680680
}
681681

llvm/lib/Transforms/IPO/SampleProfileProbe.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,7 @@ void SampleProfileProber::computeBlocksToIgnore(
199199
computeEHOnlyBlocks(*F, BlocksAndCallsToIgnore);
200200
findUnreachableBlocks(BlocksAndCallsToIgnore);
201201

202-
BlocksToIgnore.insert(BlocksAndCallsToIgnore.begin(),
203-
BlocksAndCallsToIgnore.end());
202+
BlocksToIgnore.insert_range(BlocksAndCallsToIgnore);
204203

205204
// Handle the call-to-invoke conversion case: make sure that the probe id and
206205
// callsite id are consistent before and after the block split. For block

llvm/lib/Transforms/Instrumentation/BlockCoverageInference.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,10 +239,10 @@ void BlockCoverageInference::getReachableAvoiding(const BasicBlock &Start,
239239
Visited.insert(&Avoid);
240240
if (IsForward) {
241241
auto Range = depth_first_ext(&Start, Visited);
242-
Reachable.insert(Range.begin(), Range.end());
242+
Reachable.insert_range(Range);
243243
} else {
244244
auto Range = inverse_depth_first_ext(&Start, Visited);
245-
Reachable.insert(Range.begin(), Range.end());
245+
Reachable.insert_range(Range);
246246
}
247247
}
248248

0 commit comments

Comments
 (0)