Skip to content

Commit fac8fe9

Browse files
[Target] Use *Set::insert_range (NFC) (#132879)
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 75210df commit fac8fe9

14 files changed

+15
-33
lines changed

llvm/lib/Target/AArch64/AArch64BranchTargets.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,7 @@ bool AArch64BranchTargets::runOnMachineFunction(MachineFunction &MF) {
7272
SmallPtrSet<MachineBasicBlock *, 8> JumpTableTargets;
7373
if (auto *JTI = MF.getJumpTableInfo())
7474
for (auto &JTE : JTI->getJumpTables())
75-
for (auto *MBB : JTE.MBBs)
76-
JumpTableTargets.insert(MBB);
75+
JumpTableTargets.insert_range(JTE.MBBs);
7776

7877
bool MadeChange = false;
7978
bool HasWinCFI = MF.hasWinCFI();

llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2412,8 +2412,7 @@ class AArch64Operand : public MCParsedAsmOperand {
24122412
else {
24132413
std::vector<unsigned> Regs = RegMap[std::make_pair(ElementWidth, Reg)];
24142414
assert(!Regs.empty() && "Invalid tile or element width!");
2415-
for (auto OutReg : Regs)
2416-
OutRegs.insert(OutReg);
2415+
OutRegs.insert_range(Regs);
24172416
}
24182417
}
24192418

llvm/lib/Target/AMDGPU/R600MachineCFGStructurizer.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,9 +1013,7 @@ int R600MachineCFGStructurizer::mergeLoop(MachineLoop *LoopRep) {
10131013
// We assume a single ExitBlk
10141014
MBBVector ExitBlks;
10151015
LoopRep->getExitBlocks(ExitBlks);
1016-
SmallPtrSet<MachineBasicBlock *, 2> ExitBlkSet;
1017-
for (MachineBasicBlock *MBB : ExitBlks)
1018-
ExitBlkSet.insert(MBB);
1016+
SmallPtrSet<MachineBasicBlock *, 2> ExitBlkSet(llvm::from_range, ExitBlks);
10191017
assert(ExitBlkSet.size() == 1);
10201018
MachineBasicBlock *ExitBlk = *ExitBlks.begin();
10211019
assert(ExitBlk && "Loop has several exit block");

llvm/lib/Target/ARM/ARMAsmPrinter.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,7 @@ bool ARMAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
120120
// Collect all globals that had their storage promoted to a constant pool.
121121
// Functions are emitted before variables, so this accumulates promoted
122122
// globals from all functions in PromotedGlobals.
123-
for (const auto *GV : AFI->getGlobalsPromotedToConstantPool())
124-
PromotedGlobals.insert(GV);
123+
PromotedGlobals.insert_range(AFI->getGlobalsPromotedToConstantPool());
125124

126125
// Calculate this function's optimization goal.
127126
unsigned OptimizationGoal;

llvm/lib/Target/ARM/ARMFrameLowering.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3213,8 +3213,7 @@ void ARMFrameLowering::adjustForSegmentedStacks(
32133213
MachineBasicBlock *AddedBlocks[] = {PrevStackMBB, McrMBB, GetMBB, AllocMBB,
32143214
PostStackMBB};
32153215

3216-
for (MachineBasicBlock *B : AddedBlocks)
3217-
BeforePrologueRegion.insert(B);
3216+
BeforePrologueRegion.insert_range(AddedBlocks);
32183217

32193218
for (const auto &LI : PrologueMBB.liveins()) {
32203219
for (MachineBasicBlock *PredBB : BeforePrologueRegion)

llvm/lib/Target/ARM/ARMISelLowering.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3139,9 +3139,8 @@ bool ARMTargetLowering::IsEligibleForTailCallOptimization(
31393139
// Sometimes, no register matches all of these conditions, so we can't do a
31403140
// tail-call.
31413141
if (!isa<GlobalAddressSDNode>(Callee.getNode()) || isIndirect) {
3142-
SmallSet<MCPhysReg, 5> AddressRegisters;
3143-
for (Register R : {ARM::R0, ARM::R1, ARM::R2, ARM::R3})
3144-
AddressRegisters.insert(R);
3142+
SmallSet<MCPhysReg, 5> AddressRegisters = {ARM::R0, ARM::R1, ARM::R2,
3143+
ARM::R3};
31453144
if (!(Subtarget->isThumb1Only() ||
31463145
MF.getInfo<ARMFunctionInfo>()->shouldSignReturnAddress(true)))
31473146
AddressRegisters.insert(ARM::R12);

llvm/lib/Target/ARM/Thumb2ITBlockPass.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,7 @@ static void TrackDefUses(MachineInstr *MI, RegisterSet &Defs, RegisterSet &Uses,
9696

9797
auto InsertUsesDefs = [&](RegList &Regs, RegisterSet &UsesDefs) {
9898
for (unsigned Reg : Regs)
99-
for (MCPhysReg Subreg : TRI->subregs_inclusive(Reg))
100-
UsesDefs.insert(Subreg);
99+
UsesDefs.insert_range(TRI->subregs_inclusive(Reg));
101100
};
102101

103102
InsertUsesDefs(LocalDefs, Defs);

llvm/lib/Target/Hexagon/BitTracker.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -965,8 +965,7 @@ void BT::visitBranchesFrom(const MachineInstr &BI) {
965965
Targets.insert(&*Next);
966966
}
967967
} else {
968-
for (const MachineBasicBlock *SB : B.successors())
969-
Targets.insert(SB);
968+
Targets.insert_range(B.successors());
970969
}
971970

972971
for (const MachineBasicBlock *TB : Targets)

llvm/lib/Target/Hexagon/HexagonConstPropagation.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -779,8 +779,7 @@ void MachineConstPropagator::visitBranchesFrom(const MachineInstr &BrI) {
779779
Targets.clear();
780780
LLVM_DEBUG(dbgs() << " failed to evaluate a branch...adding all CFG "
781781
"successors\n");
782-
for (const MachineBasicBlock *SB : B.successors())
783-
Targets.insert(SB);
782+
Targets.insert_range(B.successors());
784783
}
785784

786785
for (const MachineBasicBlock *TB : Targets) {

llvm/lib/Target/Hexagon/HexagonExpandCondsets.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,8 +401,7 @@ void HexagonExpandCondsets::updateDeadsInRange(Register Reg, LaneBitmask LM,
401401
continue;
402402
if (B == Entry)
403403
return false;
404-
for (auto *P : B->predecessors())
405-
Work.insert(P);
404+
Work.insert_range(B->predecessors());
406405
}
407406
return true;
408407
};

llvm/lib/Target/Hexagon/HexagonLoadStoreWidening.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -801,9 +801,7 @@ bool HexagonLoadStoreWidening::replaceInsts(InstrGroup &OG, InstrGroup &NG) {
801801
// the insertion point.
802802

803803
// Create a set of all instructions in OG (for quick lookup).
804-
InstrSet OldMemInsts;
805-
for (auto *I : OG)
806-
OldMemInsts.insert(I);
804+
InstrSet OldMemInsts(llvm::from_range, OG);
807805

808806
if (Mode == WideningMode::Load) {
809807
// Find the first load instruction in the block that is present in OG.

llvm/lib/Target/Hexagon/HexagonLoopIdiomRecognition.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2303,8 +2303,7 @@ bool HexagonLoopIdiomRecognize::processCopyingStore(Loop *CurLoop,
23032303
bool HexagonLoopIdiomRecognize::coverLoop(Loop *L,
23042304
SmallVectorImpl<Instruction*> &Insts) const {
23052305
SmallSet<BasicBlock*,8> LoopBlocks;
2306-
for (auto *B : L->blocks())
2307-
LoopBlocks.insert(B);
2306+
LoopBlocks.insert_range(L->blocks());
23082307

23092308
SetVector<Instruction*> Worklist(Insts.begin(), Insts.end());
23102309

llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,7 @@ static cl::list<SPIRV::Capability::Capability>
4444
// Use sets instead of cl::list to check "if contains" condition
4545
struct AvoidCapabilitiesSet {
4646
SmallSet<SPIRV::Capability::Capability, 4> S;
47-
AvoidCapabilitiesSet() {
48-
for (auto Cap : AvoidCapabilities)
49-
S.insert(Cap);
50-
}
47+
AvoidCapabilitiesSet() { S.insert_range(AvoidCapabilities); }
5148
};
5249

5350
char llvm::SPIRVModuleAnalysis::ID = 0;

llvm/lib/Target/X86/X86SpeculativeLoadHardening.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,8 +1041,7 @@ X86SpeculativeLoadHardeningPass::tracePredStateThroughIndirectBranches(
10411041
IndirectTerminatedMBBs.insert(&MBB);
10421042

10431043
// Add all the successors to our target candidates.
1044-
for (MachineBasicBlock *Succ : MBB.successors())
1045-
IndirectTargetMBBs.insert(Succ);
1044+
IndirectTargetMBBs.insert_range(MBB.successors());
10461045
}
10471046

10481047
// Keep track of the cmov instructions we insert so we can return them.

0 commit comments

Comments
 (0)