Skip to content

Commit 1617f90

Browse files
[Analysis] Use *Set::insert_range (NFC) (#132878)
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 8352ca0 commit 1617f90

File tree

7 files changed

+9
-19
lines changed

7 files changed

+9
-19
lines changed

llvm/lib/Analysis/CGSCCPassManager.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,8 +1071,7 @@ static LazyCallGraph::SCC &updateCGAndAnalysisManagerForPass(
10711071

10721072
// We added a ref edge earlier for new call edges, promote those to call edges
10731073
// alongside PromotedRefTargets.
1074-
for (Node *E : NewCallEdges)
1075-
PromotedRefTargets.insert(E);
1074+
PromotedRefTargets.insert_range(NewCallEdges);
10761075

10771076
// Now promote ref edges into call edges.
10781077
for (Node *CallTarget : PromotedRefTargets) {

llvm/lib/Analysis/FunctionPropertiesAnalysis.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,8 +365,7 @@ FunctionPropertiesUpdater::FunctionPropertiesUpdater(
365365
// finish().
366366
Successors.erase(&CallSiteBB);
367367

368-
for (const auto *BB : Successors)
369-
LikelyToChangeBBs.insert(BB);
368+
LikelyToChangeBBs.insert_range(Successors);
370369

371370
// Commit the change. While some of the BBs accounted for above may play dual
372371
// role - e.g. caller's entry BB may be the same as the callsite BB - set

llvm/lib/Analysis/InlineCost.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2870,8 +2870,7 @@ InlineResult CallAnalyzer::analyze() {
28702870

28712871
// If we're unable to select a particular successor, just count all of
28722872
// them.
2873-
for (BasicBlock *Succ : successors(BB))
2874-
BBWorklist.insert(Succ);
2873+
BBWorklist.insert_range(successors(BB));
28752874

28762875
onBlockAnalyzed(BB);
28772876
}

llvm/lib/Analysis/MemorySSAUpdater.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -670,9 +670,8 @@ void MemorySSAUpdater::updateForClonedLoop(const LoopBlocksRPO &LoopBlocks,
670670
ArrayRef<BasicBlock *> ExitBlocks,
671671
const ValueToValueMapTy &VMap,
672672
bool IgnoreIncomingWithNoClones) {
673-
SmallSetVector<BasicBlock *, 16> Blocks;
674-
for (BasicBlock *BB : concat<BasicBlock *const>(LoopBlocks, ExitBlocks))
675-
Blocks.insert(BB);
673+
SmallSetVector<BasicBlock *, 16> Blocks(
674+
llvm::from_range, concat<BasicBlock *const>(LoopBlocks, ExitBlocks));
676675

677676
auto IsInClonedRegion = [&](BasicBlock *BB) { return Blocks.contains(BB); };
678677

llvm/lib/Analysis/ModuleSummaryAnalysis.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -637,12 +637,10 @@ static void computeFunctionSummary(
637637
// All new reference edges inserted in two loops below are either
638638
// read or write only. They will be grouped in the end of RefEdges
639639
// vector, so we can use a single integer value to identify them.
640-
for (const auto &VI : LoadRefEdges)
641-
RefEdges.insert(VI);
640+
RefEdges.insert_range(LoadRefEdges);
642641

643642
unsigned FirstWORef = RefEdges.size();
644-
for (const auto &VI : StoreRefEdges)
645-
RefEdges.insert(VI);
643+
RefEdges.insert_range(StoreRefEdges);
646644

647645
Refs = RefEdges.takeVector();
648646
for (; RefCnt < FirstWORef; ++RefCnt)

llvm/lib/Analysis/StackSafetyAnalysis.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -672,8 +672,7 @@ void StackSafetyDataFlowAnalysis<CalleeTy>::updateOneNode(
672672
<< (UpdateToFullSet ? ", full-set" : "") << "] " << &FS
673673
<< "\n");
674674
// Callers of this function may need updating.
675-
for (auto &CallerID : Callers[Callee])
676-
WorkList.insert(CallerID);
675+
WorkList.insert_range(Callers[Callee]);
677676

678677
++FS.UpdateCount;
679678
}

llvm/lib/Analysis/SyntheticCountsUtils.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,9 @@ template <typename CallGraphType>
2323
void SyntheticCountsUtils<CallGraphType>::propagateFromSCC(
2424
const SccTy &SCC, GetProfCountTy GetProfCount, AddCountTy AddCount) {
2525

26-
DenseSet<NodeRef> SCCNodes;
26+
DenseSet<NodeRef> SCCNodes(llvm::from_range, SCC);
2727
SmallVector<std::pair<NodeRef, EdgeRef>, 8> SCCEdges, NonSCCEdges;
2828

29-
for (auto &Node : SCC)
30-
SCCNodes.insert(Node);
31-
3229
// Partition the edges coming out of the SCC into those whose destination is
3330
// in the SCC and the rest.
3431
for (const auto &Node : SCCNodes) {

0 commit comments

Comments
 (0)