Skip to content

Commit 40d251d

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

File tree

12 files changed

+22
-44
lines changed

12 files changed

+22
-44
lines changed

llvm/include/llvm/Transforms/IPO/Attributor.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5103,8 +5103,7 @@ template <typename MemberTy> struct PotentialValuesState : AbstractState {
51035103
indicatePessimisticFixpoint();
51045104
return;
51055105
}
5106-
for (const MemberTy &C : R.Set)
5107-
Set.insert(C);
5106+
Set.insert_range(R.Set);
51085107
UndefIsContained |= R.undefIsContained();
51095108
checkAndInvalidate();
51105109
}

llvm/include/llvm/Transforms/Utils/LockstepReverseIterator.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@ class LockstepReverseIterator
5757
Fail = false;
5858
if constexpr (!EarlyFailure) {
5959
this->ActiveBlocks.clear();
60-
for (BasicBlock *BB : Blocks)
61-
this->ActiveBlocks.insert(BB);
60+
this->ActiveBlocks.insert_range(Blocks);
6261
}
6362
Insts.clear();
6463
for (BasicBlock *BB : Blocks) {

llvm/lib/ExecutionEngine/MCJIT/MCJIT.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,7 @@ class MCJIT : public ExecutionEngine {
150150
}
151151

152152
void markAllLoadedModulesAsFinalized() {
153-
for (Module *M : LoadedModules)
154-
FinalizedModules.insert(M);
153+
FinalizedModules.insert_range(LoadedModules);
155154
LoadedModules.clear();
156155
}
157156

llvm/lib/ExecutionEngine/Orc/Core.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1261,8 +1261,7 @@ JITDylib::RemoveTrackerResult JITDylib::IL_removeTracker(ResourceTracker &RT) {
12611261
if (&RT == DefaultTracker.get()) {
12621262
SymbolNameSet TrackedSymbols;
12631263
for (auto &KV : TrackerSymbols)
1264-
for (auto &Sym : KV.second)
1265-
TrackedSymbols.insert(Sym);
1264+
TrackedSymbols.insert_range(KV.second);
12661265

12671266
for (auto &KV : Symbols) {
12681267
auto &Sym = KV.first;
@@ -1346,8 +1345,7 @@ void JITDylib::transferTracker(ResourceTracker &DstRT, ResourceTracker &SrcRT) {
13461345
if (DstMRs.empty())
13471346
DstMRs = std::move(SrcMRs);
13481347
else
1349-
for (auto *MR : SrcMRs)
1350-
DstMRs.insert(MR);
1348+
DstMRs.insert_range(SrcMRs);
13511349
// Erase SrcRT entry in TrackerMRs. Use &SrcRT key rather than iterator I
13521350
// for this, since I may have been invalidated by 'TrackerMRs[&DstRT]'.
13531351
TrackerMRs.erase(&SrcRT);
@@ -1371,8 +1369,7 @@ void JITDylib::transferTracker(ResourceTracker &DstRT, ResourceTracker &SrcRT) {
13711369

13721370
SymbolNameSet CurrentlyTrackedSymbols;
13731371
for (auto &KV : TrackerSymbols)
1374-
for (auto &Sym : KV.second)
1375-
CurrentlyTrackedSymbols.insert(Sym);
1372+
CurrentlyTrackedSymbols.insert_range(KV.second);
13761373

13771374
for (auto &KV : Symbols) {
13781375
auto &Sym = KV.first;

llvm/lib/ExecutionEngine/Orc/LinkGraphLinkingLayer.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -396,16 +396,13 @@ class LinkGraphLinkingLayer::JITLinkCtx final : public JITLinkContext {
396396

397397
for (auto *FB : BI.AnonEdges) {
398398
auto &FBI = BlockInfos[FB];
399-
for (auto *BB : BI.AnonBackEdges)
400-
FBI.AnonBackEdges.insert(BB);
399+
FBI.AnonBackEdges.insert_range(BI.AnonBackEdges);
401400
}
402401

403402
for (auto *BB : BI.AnonBackEdges) {
404403
auto &BBI = BlockInfos[BB];
405-
for (auto *SD : BI.SymbolDeps)
406-
BBI.SymbolDeps.insert(SD);
407-
for (auto *FB : BI.AnonEdges)
408-
BBI.AnonEdges.insert(FB);
404+
BBI.SymbolDeps.insert_range(BI.SymbolDeps);
405+
BBI.AnonEdges.insert_range(BI.AnonEdges);
409406
}
410407
}
411408

llvm/lib/FileCheck/FileCheck.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2491,14 +2491,10 @@ static bool ValidatePrefixes(StringRef Kind, StringSet<> &UniquePrefixes,
24912491
bool FileCheck::ValidateCheckPrefixes() {
24922492
StringSet<> UniquePrefixes;
24932493
// Add default prefixes to catch user-supplied duplicates of them below.
2494-
if (Req.CheckPrefixes.empty()) {
2495-
for (const char *Prefix : DefaultCheckPrefixes)
2496-
UniquePrefixes.insert(Prefix);
2497-
}
2498-
if (Req.CommentPrefixes.empty()) {
2499-
for (const char *Prefix : DefaultCommentPrefixes)
2500-
UniquePrefixes.insert(Prefix);
2501-
}
2494+
if (Req.CheckPrefixes.empty())
2495+
UniquePrefixes.insert_range(DefaultCheckPrefixes);
2496+
if (Req.CommentPrefixes.empty())
2497+
UniquePrefixes.insert_range(DefaultCommentPrefixes);
25022498
// Do not validate the default prefixes, or diagnostics about duplicates might
25032499
// incorrectly indicate that they were supplied by the user.
25042500
if (!ValidatePrefixes("check", UniquePrefixes, Req.CheckPrefixes))

llvm/lib/IR/Assumptions.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ DenseSet<StringRef> getAssumptions(const Attribute &A) {
4242
SmallVector<StringRef, 8> Strings;
4343
A.getValueAsString().split(Strings, ",");
4444

45-
for (StringRef Str : Strings)
46-
Assumptions.insert(Str);
45+
Assumptions.insert_range(Strings);
4746
return Assumptions;
4847
}
4948

llvm/lib/LTO/LTOCodeGenerator.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,7 @@ LTOCodeGenerator::LTOCodeGenerator(LLVMContext &Context)
142142
LTOCodeGenerator::~LTOCodeGenerator() = default;
143143

144144
void LTOCodeGenerator::setAsmUndefinedRefs(LTOModule *Mod) {
145-
for (const StringRef &Undef : Mod->getAsmUndefinedRefs())
146-
AsmUndefinedRefs.insert(Undef);
145+
AsmUndefinedRefs.insert_range(Mod->getAsmUndefinedRefs());
147146
}
148147

149148
bool LTOCodeGenerator::addModule(LTOModule *Mod) {

llvm/lib/LTO/ThinLTOCodeGenerator.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,8 +1057,7 @@ void ThinLTOCodeGenerator::run() {
10571057
std::map<ValueInfo, std::vector<VTableSlotSummary>> LocalWPDTargetsMap;
10581058
std::set<GlobalValue::GUID> ExportedGUIDs;
10591059
runWholeProgramDevirtOnIndex(*Index, ExportedGUIDs, LocalWPDTargetsMap);
1060-
for (auto GUID : ExportedGUIDs)
1061-
GUIDPreservedSymbols.insert(GUID);
1060+
GUIDPreservedSymbols.insert_range(ExportedGUIDs);
10621061

10631062
// Compute prevailing symbols
10641063
DenseMap<GlobalValue::GUID, const GlobalValueSummary *> PrevailingCopy;

llvm/tools/bugpoint/CrashDebugger.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -417,9 +417,8 @@ void simpleSimplifyCfg(Function &F, SmallVectorImpl<BasicBlock *> &BBs) {
417417
// undefined behavior into unreachables, but bugpoint was the thing that
418418
// generated the undefined behavior, and we don't want it to kill the entire
419419
// program.
420-
SmallPtrSet<BasicBlock *, 16> Visited;
421-
for (auto *BB : depth_first(&F.getEntryBlock()))
422-
Visited.insert(BB);
420+
SmallPtrSet<BasicBlock *, 16> Visited(llvm::from_range,
421+
depth_first(&F.getEntryBlock()));
423422

424423
SmallVector<BasicBlock *, 16> Unreachable;
425424
for (auto &BB : F)
@@ -917,9 +916,7 @@ bool ReduceCrashingNamedMD::TestNamedMDs(std::vector<std::string> &NamedMDs) {
917916
outs() << ": ";
918917

919918
// Make a StringMap for faster lookup
920-
StringSet<> Names;
921-
for (const std::string &Name : NamedMDs)
922-
Names.insert(Name);
919+
StringSet<> Names(llvm::from_range, NamedMDs);
923920

924921
// First collect all the metadata to delete in a vector, then
925922
// delete them all at once to avoid invalidating the iterator

llvm/tools/llvm-reduce/ReducerWorkItem.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -343,11 +343,9 @@ static std::unique_ptr<MachineFunction> cloneMF(MachineFunction *SrcMF,
343343
}
344344
}
345345

346-
DenseSet<const uint32_t *> ConstRegisterMasks;
347-
348346
// Track predefined/named regmasks which we ignore.
349-
for (const uint32_t *Mask : TRI->getRegMasks())
350-
ConstRegisterMasks.insert(Mask);
347+
DenseSet<const uint32_t *> ConstRegisterMasks(llvm::from_range,
348+
TRI->getRegMasks());
351349

352350
// Clone instructions.
353351
for (auto &SrcMBB : *SrcMF) {

llvm/tools/llvm-reduce/deltas/ReduceRegisterMasks.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ static void reduceMasksInFunction(Oracle &O, MachineFunction &MF) {
2424

2525
// Track predefined/named regmasks which we ignore.
2626
const unsigned NumRegs = TRI->getNumRegs();
27-
for (const uint32_t *Mask : TRI->getRegMasks())
28-
ConstRegisterMasks.insert(Mask);
27+
ConstRegisterMasks.insert_range(TRI->getRegMasks());
2928

3029
for (MachineBasicBlock &MBB : MF) {
3130
for (MachineInstr &MI : MBB) {

0 commit comments

Comments
 (0)