Skip to content

Commit 73dc2af

Browse files
[Transforms] Use *Set::insert_range (NFC) (#132652)
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 943a707 commit 73dc2af

19 files changed

+29
-62
lines changed

llvm/lib/Transforms/IPO/FunctionAttrs.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1467,8 +1467,7 @@ static bool isFunctionMallocLike(Function *F, const SCCNodeSet &SCCNodes) {
14671467
}
14681468
case Instruction::PHI: {
14691469
PHINode *PN = cast<PHINode>(RVI);
1470-
for (Value *IncValue : PN->incoming_values())
1471-
FlowsToReturn.insert(IncValue);
1470+
FlowsToReturn.insert_range(PN->incoming_values());
14721471
continue;
14731472
}
14741473

llvm/lib/Transforms/IPO/FunctionImport.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1219,14 +1219,11 @@ void llvm::ComputeCrossModuleImport(
12191219
// we convert such variables initializers to "zeroinitializer".
12201220
// See processGlobalForThinLTO.
12211221
if (!Index.isWriteOnly(GVS))
1222-
for (const auto &VI : GVS->refs())
1223-
NewExports.insert(VI);
1222+
NewExports.insert_range(GVS->refs());
12241223
} else {
12251224
auto *FS = cast<FunctionSummary>(S);
1226-
for (const auto &Edge : FS->calls())
1227-
NewExports.insert(Edge.first);
1228-
for (const auto &Ref : FS->refs())
1229-
NewExports.insert(Ref);
1225+
NewExports.insert_range(llvm::make_first_range(FS->calls()));
1226+
NewExports.insert_range(FS->refs());
12301227
}
12311228
}
12321229
// Prune list computed above to only include values defined in the

llvm/lib/Transforms/IPO/LowerTypeTests.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1866,8 +1866,7 @@ LowerTypeTestsModule::LowerTypeTestsModule(
18661866
if (GlobalAnnotation && GlobalAnnotation->hasInitializer()) {
18671867
const ConstantArray *CA =
18681868
cast<ConstantArray>(GlobalAnnotation->getInitializer());
1869-
for (Value *Op : CA->operands())
1870-
FunctionAnnotations.insert(Op);
1869+
FunctionAnnotations.insert_range(CA->operands());
18711870
}
18721871
}
18731872

llvm/lib/Transforms/IPO/PartialInlining.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -490,8 +490,7 @@ PartialInlinerImpl::computeOutliningColdRegionsInfo(
490490
// candidate for outlining. In the future, we may want to look
491491
// at inner regions because the outer region may have live-exit
492492
// variables.
493-
for (auto *BB : DominateVector)
494-
VisitedSet.insert(BB);
493+
VisitedSet.insert_range(DominateVector);
495494

496495
// ReturnBlock here means the block after the outline call
497496
BasicBlock *ReturnBlock = ExitBlock->getSingleSuccessor();
@@ -593,9 +592,7 @@ PartialInlinerImpl::computeOutliningInfo(Function &F) const {
593592
// {ReturnBlock, NonReturnBlock}
594593
assert(OutliningInfo->Entries[0] == &F.front() &&
595594
"Function Entry must be the first in Entries vector");
596-
DenseSet<BasicBlock *> Entries;
597-
for (BasicBlock *E : OutliningInfo->Entries)
598-
Entries.insert(E);
595+
DenseSet<BasicBlock *> Entries(llvm::from_range, OutliningInfo->Entries);
599596

600597
// Returns true of BB has Predecessor which is not
601598
// in Entries set.

llvm/lib/Transforms/Instrumentation/ControlHeightReduction.cpp

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -881,11 +881,8 @@ void CHR::checkScopeHoistable(CHRScope *Scope) {
881881
// Avoid a data dependence from a select or a branch to a(nother)
882882
// select. Note no instruction can't data-depend on a branch (a branch
883883
// instruction doesn't produce a value).
884-
DenseSet<Instruction *> Unhoistables;
885884
// Initialize Unhoistables with the selects.
886-
for (SelectInst *SI : Selects) {
887-
Unhoistables.insert(SI);
888-
}
885+
DenseSet<Instruction *> Unhoistables(llvm::from_range, Selects);
889886
// Remove Selects that can't be hoisted.
890887
for (auto it = Selects.begin(); it != Selects.end(); ) {
891888
SelectInst *SI = *it;
@@ -1104,8 +1101,7 @@ static bool shouldSplit(Instruction *InsertPoint,
11041101
static void getSelectsInScope(CHRScope *Scope,
11051102
DenseSet<Instruction *> &Output) {
11061103
for (RegInfo &RI : Scope->RegInfos)
1107-
for (SelectInst *SI : RI.Selects)
1108-
Output.insert(SI);
1104+
Output.insert_range(RI.Selects);
11091105
for (CHRScope *Sub : Scope->Subs)
11101106
getSelectsInScope(Sub, Output);
11111107
}
@@ -1370,11 +1366,8 @@ void CHR::setCHRRegions(CHRScope *Scope, CHRScope *OutermostScope) {
13701366
// Put the biased selects in Unhoistables because they should stay where they
13711367
// are and constant-folded after CHR (in case one biased select or a branch
13721368
// can depend on another biased select.)
1373-
for (RegInfo &RI : Scope->RegInfos) {
1374-
for (SelectInst *SI : RI.Selects) {
1375-
Unhoistables.insert(SI);
1376-
}
1377-
}
1369+
for (RegInfo &RI : Scope->RegInfos)
1370+
Unhoistables.insert_range(RI.Selects);
13781371
Instruction *InsertPoint = OutermostScope->BranchInsertPoint;
13791372
for (RegInfo &RI : Scope->RegInfos) {
13801373
Region *R = RI.R;

llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -874,8 +874,7 @@ DataFlowSanitizer::DataFlowSanitizer(
874874
ABIList.set(
875875
SpecialCaseList::createOrDie(AllABIListFiles, *vfs::getRealFileSystem()));
876876

877-
for (StringRef v : ClCombineTaintLookupTables)
878-
CombineTaintLookupTableNames.insert(v);
877+
CombineTaintLookupTableNames.insert_range(ClCombineTaintLookupTables);
879878
}
880879

881880
TransformedFunction DataFlowSanitizer::getCustomFunctionType(FunctionType *T) {

llvm/lib/Transforms/Instrumentation/IndirectCallPromotion.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,8 +1003,7 @@ static bool promoteIndirectCalls(Module &M, ProfileSummaryInfo *PSI, bool InLTO,
10031003
if (EnableVTableProfileUse) {
10041004
computeVirtualCallSiteTypeInfoMap(M, MAM, VirtualCSInfo);
10051005

1006-
for (StringRef Str : ICPIgnoredBaseTypes)
1007-
IgnoredBaseTypes.insert(Str);
1006+
IgnoredBaseTypes.insert_range(ICPIgnoredBaseTypes);
10081007
}
10091008

10101009
// VTableAddressPointOffsetVal stores the vtable address points. The vtable

llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -957,8 +957,7 @@ struct TransformDFA {
957957
DefMap NewDefs;
958958

959959
SmallSet<BasicBlock *, 16> BlocksToClean;
960-
for (BasicBlock *BB : successors(SwitchBlock))
961-
BlocksToClean.insert(BB);
960+
BlocksToClean.insert_range(successors(SwitchBlock));
962961

963962
for (ThreadingPath &TPath : SwitchPaths->getThreadingPaths()) {
964963
createExitPath(NewDefs, TPath, DuplicateMap, BlocksToClean, &DTU);

llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1824,8 +1824,7 @@ struct DSEState {
18241824
if (!DT.isReachableFromEntry(Current))
18251825
continue;
18261826

1827-
for (BasicBlock *Pred : predecessors(Current))
1828-
WorkList.insert(Pred);
1827+
WorkList.insert_range(predecessors(Current));
18291828

18301829
if (WorkList.size() >= MemorySSAPathCheckLimit)
18311830
return std::nullopt;

llvm/lib/Transforms/Scalar/GVNSink.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -566,8 +566,7 @@ class GVNSink {
566566
for (PHINode &PN : BB->phis()) {
567567
auto MPHI = ModelledPHI(&PN, RPOTOrder);
568568
PHIs.insert(MPHI);
569-
for (auto *V : MPHI.getValues())
570-
PHIContents.insert(V);
569+
PHIContents.insert_range(MPHI.getValues());
571570
}
572571
}
573572

0 commit comments

Comments
 (0)