[llvm] [llvm] Use *Set::insert_range (NFC) (PR #132509)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 21 20:51:46 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-analysis
Author: Kazu Hirata (kazutakahirata)
<details>
<summary>Changes</summary>
DenseSet, SmallPtrSet, SmallSet, SetVector, and StringSet recently
gained C++23-style insert_range. This patch uses insert_range in
conjunction with llvm::{predecessors,successors} and
MachineBasicBlock::{predecessors,successors}.
---
Full diff: https://github.com/llvm/llvm-project/pull/132509.diff
12 Files Affected:
- (modified) llvm/lib/Analysis/FunctionPropertiesAnalysis.cpp (+3-3)
- (modified) llvm/lib/CodeGen/CodeGenPrepare.cpp (+1-1)
- (modified) llvm/lib/CodeGen/MachineVerifier.cpp (+2-2)
- (modified) llvm/lib/CodeGen/TailDuplicator.cpp (+1-1)
- (modified) llvm/lib/IR/SafepointIRVerifier.cpp (+1-1)
- (modified) llvm/lib/Target/AMDGPU/AMDGPUInsertDelayAlu.cpp (+1-1)
- (modified) llvm/lib/Target/ARM/ARMISelLowering.cpp (+1-1)
- (modified) llvm/lib/Target/VE/VEISelLowering.cpp (+1-1)
- (modified) llvm/lib/Target/X86/X86ISelLowering.cpp (+1-1)
- (modified) llvm/lib/Transforms/Scalar/LICM.cpp (+2-2)
- (modified) llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp (+2-2)
- (modified) llvm/lib/Transforms/Utils/BasicBlockUtils.cpp (+1-1)
``````````diff
diff --git a/llvm/lib/Analysis/FunctionPropertiesAnalysis.cpp b/llvm/lib/Analysis/FunctionPropertiesAnalysis.cpp
index c135fe12dc37e..9389a109cfcb5 100644
--- a/llvm/lib/Analysis/FunctionPropertiesAnalysis.cpp
+++ b/llvm/lib/Analysis/FunctionPropertiesAnalysis.cpp
@@ -324,7 +324,7 @@ FunctionPropertiesUpdater::FunctionPropertiesUpdater(
// The successors may become unreachable in the case of `invoke` inlining.
// We track successors separately, too, because they form a boundary, together
// with the CB BB ('Entry') between which the inlined callee will be pasted.
- Successors.insert(succ_begin(&CallSiteBB), succ_end(&CallSiteBB));
+ Successors.insert_range(successors(&CallSiteBB));
// the outcome of the inlining may be that some edges get lost (DCEd BBs
// because inlining brought some constant, for example). We don't know which
@@ -349,7 +349,7 @@ FunctionPropertiesUpdater::FunctionPropertiesUpdater(
// discounted BBs will be checked if reachable and re-added.
if (const auto *II = dyn_cast<InvokeInst>(&CB)) {
const auto *UnwindDest = II->getUnwindDest();
- Successors.insert(succ_begin(UnwindDest), succ_end(UnwindDest));
+ Successors.insert_range(successors(UnwindDest));
// Same idea as above, we pretend we lose all these edges.
for (auto *Succ : successors(UnwindDest))
if (Inserted.insert(Succ).second)
@@ -454,7 +454,7 @@ void FunctionPropertiesUpdater::finish(FunctionAnalysisManager &FAM) const {
const auto *BB = Reinclude[I];
FPI.reIncludeBB(*BB);
if (I >= IncludeSuccessorsMark)
- Reinclude.insert(succ_begin(BB), succ_end(BB));
+ Reinclude.insert_range(successors(BB));
}
// For exclusion, we don't need to exclude the set of BBs that were successors
diff --git a/llvm/lib/CodeGen/CodeGenPrepare.cpp b/llvm/lib/CodeGen/CodeGenPrepare.cpp
index 1a791f086f11a..2d34c8ee9302d 100644
--- a/llvm/lib/CodeGen/CodeGenPrepare.cpp
+++ b/llvm/lib/CodeGen/CodeGenPrepare.cpp
@@ -1082,7 +1082,7 @@ bool CodeGenPrepare::canMergeBlocks(const BasicBlock *BB,
for (unsigned i = 0, e = BBPN->getNumIncomingValues(); i != e; ++i)
BBPreds.insert(BBPN->getIncomingBlock(i));
} else {
- BBPreds.insert(pred_begin(BB), pred_end(BB));
+ BBPreds.insert_range(predecessors(BB));
}
// Walk the preds of DestBB.
diff --git a/llvm/lib/CodeGen/MachineVerifier.cpp b/llvm/lib/CodeGen/MachineVerifier.cpp
index 754c265c4c4fb..4484a3fc05208 100644
--- a/llvm/lib/CodeGen/MachineVerifier.cpp
+++ b/llvm/lib/CodeGen/MachineVerifier.cpp
@@ -708,11 +708,11 @@ void MachineVerifier::visitMachineFunctionBefore() {
FunctionBlocks.insert(&MBB);
BBInfo &MInfo = MBBInfoMap[&MBB];
- MInfo.Preds.insert(MBB.pred_begin(), MBB.pred_end());
+ MInfo.Preds.insert_range(MBB.predecessors());
if (MInfo.Preds.size() != MBB.pred_size())
report("MBB has duplicate entries in its predecessor list.", &MBB);
- MInfo.Succs.insert(MBB.succ_begin(), MBB.succ_end());
+ MInfo.Succs.insert_range(MBB.successors());
if (MInfo.Succs.size() != MBB.succ_size())
report("MBB has duplicate entries in its successor list.", &MBB);
}
diff --git a/llvm/lib/CodeGen/TailDuplicator.cpp b/llvm/lib/CodeGen/TailDuplicator.cpp
index 4a2d1355485da..c79c29b929fc8 100644
--- a/llvm/lib/CodeGen/TailDuplicator.cpp
+++ b/llvm/lib/CodeGen/TailDuplicator.cpp
@@ -878,7 +878,7 @@ bool TailDuplicator::tailDuplicate(bool IsSimple, MachineBasicBlock *TailBB,
if (CandidatePtr)
Preds.insert_range(*CandidatePtr);
else
- Preds.insert(TailBB->pred_begin(), TailBB->pred_end());
+ Preds.insert_range(TailBB->predecessors());
for (MachineBasicBlock *PredBB : Preds) {
assert(TailBB != PredBB &&
diff --git a/llvm/lib/IR/SafepointIRVerifier.cpp b/llvm/lib/IR/SafepointIRVerifier.cpp
index f649f8fb61ad3..9c7f91d756301 100644
--- a/llvm/lib/IR/SafepointIRVerifier.cpp
+++ b/llvm/lib/IR/SafepointIRVerifier.cpp
@@ -646,7 +646,7 @@ void GCPtrTracker::recalculateBBsStates() {
transferBlock(BB, *BBS, ContributionChanged);
if (OldOutCount != BBS->AvailableOut.size()) {
assert(OldOutCount > BBS->AvailableOut.size() && "invariant!");
- Worklist.insert(succ_begin(BB), succ_end(BB));
+ Worklist.insert_range(successors(BB));
}
}
}
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUInsertDelayAlu.cpp b/llvm/lib/Target/AMDGPU/AMDGPUInsertDelayAlu.cpp
index 51c4528e07d62..10efbab805676 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUInsertDelayAlu.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUInsertDelayAlu.cpp
@@ -466,7 +466,7 @@ class AMDGPUInsertDelayAlu {
auto &MBB = *WorkList.pop_back_val();
bool Changed = runOnMachineBasicBlock(MBB, false);
if (Changed)
- WorkList.insert(MBB.succ_begin(), MBB.succ_end());
+ WorkList.insert_range(MBB.successors());
}
LLVM_DEBUG(dbgs() << "Final pass over all BBs\n");
diff --git a/llvm/lib/Target/ARM/ARMISelLowering.cpp b/llvm/lib/Target/ARM/ARMISelLowering.cpp
index c015448ef69d4..f99e084d9347c 100644
--- a/llvm/lib/Target/ARM/ARMISelLowering.cpp
+++ b/llvm/lib/Target/ARM/ARMISelLowering.cpp
@@ -11045,7 +11045,7 @@ void ARMTargetLowering::EmitSjLjDispatchBlock(MachineInstr &MI,
SmallVectorImpl<MachineBasicBlock*> &MBBList = CallSiteNumToLPad[I];
for (MachineBasicBlock *MBB : MBBList) {
LPadList.push_back(MBB);
- InvokeBBs.insert(MBB->pred_begin(), MBB->pred_end());
+ InvokeBBs.insert_range(MBB->predecessors());
}
}
diff --git a/llvm/lib/Target/VE/VEISelLowering.cpp b/llvm/lib/Target/VE/VEISelLowering.cpp
index 9881ba0305759..b7fa089921c2d 100644
--- a/llvm/lib/Target/VE/VEISelLowering.cpp
+++ b/llvm/lib/Target/VE/VEISelLowering.cpp
@@ -2412,7 +2412,7 @@ VETargetLowering::emitSjLjDispatchBlock(MachineInstr &MI,
for (unsigned CSI = 1; CSI <= MaxCSNum; ++CSI) {
for (auto &LP : CallSiteNumToLPad[CSI]) {
LPadList.push_back(LP);
- InvokeBBs.insert(LP->pred_begin(), LP->pred_end());
+ InvokeBBs.insert_range(LP->predecessors());
}
}
diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp
index 02398923ebc90..a7db154bfaa3b 100644
--- a/llvm/lib/Target/X86/X86ISelLowering.cpp
+++ b/llvm/lib/Target/X86/X86ISelLowering.cpp
@@ -37269,7 +37269,7 @@ X86TargetLowering::EmitSjLjDispatchBlock(MachineInstr &MI,
for (unsigned CSI = 1; CSI <= MaxCSNum; ++CSI) {
for (auto &LP : CallSiteNumToLPad[CSI]) {
LPadList.push_back(LP);
- InvokeBBs.insert(LP->pred_begin(), LP->pred_end());
+ InvokeBBs.insert_range(LP->predecessors());
}
}
diff --git a/llvm/lib/Transforms/Scalar/LICM.cpp b/llvm/lib/Transforms/Scalar/LICM.cpp
index 4bad19e6fb7be..f42bc2c38ba03 100644
--- a/llvm/lib/Transforms/Scalar/LICM.cpp
+++ b/llvm/lib/Transforms/Scalar/LICM.cpp
@@ -689,8 +689,8 @@ class ControlFlowHoister {
// TODO: This could be expanded to allowing branches where both ends
// eventually converge to a single block.
SmallPtrSet<BasicBlock *, 4> TrueDestSucc, FalseDestSucc;
- TrueDestSucc.insert(succ_begin(TrueDest), succ_end(TrueDest));
- FalseDestSucc.insert(succ_begin(FalseDest), succ_end(FalseDest));
+ TrueDestSucc.insert_range(successors(TrueDest));
+ FalseDestSucc.insert_range(successors(FalseDest));
BasicBlock *CommonSucc = nullptr;
if (TrueDestSucc.count(FalseDest)) {
CommonSucc = FalseDest;
diff --git a/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp b/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
index ef425e0318ea9..38b7984d13606 100644
--- a/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
+++ b/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
@@ -3302,7 +3302,7 @@ static void computeLiveInValues(DominatorTree &DT, Function &F,
Data.LiveIn[&BB].set_union(Data.LiveOut[&BB]);
Data.LiveIn[&BB].set_subtract(Data.KillSet[&BB]);
if (!Data.LiveIn[&BB].empty())
- Worklist.insert(pred_begin(&BB), pred_end(&BB));
+ Worklist.insert_range(predecessors(&BB));
}
// Propagate that liveness until stable
@@ -3336,7 +3336,7 @@ static void computeLiveInValues(DominatorTree &DT, Function &F,
// assert: OldLiveIn is a subset of LiveTmp
if (OldLiveIn.size() != LiveTmp.size()) {
Data.LiveIn[BB] = LiveTmp;
- Worklist.insert(pred_begin(BB), pred_end(BB));
+ Worklist.insert_range(predecessors(BB));
}
} // while (!Worklist.empty())
diff --git a/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp b/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
index 04b2d1a38ab60..ce5bf0c7207c7 100644
--- a/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
+++ b/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
@@ -1660,7 +1660,7 @@ void llvm::SplitBlockAndInsertIfThenElse(
SmallPtrSet<BasicBlock *, 8> UniqueOrigSuccessors;
BasicBlock *Head = SplitBefore->getParent();
if (DTU) {
- UniqueOrigSuccessors.insert(succ_begin(Head), succ_end(Head));
+ UniqueOrigSuccessors.insert_range(successors(Head));
Updates.reserve(4 + 2 * UniqueOrigSuccessors.size());
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/132509
More information about the llvm-commits
mailing list