From 596d5823a7b76da1190f21155e1601307067ce0a Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Thu, 20 Mar 2025 22:46:02 -0700 Subject: [PATCH] [llvm] Use *Set::insert_range (NFC) 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}. --- llvm/lib/Analysis/FunctionPropertiesAnalysis.cpp | 6 +++--- llvm/lib/CodeGen/CodeGenPrepare.cpp | 2 +- llvm/lib/CodeGen/MachineVerifier.cpp | 4 ++-- llvm/lib/CodeGen/TailDuplicator.cpp | 2 +- llvm/lib/IR/SafepointIRVerifier.cpp | 2 +- llvm/lib/Target/AMDGPU/AMDGPUInsertDelayAlu.cpp | 2 +- llvm/lib/Target/ARM/ARMISelLowering.cpp | 2 +- llvm/lib/Target/VE/VEISelLowering.cpp | 2 +- llvm/lib/Target/X86/X86ISelLowering.cpp | 2 +- llvm/lib/Transforms/Scalar/LICM.cpp | 4 ++-- llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp | 4 ++-- llvm/lib/Transforms/Utils/BasicBlockUtils.cpp | 2 +- 12 files changed, 17 insertions(+), 17 deletions(-) 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(&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 &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 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 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()); }