-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[Analysis] Use *Set::insert_range (NFC) #132878
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Analysis] Use *Set::insert_range (NFC) #132878
Conversation
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.
@llvm/pr-subscribers-llvm-analysis @llvm/pr-subscribers-mlgo Author: Kazu Hirata (kazutakahirata) ChangesWe can use *Set::insert_range to collapse: for (auto Elem : Range) down to: Set.insert_range(Range); In some cases, we can further fold that into the set declaration. Full diff: https://github.com/llvm/llvm-project/pull/132878.diff 7 Files Affected:
diff --git a/llvm/lib/Analysis/CGSCCPassManager.cpp b/llvm/lib/Analysis/CGSCCPassManager.cpp
index ab3a721d874a5..1f0cda7e3f91f 100644
--- a/llvm/lib/Analysis/CGSCCPassManager.cpp
+++ b/llvm/lib/Analysis/CGSCCPassManager.cpp
@@ -1071,8 +1071,7 @@ static LazyCallGraph::SCC &updateCGAndAnalysisManagerForPass(
// We added a ref edge earlier for new call edges, promote those to call edges
// alongside PromotedRefTargets.
- for (Node *E : NewCallEdges)
- PromotedRefTargets.insert(E);
+ PromotedRefTargets.insert_range(NewCallEdges);
// Now promote ref edges into call edges.
for (Node *CallTarget : PromotedRefTargets) {
diff --git a/llvm/lib/Analysis/FunctionPropertiesAnalysis.cpp b/llvm/lib/Analysis/FunctionPropertiesAnalysis.cpp
index 9389a109cfcb5..f5960073e93b6 100644
--- a/llvm/lib/Analysis/FunctionPropertiesAnalysis.cpp
+++ b/llvm/lib/Analysis/FunctionPropertiesAnalysis.cpp
@@ -365,8 +365,7 @@ FunctionPropertiesUpdater::FunctionPropertiesUpdater(
// finish().
Successors.erase(&CallSiteBB);
- for (const auto *BB : Successors)
- LikelyToChangeBBs.insert(BB);
+ LikelyToChangeBBs.insert_range(Successors);
// Commit the change. While some of the BBs accounted for above may play dual
// role - e.g. caller's entry BB may be the same as the callsite BB - set
diff --git a/llvm/lib/Analysis/InlineCost.cpp b/llvm/lib/Analysis/InlineCost.cpp
index df212eb31950d..e42b2bd82cf2e 100644
--- a/llvm/lib/Analysis/InlineCost.cpp
+++ b/llvm/lib/Analysis/InlineCost.cpp
@@ -2870,8 +2870,7 @@ InlineResult CallAnalyzer::analyze() {
// If we're unable to select a particular successor, just count all of
// them.
- for (BasicBlock *Succ : successors(BB))
- BBWorklist.insert(Succ);
+ BBWorklist.insert_range(successors(BB));
onBlockAnalyzed(BB);
}
diff --git a/llvm/lib/Analysis/MemorySSAUpdater.cpp b/llvm/lib/Analysis/MemorySSAUpdater.cpp
index 050b827388d3c..7c6b58cebfd87 100644
--- a/llvm/lib/Analysis/MemorySSAUpdater.cpp
+++ b/llvm/lib/Analysis/MemorySSAUpdater.cpp
@@ -670,9 +670,8 @@ void MemorySSAUpdater::updateForClonedLoop(const LoopBlocksRPO &LoopBlocks,
ArrayRef<BasicBlock *> ExitBlocks,
const ValueToValueMapTy &VMap,
bool IgnoreIncomingWithNoClones) {
- SmallSetVector<BasicBlock *, 16> Blocks;
- for (BasicBlock *BB : concat<BasicBlock *const>(LoopBlocks, ExitBlocks))
- Blocks.insert(BB);
+ SmallSetVector<BasicBlock *, 16> Blocks(
+ llvm::from_range, concat<BasicBlock *const>(LoopBlocks, ExitBlocks));
auto IsInClonedRegion = [&](BasicBlock *BB) { return Blocks.contains(BB); };
diff --git a/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp b/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
index e6bf2ee14c036..5693e235836bf 100644
--- a/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
+++ b/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
@@ -637,12 +637,10 @@ static void computeFunctionSummary(
// All new reference edges inserted in two loops below are either
// read or write only. They will be grouped in the end of RefEdges
// vector, so we can use a single integer value to identify them.
- for (const auto &VI : LoadRefEdges)
- RefEdges.insert(VI);
+ RefEdges.insert_range(LoadRefEdges);
unsigned FirstWORef = RefEdges.size();
- for (const auto &VI : StoreRefEdges)
- RefEdges.insert(VI);
+ RefEdges.insert_range(StoreRefEdges);
Refs = RefEdges.takeVector();
for (; RefCnt < FirstWORef; ++RefCnt)
diff --git a/llvm/lib/Analysis/StackSafetyAnalysis.cpp b/llvm/lib/Analysis/StackSafetyAnalysis.cpp
index 5d81658409dae..fde5345229f55 100644
--- a/llvm/lib/Analysis/StackSafetyAnalysis.cpp
+++ b/llvm/lib/Analysis/StackSafetyAnalysis.cpp
@@ -672,8 +672,7 @@ void StackSafetyDataFlowAnalysis<CalleeTy>::updateOneNode(
<< (UpdateToFullSet ? ", full-set" : "") << "] " << &FS
<< "\n");
// Callers of this function may need updating.
- for (auto &CallerID : Callers[Callee])
- WorkList.insert(CallerID);
+ WorkList.insert_range(Callers[Callee]);
++FS.UpdateCount;
}
diff --git a/llvm/lib/Analysis/SyntheticCountsUtils.cpp b/llvm/lib/Analysis/SyntheticCountsUtils.cpp
index 29c41fda5e28f..0893452436909 100644
--- a/llvm/lib/Analysis/SyntheticCountsUtils.cpp
+++ b/llvm/lib/Analysis/SyntheticCountsUtils.cpp
@@ -23,12 +23,9 @@ template <typename CallGraphType>
void SyntheticCountsUtils<CallGraphType>::propagateFromSCC(
const SccTy &SCC, GetProfCountTy GetProfCount, AddCountTy AddCount) {
- DenseSet<NodeRef> SCCNodes;
+ DenseSet<NodeRef> SCCNodes(llvm::from_range, SCC);
SmallVector<std::pair<NodeRef, EdgeRef>, 8> SCCEdges, NonSCCEdges;
- for (auto &Node : SCC)
- SCCNodes.insert(Node);
-
// Partition the edges coming out of the SCC into those whose destination is
// in the SCC and the rest.
for (const auto &Node : SCCNodes) {
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/162/builds/18848 Here is the relevant piece of the build log for the reference
|
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.