Skip to content

Commit 47d8fec

Browse files
[llvm] Use llvm::append_range (NFC) (#136066)
This patch replaces: llvm::copy(Src, std::back_inserter(Dst)); with: llvm::append_range(Dst, Src); for breavity. One side benefit is that llvm::append_range eventually calls llvm::SmallVector::reserve if Dst is of llvm::SmallVector.
1 parent 799916a commit 47d8fec

File tree

11 files changed

+17
-19
lines changed

11 files changed

+17
-19
lines changed

llvm/include/llvm/Analysis/BlockFrequencyInfoImpl.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,8 +1159,7 @@ void BlockFrequencyInfoImpl<BT>::setBlockFreq(const BlockT *BB,
11591159

11601160
template <class BT> void BlockFrequencyInfoImpl<BT>::initializeRPOT() {
11611161
const BlockT *Entry = &F->front();
1162-
RPOT.reserve(F->size());
1163-
std::copy(po_begin(Entry), po_end(Entry), std::back_inserter(RPOT));
1162+
llvm::append_range(RPOT, post_order(Entry));
11641163
std::reverse(RPOT.begin(), RPOT.end());
11651164

11661165
assert(RPOT.size() - 1 <= BlockNode::getMaxIndex() &&

llvm/include/llvm/Bitcode/BitcodeConvenience.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ template <typename ElementTy> class BCRecordCoding<BCArray<ElementTy>> {
266266
ElementTy::assertValid(element);
267267
#endif
268268
buffer.reserve(buffer.size() + std::distance(array.begin(), array.end()));
269-
std::copy(array.begin(), array.end(), std::back_inserter(buffer));
269+
llvm::append_range(buffer, array);
270270
Stream.EmitRecordWithAbbrev(code, buffer);
271271
}
272272

llvm/include/llvm/IR/DiagnosticInfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,7 @@ class DiagnosticInfoIROptimization : public DiagnosticInfoOptimizationBase {
693693
Orig.RemarkName, Orig.getFunction(), Orig.getLocation()),
694694
CodeRegion(Orig.getCodeRegion()) {
695695
*this << Prepend;
696-
std::copy(Orig.Args.begin(), Orig.Args.end(), std::back_inserter(Args));
696+
llvm::append_range(Args, Orig.Args);
697697
}
698698

699699
/// Legacy interface.

llvm/lib/Analysis/LoopAccessAnalysis.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ void RuntimePointerChecking::groupChecks(
563563

564564
// We've computed the grouped checks for this partition.
565565
// Save the results and continue with the next one.
566-
llvm::copy(Groups, std::back_inserter(CheckingGroups));
566+
llvm::append_range(CheckingGroups, Groups);
567567
}
568568
}
569569

llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ ArrayRef<Register> IRTranslator::getOrCreateVRegs(const Value &Val) {
232232
unsigned Idx = 0;
233233
while (auto Elt = C.getAggregateElement(Idx++)) {
234234
auto EltRegs = getOrCreateVRegs(*Elt);
235-
llvm::copy(EltRegs, std::back_inserter(*VRegs));
235+
llvm::append_range(*VRegs, EltRegs);
236236
}
237237
} else {
238238
assert(SplitTys.size() == 1 && "unexpectedly split LLT");

llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,7 @@ llvm::createLibcall(MachineIRBuilder &MIRBuilder, const char *Name,
592592
isLibCallInTailPosition(Result, *MI, MIRBuilder.getTII(),
593593
*MIRBuilder.getMRI());
594594

595-
std::copy(Args.begin(), Args.end(), std::back_inserter(Info.OrigArgs));
595+
llvm::append_range(Info.OrigArgs, Args);
596596
if (!CLI.lowerCall(MIRBuilder, Info))
597597
return LegalizerHelper::UnableToLegalize;
598598

@@ -708,7 +708,7 @@ llvm::createMemLibcall(MachineIRBuilder &MIRBuilder, MachineRegisterInfo &MRI,
708708
MI.getOperand(MI.getNumOperands() - 1).getImm() &&
709709
isLibCallInTailPosition(Info.OrigRet, MI, MIRBuilder.getTII(), MRI);
710710

711-
std::copy(Args.begin(), Args.end(), std::back_inserter(Info.OrigArgs));
711+
llvm::append_range(Info.OrigArgs, Args);
712712
if (!CLI.lowerCall(MIRBuilder, Info))
713713
return LegalizerHelper::UnableToLegalize;
714714

@@ -855,7 +855,7 @@ createAtomicLibcall(MachineIRBuilder &MIRBuilder, MachineInstr &MI) {
855855
Info.Callee = MachineOperand::CreateES(Name);
856856
Info.OrigRet = CallLowering::ArgInfo(RetRegs, RetTy, 0);
857857

858-
std::copy(Args.begin(), Args.end(), std::back_inserter(Info.OrigArgs));
858+
llvm::append_range(Info.OrigArgs, Args);
859859
if (!CLI.lowerCall(MIRBuilder, Info))
860860
return LegalizerHelper::UnableToLegalize;
861861

llvm/lib/CodeGen/ModuloSchedule.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1855,9 +1855,9 @@ void PeelingModuloScheduleExpander::peelPrologAndEpilogs() {
18551855

18561856
// Create a list of all blocks in order.
18571857
SmallVector<MachineBasicBlock *, 8> Blocks;
1858-
llvm::copy(PeeledFront, std::back_inserter(Blocks));
1858+
llvm::append_range(Blocks, PeeledFront);
18591859
Blocks.push_back(BB);
1860-
llvm::copy(PeeledBack, std::back_inserter(Blocks));
1860+
llvm::append_range(Blocks, PeeledBack);
18611861

18621862
// Iterate in reverse order over all instructions, remapping as we go.
18631863
for (MachineBasicBlock *B : reverse(Blocks)) {

llvm/lib/ExecutionEngine/JITLink/JITLink.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ void LinkGraph::dump(raw_ostream &OS) {
313313
OS << "section " << Sec->getName() << ":\n\n";
314314

315315
std::vector<Block *> SortedBlocks;
316-
llvm::copy(Sec->blocks(), std::back_inserter(SortedBlocks));
316+
llvm::append_range(SortedBlocks, Sec->blocks());
317317
llvm::sort(SortedBlocks, [](const Block *LHS, const Block *RHS) {
318318
return LHS->getAddress() < RHS->getAddress();
319319
});
@@ -339,7 +339,7 @@ void LinkGraph::dump(raw_ostream &OS) {
339339
if (!B->edges_empty()) {
340340
OS << " edges:\n";
341341
std::vector<Edge> SortedEdges;
342-
llvm::copy(B->edges(), std::back_inserter(SortedEdges));
342+
llvm::append_range(SortedEdges, B->edges());
343343
llvm::sort(SortedEdges, [](const Edge &LHS, const Edge &RHS) {
344344
return LHS.getOffset() < RHS.getOffset();
345345
});

llvm/lib/Transforms/Scalar/GVNSink.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,16 +199,16 @@ class ModelledPHI {
199199
SmallSetVector<BasicBlock *, 4> &B,
200200
const DenseMap<const BasicBlock *, unsigned> &BlockOrder) {
201201
// The order of Values and Blocks are already ordered by the caller.
202-
llvm::copy(V, std::back_inserter(Values));
203-
llvm::copy(B, std::back_inserter(Blocks));
202+
llvm::append_range(Values, V);
203+
llvm::append_range(Blocks, B);
204204
verifyModelledPHI(BlockOrder);
205205
}
206206

207207
/// Create a PHI from [I[OpNum] for I in Insts].
208208
/// TODO: Figure out a way to verifyModelledPHI in this constructor.
209209
ModelledPHI(ArrayRef<Instruction *> Insts, unsigned OpNum,
210210
SmallSetVector<BasicBlock *, 4> &B) {
211-
llvm::copy(B, std::back_inserter(Blocks));
211+
llvm::append_range(Blocks, B);
212212
for (auto *I : Insts)
213213
Values.push_back(I->getOperand(OpNum));
214214
}

llvm/tools/llvm-jitlink/llvm-jitlink.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2360,7 +2360,7 @@ static Error addLibraries(Session &S,
23602360
SmallVector<char, 256> LibPath;
23612361
LibPath.reserve(SearchPath.size() + strlen("lib") + LL.LibName.size() +
23622362
LibExt.size() + 2); // +2 for pathsep, null term.
2363-
llvm::copy(SearchPath, std::back_inserter(LibPath));
2363+
llvm::append_range(LibPath, SearchPath);
23642364
if (LibExt != ".lib" && LibExt != ".dll")
23652365
sys::path::append(LibPath, "lib" + LL.LibName + LibExt);
23662366
else

llvm/utils/TableGen/SearchableTableEmitter.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -701,8 +701,7 @@ void SearchableTableEmitter::collectTableEntries(
701701
}
702702

703703
SearchIndex Idx;
704-
std::copy(Table.Fields.begin(), Table.Fields.end(),
705-
std::back_inserter(Idx.Fields));
704+
llvm::append_range(Idx.Fields, Table.Fields);
706705
llvm::sort(Table.Entries, [&](const Record *LHS, const Record *RHS) {
707706
return compareBy(LHS, RHS, Idx);
708707
});

0 commit comments

Comments
 (0)