Skip to content

Commit e9487fe

Browse files
[llvm] Construct SmallVector with iterator ranges (NFC) (#136460)
1 parent 6aab2b1 commit e9487fe

File tree

17 files changed

+37
-78
lines changed

17 files changed

+37
-78
lines changed

llvm/lib/Analysis/CGSCCPassManager.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -515,9 +515,7 @@ PreservedAnalyses CGSCCToFunctionPassAdaptor::run(LazyCallGraph::SCC &C,
515515
FunctionAnalysisManager &FAM =
516516
AM.getResult<FunctionAnalysisManagerCGSCCProxy>(C, CG).getManager();
517517

518-
SmallVector<LazyCallGraph::Node *, 4> Nodes;
519-
for (LazyCallGraph::Node &N : C)
520-
Nodes.push_back(&N);
518+
SmallVector<LazyCallGraph::Node *, 4> Nodes(llvm::make_pointer_range(C));
521519

522520
// The SCC may get split while we are optimizing functions due to deleting
523521
// edges. If this happens, the current SCC can shift, so keep track of

llvm/lib/CodeGen/AsmPrinter/DwarfStringPool.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,8 @@ void DwarfStringPool::emit(AsmPrinter &Asm, MCSection *StrSection,
8181
Asm.OutStreamer->switchSection(StrSection);
8282

8383
// Get all of the string pool entries and sort them by their offset.
84-
SmallVector<const StringMapEntry<EntryTy> *, 64> Entries;
85-
Entries.reserve(Pool.size());
86-
87-
for (const auto &E : Pool)
88-
Entries.push_back(&E);
84+
SmallVector<const StringMapEntry<EntryTy> *, 64> Entries(
85+
llvm::make_pointer_range(Pool));
8986

9087
llvm::sort(Entries, [](const StringMapEntry<EntryTy> *A,
9188
const StringMapEntry<EntryTy> *B) {

llvm/lib/ExecutionEngine/JITLink/EHFrameSupport.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -643,9 +643,7 @@ EHFrameCFIBlockInspector EHFrameCFIBlockInspector::FromEdgeScan(Block &B) {
643643
return EHFrameCFIBlockInspector(nullptr);
644644
if (B.edges_size() == 1)
645645
return EHFrameCFIBlockInspector(&*B.edges().begin());
646-
SmallVector<Edge *, 3> Es;
647-
for (auto &E : B.edges())
648-
Es.push_back(&E);
646+
SmallVector<Edge *, 3> Es(llvm::make_pointer_range(B.edges()));
649647
assert(Es.size() >= 2 && Es.size() <= 3 && "Unexpected number of edges");
650648
llvm::sort(Es, [](const Edge *LHS, const Edge *RHS) {
651649
return LHS->getOffset() < RHS->getOffset();

llvm/lib/FuzzMutate/IRMutator.cpp

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,8 @@ getInsertionRange(BasicBlock &BB) {
122122
}
123123

124124
void InjectorIRStrategy::mutate(BasicBlock &BB, RandomIRBuilder &IB) {
125-
SmallVector<Instruction *, 32> Insts;
126-
for (Instruction &I : getInsertionRange(BB))
127-
Insts.push_back(&I);
125+
SmallVector<Instruction *, 32> Insts(
126+
llvm::make_pointer_range(getInsertionRange(BB)));
128127
if (Insts.size() < 1)
129128
return;
130129

@@ -395,9 +394,8 @@ void InsertFunctionStrategy::mutate(BasicBlock &BB, RandomIRBuilder &IB) {
395394
return isRetVoid ? nullptr : Call;
396395
};
397396

398-
SmallVector<Instruction *, 32> Insts;
399-
for (Instruction &I : getInsertionRange(BB))
400-
Insts.push_back(&I);
397+
SmallVector<Instruction *, 32> Insts(
398+
llvm::make_pointer_range(getInsertionRange(BB)));
401399
if (Insts.size() < 1)
402400
return;
403401

@@ -421,9 +419,8 @@ void InsertFunctionStrategy::mutate(BasicBlock &BB, RandomIRBuilder &IB) {
421419
}
422420

423421
void InsertCFGStrategy::mutate(BasicBlock &BB, RandomIRBuilder &IB) {
424-
SmallVector<Instruction *, 32> Insts;
425-
for (Instruction &I : getInsertionRange(BB))
426-
Insts.push_back(&I);
422+
SmallVector<Instruction *, 32> Insts(
423+
llvm::make_pointer_range(getInsertionRange(BB)));
427424
if (Insts.size() < 1)
428425
return;
429426

@@ -561,9 +558,8 @@ void InsertPHIStrategy::mutate(BasicBlock &BB, RandomIRBuilder &IB) {
561558
}
562559
PHI->addIncoming(Src, Pred);
563560
}
564-
SmallVector<Instruction *, 32> InstsAfter;
565-
for (Instruction &I : getInsertionRange(BB))
566-
InstsAfter.push_back(&I);
561+
SmallVector<Instruction *, 32> InstsAfter(
562+
llvm::make_pointer_range(getInsertionRange(BB)));
567563
IB.connectToSink(BB, InstsAfter, PHI);
568564
}
569565

@@ -573,9 +569,8 @@ void SinkInstructionStrategy::mutate(Function &F, RandomIRBuilder &IB) {
573569
}
574570
}
575571
void SinkInstructionStrategy::mutate(BasicBlock &BB, RandomIRBuilder &IB) {
576-
SmallVector<Instruction *, 32> Insts;
577-
for (Instruction &I : getInsertionRange(BB))
578-
Insts.push_back(&I);
572+
SmallVector<Instruction *, 32> Insts(
573+
llvm::make_pointer_range(getInsertionRange(BB)));
579574
if (Insts.size() < 1)
580575
return;
581576
// Choose an Instruction to mutate.

llvm/lib/FuzzMutate/RandomIRBuilder.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,8 @@ RandomIRBuilder::findOrCreateGlobalVariable(Module *M, ArrayRef<Value *> Srcs,
8484
return Pred.matches(Srcs, PoisonValue::get(GV->getValueType()));
8585
};
8686
bool DidCreate = false;
87-
SmallVector<GlobalVariable *, 4> GlobalVars;
88-
for (GlobalVariable &GV : M->globals()) {
89-
GlobalVars.push_back(&GV);
90-
}
87+
SmallVector<GlobalVariable *, 4> GlobalVars(
88+
llvm::make_pointer_range(M->globals()));
9189
auto RS = makeSampler(Rand, make_filter_range(GlobalVars, MatchesPred));
9290
RS.sample(nullptr, 1);
9391
GlobalVariable *GV = RS.getSelection();
@@ -146,10 +144,8 @@ Value *RandomIRBuilder::findOrCreateSource(BasicBlock &BB,
146144
auto Dominators = getDominators(&BB);
147145
std::shuffle(Dominators.begin(), Dominators.end(), Rand);
148146
for (BasicBlock *Dom : Dominators) {
149-
SmallVector<Instruction *, 16> Instructions;
150-
for (Instruction &I : *Dom) {
151-
Instructions.push_back(&I);
152-
}
147+
SmallVector<Instruction *, 16> Instructions(
148+
llvm::make_pointer_range(*Dom));
153149
auto RS =
154150
makeSampler(Rand, make_filter_range(Instructions, MatchesPred));
155151
// Also consider choosing no source, meaning we want a new one.

llvm/lib/Target/AArch64/AArch64Arm64ECCallLowering.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -656,9 +656,7 @@ Function *AArch64Arm64ECCallLowering::buildGuestExitThunk(Function *F) {
656656
GuardCheck->setCallingConv(CallingConv::CFGuard_Check);
657657

658658
Value *GuardRetVal = B.CreateBitCast(GuardCheck, PtrTy);
659-
SmallVector<Value *> Args;
660-
for (Argument &Arg : GuestExit->args())
661-
Args.push_back(&Arg);
659+
SmallVector<Value *> Args(llvm::make_pointer_range(GuestExit->args()));
662660
CallInst *Call = B.CreateCall(Arm64Ty, GuardRetVal, Args);
663661
Call->setTailCallKind(llvm::CallInst::TCK_MustTail);
664662

@@ -715,9 +713,7 @@ AArch64Arm64ECCallLowering::buildPatchableThunk(GlobalAlias *UnmangledAlias,
715713
Dispatch->setCallingConv(CallingConv::CFGuard_Check);
716714

717715
Value *DispatchRetVal = B.CreateBitCast(Dispatch, PtrTy);
718-
SmallVector<Value *> Args;
719-
for (Argument &Arg : GuestExit->args())
720-
Args.push_back(&Arg);
716+
SmallVector<Value *> Args(llvm::make_pointer_range(GuestExit->args()));
721717
CallInst *Call = B.CreateCall(Arm64Ty, DispatchRetVal, Args);
722718
Call->setTailCallKind(llvm::CallInst::TCK_MustTail);
723719

llvm/lib/Target/ARM/A15SDOptimizer.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -617,10 +617,9 @@ bool A15SDOptimizer::runOnInstruction(MachineInstr *MI) {
617617
continue;
618618

619619
// Collect all the uses of this MI's DPR def for updating later.
620-
SmallVector<MachineOperand*, 8> Uses;
621620
Register DPRDefReg = MI->getOperand(0).getReg();
622-
for (MachineOperand &MO : MRI->use_operands(DPRDefReg))
623-
Uses.push_back(&MO);
621+
SmallVector<MachineOperand *, 8> Uses(
622+
llvm::make_pointer_range(MRI->use_operands(DPRDefReg)));
624623

625624
// We can optimize this.
626625
unsigned NewReg = optimizeSDPattern(MI);

llvm/lib/Target/NVPTX/NVPTXLowerArgs.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -554,9 +554,7 @@ static void handleByValParam(const NVPTXTargetMachine &TM, Argument *Arg) {
554554
if (ArgUseIsReadOnly && AUC.Conditionals.empty()) {
555555
// Convert all loads and intermediate operations to use parameter AS and
556556
// skip creation of a local copy of the argument.
557-
SmallVector<Use *, 16> UsesToUpdate;
558-
for (Use &U : Arg->uses())
559-
UsesToUpdate.push_back(&U);
557+
SmallVector<Use *, 16> UsesToUpdate(llvm::make_pointer_range(Arg->uses()));
560558

561559
Value *ArgInParamAS = new AddrSpaceCastInst(
562560
Arg, PointerType::get(StructType->getContext(), ADDRESS_SPACE_PARAM),

llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2399,9 +2399,8 @@ bool SPIRVEmitIntrinsics::runOnFunction(Function &Func) {
23992399

24002400
preprocessUndefs(B);
24012401
preprocessCompositeConstants(B);
2402-
SmallVector<Instruction *> Worklist;
2403-
for (auto &I : instructions(Func))
2404-
Worklist.push_back(&I);
2402+
SmallVector<Instruction *> Worklist(
2403+
llvm::make_pointer_range(instructions(Func)));
24052404

24062405
applyDemangledPtrArgTypes(B);
24072406

llvm/lib/Target/SPIRV/SPIRVPreLegalizerCombiner.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,8 @@ void applySPIRVDistance(MachineInstr &MI, MachineRegisterInfo &MRI,
9999
SPIRVGlobalRegistry *GR =
100100
MI.getMF()->getSubtarget<SPIRVSubtarget>().getSPIRVGlobalRegistry();
101101
auto RemoveAllUses = [&](Register Reg) {
102-
SmallVector<MachineInstr *, 4> UsesToErase;
103-
for (auto &UseMI : MRI.use_instructions(Reg))
104-
UsesToErase.push_back(&UseMI);
102+
SmallVector<MachineInstr *, 4> UsesToErase(
103+
llvm::make_pointer_range(MRI.use_instructions(Reg)));
105104

106105
// calling eraseFromParent to early invalidates the iterator.
107106
for (auto *MIToErase : UsesToErase) {

0 commit comments

Comments
 (0)