[llvm] [llvm] Use llvm::append_range (NFC) (PR #135931)

Kazu Hirata via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 16 10:32:23 PDT 2025


https://github.com/kazutakahirata updated https://github.com/llvm/llvm-project/pull/135931

>From 659869eb5a44ac3acb58e66d084c18ea7f22bd97 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Mon, 14 Apr 2025 22:24:42 -0700
Subject: [PATCH 1/2] [llvm] Use llvm::append_range (NFC)

---
 llvm/include/llvm/IR/ModuleSummaryIndex.h                   | 2 +-
 llvm/lib/Analysis/MemoryProfileInfo.cpp                     | 6 ++----
 llvm/lib/Analysis/ScalarEvolution.cpp                       | 6 ++----
 llvm/lib/Bitcode/Writer/BitcodeWriter.cpp                   | 2 +-
 llvm/lib/DebugInfo/GSYM/DwarfTransformer.cpp                | 4 +---
 llvm/lib/DebugInfo/LogicalView/Core/LVCompare.cpp           | 2 +-
 llvm/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp  | 2 +-
 .../ExecutionEngine/Orc/Debugging/VTuneSupportPlugin.cpp    | 2 +-
 llvm/lib/ExecutionEngine/Orc/LazyReexports.cpp              | 4 ++--
 llvm/lib/IR/DebugInfoMetadata.cpp                           | 2 +-
 llvm/lib/MC/DXContainerPSVInfo.cpp                          | 3 +--
 llvm/lib/MC/MCParser/MasmParser.cpp                         | 5 ++---
 llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp                         | 4 ++--
 llvm/lib/ProfileData/InstrProfReader.cpp                    | 2 +-
 llvm/lib/TargetParser/SubtargetFeature.cpp                  | 2 +-
 llvm/unittests/DebugInfo/DWARF/DwarfGenerator.cpp           | 4 ++--
 llvm/unittests/DebugInfo/PDB/HashTableTest.cpp              | 2 +-
 llvm/unittests/Transforms/IPO/LowerTypeTests.cpp            | 2 +-
 llvm/utils/TableGen/Common/CodeGenRegisters.cpp             | 6 +++---
 llvm/utils/TableGen/RegisterInfoEmitter.cpp                 | 2 +-
 20 files changed, 28 insertions(+), 36 deletions(-)

diff --git a/llvm/include/llvm/IR/ModuleSummaryIndex.h b/llvm/include/llvm/IR/ModuleSummaryIndex.h
index 7aa36345268cd..b4202fa627621 100644
--- a/llvm/include/llvm/IR/ModuleSummaryIndex.h
+++ b/llvm/include/llvm/IR/ModuleSummaryIndex.h
@@ -1320,7 +1320,7 @@ class CfiFunctionIndex {
   std::vector<StringRef> symbols() const {
     std::vector<StringRef> Symbols;
     for (auto &[GUID, Syms] : Index)
-      Symbols.insert(Symbols.end(), Syms.begin(), Syms.end());
+      llvm::append_range(Symbols, Syms);
     return Symbols;
   }
 
diff --git a/llvm/lib/Analysis/MemoryProfileInfo.cpp b/llvm/lib/Analysis/MemoryProfileInfo.cpp
index 95138de592290..6ca5b5e492723 100644
--- a/llvm/lib/Analysis/MemoryProfileInfo.cpp
+++ b/llvm/lib/Analysis/MemoryProfileInfo.cpp
@@ -181,8 +181,7 @@ void CallStackTrie::addCallStack(
     Curr = New;
   }
   assert(Curr);
-  Curr->ContextSizeInfo.insert(Curr->ContextSizeInfo.end(),
-                               ContextSizeInfo.begin(), ContextSizeInfo.end());
+  llvm::append_range(Curr->ContextSizeInfo, ContextSizeInfo);
 }
 
 void CallStackTrie::addCallStack(MDNode *MIB) {
@@ -235,8 +234,7 @@ static MDNode *createMIBNode(LLVMContext &Ctx, ArrayRef<uint64_t> MIBCallStack,
 
 void CallStackTrie::collectContextSizeInfo(
     CallStackTrieNode *Node, std::vector<ContextTotalSize> &ContextSizeInfo) {
-  ContextSizeInfo.insert(ContextSizeInfo.end(), Node->ContextSizeInfo.begin(),
-                         Node->ContextSizeInfo.end());
+  llvm::append_range(ContextSizeInfo, Node->ContextSizeInfo);
   for (auto &Caller : Node->Callers)
     collectContextSizeInfo(Caller.second, ContextSizeInfo);
 }
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
index d193c9e3210ea..5132ee13a9632 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -8503,10 +8503,8 @@ void ScalarEvolution::forgetLoop(const Loop *L) {
     }
 
     auto LoopUsersItr = LoopUsers.find(CurrL);
-    if (LoopUsersItr != LoopUsers.end()) {
-      ToForget.insert(ToForget.end(), LoopUsersItr->second.begin(),
-                LoopUsersItr->second.end());
-    }
+    if (LoopUsersItr != LoopUsers.end())
+      llvm::append_range(ToForget, LoopUsersItr->second);
 
     // Drop information about expressions based on loop-header PHIs.
     PushLoopPHIs(CurrL, Worklist, Visited);
diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
index ad15f13902e63..73bed85c65b3d 100644
--- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -5098,7 +5098,7 @@ void IndexBitcodeWriter::writeCombinedGlobalValueSummary() {
       return;
     for (GlobalValue::GUID GUID : DefOrUseGUIDs) {
       auto Defs = CfiIndex.forGuid(GUID);
-      Functions.insert(Functions.end(), Defs.begin(), Defs.end());
+      llvm::append_range(Functions, Defs);
     }
     if (Functions.empty())
       return;
diff --git a/llvm/lib/DebugInfo/GSYM/DwarfTransformer.cpp b/llvm/lib/DebugInfo/GSYM/DwarfTransformer.cpp
index 642ab61756ea5..22137ea172240 100644
--- a/llvm/lib/DebugInfo/GSYM/DwarfTransformer.cpp
+++ b/llvm/lib/DebugInfo/GSYM/DwarfTransformer.cpp
@@ -621,9 +621,7 @@ void DwarfTransformer::parseCallSiteInfoFromDwarf(CUInfo &CUI, DWARFDie Die,
     if (!FI.CallSites)
       FI.CallSites = CallSiteInfoCollection();
     // Append parsed DWARF callsites:
-    FI.CallSites->CallSites.insert(FI.CallSites->CallSites.end(),
-                                   CSIC.CallSites.begin(),
-                                   CSIC.CallSites.end());
+    llvm::append_range(FI.CallSites->CallSites, CSIC.CallSites);
   }
 }
 
diff --git a/llvm/lib/DebugInfo/LogicalView/Core/LVCompare.cpp b/llvm/lib/DebugInfo/LogicalView/Core/LVCompare.cpp
index 5673ea7c2cd23..3cb2662f2f313 100644
--- a/llvm/lib/DebugInfo/LogicalView/Core/LVCompare.cpp
+++ b/llvm/lib/DebugInfo/LogicalView/Core/LVCompare.cpp
@@ -230,7 +230,7 @@ Error LVCompare::execute(LVReader *ReferenceReader, LVReader *TargetReader) {
         }
         if (Pass == LVComparePass::Added)
           // Record all the current missing elements for this category.
-          Set.insert(Set.end(), Elements.begin(), Elements.end());
+          llvm::append_range(Set, Elements);
         if (options().getReportList()) {
           if (Elements.size()) {
             OS << "\n(" << Elements.size() << ") "
diff --git a/llvm/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp b/llvm/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp
index 4f8f883a75f32..87675be1fc8e1 100644
--- a/llvm/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp
+++ b/llvm/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp
@@ -485,7 +485,7 @@ static GenericValue lle_X_fprintf(FunctionType *FT,
   char Buffer[10000];
   std::vector<GenericValue> NewArgs;
   NewArgs.push_back(PTOGV(Buffer));
-  NewArgs.insert(NewArgs.end(), Args.begin()+1, Args.end());
+  llvm::append_range(NewArgs, llvm::drop_begin(Args));
   GenericValue GV = lle_X_sprintf(FT, NewArgs);
 
   fputs(Buffer, (FILE *) GVTOP(Args[0]));
diff --git a/llvm/lib/ExecutionEngine/Orc/Debugging/VTuneSupportPlugin.cpp b/llvm/lib/ExecutionEngine/Orc/Debugging/VTuneSupportPlugin.cpp
index 6a00b87dd0a6b..8793d6f8ab90b 100644
--- a/llvm/lib/ExecutionEngine/Orc/Debugging/VTuneSupportPlugin.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/Debugging/VTuneSupportPlugin.cpp
@@ -162,7 +162,7 @@ void VTuneSupportPlugin::notifyTransferringResources(JITDylib &JD,
     return;
 
   auto &Dest = LoadedMethodIDs[DstKey];
-  Dest.insert(Dest.end(), I->second.begin(), I->second.end());
+  llvm::append_range(Dest, I->second);
   LoadedMethodIDs.erase(SrcKey);
 }
 
diff --git a/llvm/lib/ExecutionEngine/Orc/LazyReexports.cpp b/llvm/lib/ExecutionEngine/Orc/LazyReexports.cpp
index 80f2a1304dde7..48b096f62ff29 100644
--- a/llvm/lib/ExecutionEngine/Orc/LazyReexports.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/LazyReexports.cpp
@@ -323,7 +323,7 @@ void LazyReexportsManager::handleTransferResources(JITDylib &JD,
     } else {
       auto &SrcAddrs = I->second;
       auto &DstAddrs = J->second;
-      DstAddrs.insert(DstAddrs.end(), SrcAddrs.begin(), SrcAddrs.end());
+      llvm::append_range(DstAddrs, SrcAddrs);
       KeyToReentryAddrs.erase(I);
     }
     if (L)
@@ -503,7 +503,7 @@ void SimpleLazyReexportsSpeculator::onLazyReexportsTransfered(
   } else {
     auto &SrcNames = J->second;
     auto &DstNames = K->second;
-    DstNames.insert(DstNames.end(), SrcNames.begin(), SrcNames.end());
+    llvm::append_range(DstNames, SrcNames);
     MapForJD.erase(J);
   }
 }
diff --git a/llvm/lib/IR/DebugInfoMetadata.cpp b/llvm/lib/IR/DebugInfoMetadata.cpp
index 12aba7d2bd123..b8b824aed7178 100644
--- a/llvm/lib/IR/DebugInfoMetadata.cpp
+++ b/llvm/lib/IR/DebugInfoMetadata.cpp
@@ -1990,7 +1990,7 @@ DIExpression *DIExpression::appendOpsToArg(const DIExpression *Expr,
     }
     Op.appendToVector(NewOps);
     if (Op.getOp() == dwarf::DW_OP_LLVM_arg && Op.getArg(0) == ArgNo)
-      NewOps.insert(NewOps.end(), Ops.begin(), Ops.end());
+      llvm::append_range(NewOps, Ops);
   }
   if (StackValue)
     NewOps.push_back(dwarf::DW_OP_stack_value);
diff --git a/llvm/lib/MC/DXContainerPSVInfo.cpp b/llvm/lib/MC/DXContainerPSVInfo.cpp
index aeff693801397..f70c8b1af01b3 100644
--- a/llvm/lib/MC/DXContainerPSVInfo.cpp
+++ b/llvm/lib/MC/DXContainerPSVInfo.cpp
@@ -58,8 +58,7 @@ ProcessElementList(StringTableBuilder &StrTabBuilder,
     size_t Idx = FindSequence(IndexBuffer, El.Indices);
     if (Idx == npos) {
       FinalElement.IndicesOffset = static_cast<uint32_t>(IndexBuffer.size());
-      IndexBuffer.insert(IndexBuffer.end(), El.Indices.begin(),
-                         El.Indices.end());
+      llvm::append_range(IndexBuffer, El.Indices);
     } else
       FinalElement.IndicesOffset = static_cast<uint32_t>(Idx);
     FinalElements.push_back(FinalElement);
diff --git a/llvm/lib/MC/MCParser/MasmParser.cpp b/llvm/lib/MC/MCParser/MasmParser.cpp
index bbcdffd4d4fa8..f758020566465 100644
--- a/llvm/lib/MC/MCParser/MasmParser.cpp
+++ b/llvm/lib/MC/MCParser/MasmParser.cpp
@@ -3647,9 +3647,8 @@ bool MasmParser::parseFieldInitializer(const FieldInfo &Field,
                           std::to_string(Initializers.size()));
   }
   // Default-initialize all remaining values.
-  Initializers.insert(Initializers.end(),
-                      Contents.Initializers.begin() + Initializers.size(),
-                      Contents.Initializers.end());
+  llvm::append_range(Initializers, llvm::drop_begin(Contents.Initializers,
+                                                    Initializers.size()));
 
   Initializer = FieldInitializer(std::move(Initializers), Contents.Structure);
   return false;
diff --git a/llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp b/llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp
index b0ec215aec203..935f89ad76440 100644
--- a/llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp
+++ b/llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp
@@ -662,13 +662,13 @@ RemoveNoteDetail::updateData(ArrayRef<uint8_t> OldData,
   for (const DeletedRange &RemRange : ToRemove) {
     if (CurPos < RemRange.OldFrom) {
       auto Slice = OldData.slice(CurPos, RemRange.OldFrom - CurPos);
-      NewData.insert(NewData.end(), Slice.begin(), Slice.end());
+      llvm::append_range(NewData, Slice);
     }
     CurPos = RemRange.OldTo;
   }
   if (CurPos < OldData.size()) {
     auto Slice = OldData.slice(CurPos);
-    NewData.insert(NewData.end(), Slice.begin(), Slice.end());
+    llvm::append_range(NewData, Slice);
   }
   return NewData;
 }
diff --git a/llvm/lib/ProfileData/InstrProfReader.cpp b/llvm/lib/ProfileData/InstrProfReader.cpp
index cac1760d3ef80..4075b513c218d 100644
--- a/llvm/lib/ProfileData/InstrProfReader.cpp
+++ b/llvm/lib/ProfileData/InstrProfReader.cpp
@@ -1096,7 +1096,7 @@ class llvm::InstrProfReaderItaniumRemapper
                                SmallVectorImpl<char> &Out) {
     Out.reserve(OrigName.size() + Replacement.size() - ExtractedName.size());
     Out.insert(Out.end(), OrigName.begin(), ExtractedName.begin());
-    Out.insert(Out.end(), Replacement.begin(), Replacement.end());
+    llvm::append_range(Out, Replacement);
     Out.insert(Out.end(), ExtractedName.end(), OrigName.end());
   }
 
diff --git a/llvm/lib/TargetParser/SubtargetFeature.cpp b/llvm/lib/TargetParser/SubtargetFeature.cpp
index be42a42967332..36c67f661d9a5 100644
--- a/llvm/lib/TargetParser/SubtargetFeature.cpp
+++ b/llvm/lib/TargetParser/SubtargetFeature.cpp
@@ -43,7 +43,7 @@ void SubtargetFeatures::AddFeature(StringRef String, bool Enable) {
 
 void SubtargetFeatures::addFeaturesVector(
     const ArrayRef<std::string> OtherFeatures) {
-  Features.insert(Features.cend(), OtherFeatures.begin(), OtherFeatures.end());
+  llvm::append_range(Features, OtherFeatures);
 }
 
 SubtargetFeatures::SubtargetFeatures(StringRef Initial) {
diff --git a/llvm/unittests/DebugInfo/DWARF/DwarfGenerator.cpp b/llvm/unittests/DebugInfo/DWARF/DwarfGenerator.cpp
index cf4a5f27585d0..f8d161d8c50b6 100644
--- a/llvm/unittests/DebugInfo/DWARF/DwarfGenerator.cpp
+++ b/llvm/unittests/DebugInfo/DWARF/DwarfGenerator.cpp
@@ -243,7 +243,7 @@ void dwarfgen::LineTable::addByte(uint8_t Value) {
 void dwarfgen::LineTable::addStandardOpcode(uint8_t Opcode,
                                             ArrayRef<ValueAndLength> Operands) {
   Contents.push_back({Opcode, Byte});
-  Contents.insert(Contents.end(), Operands.begin(), Operands.end());
+  llvm::append_range(Contents, Operands);
 }
 
 void dwarfgen::LineTable::addExtendedOpcode(uint64_t Length, uint8_t Opcode,
@@ -251,7 +251,7 @@ void dwarfgen::LineTable::addExtendedOpcode(uint64_t Length, uint8_t Opcode,
   Contents.push_back({0, Byte});
   Contents.push_back({Length, ULEB});
   Contents.push_back({Opcode, Byte});
-  Contents.insert(Contents.end(), Operands.begin(), Operands.end());
+  llvm::append_range(Contents, Operands);
 }
 
 void dwarfgen::LineTable::generate(MCContext &MC, AsmPrinter &Asm) const {
diff --git a/llvm/unittests/DebugInfo/PDB/HashTableTest.cpp b/llvm/unittests/DebugInfo/PDB/HashTableTest.cpp
index 6d17332f49079..94e82ed02c398 100644
--- a/llvm/unittests/DebugInfo/PDB/HashTableTest.cpp
+++ b/llvm/unittests/DebugInfo/PDB/HashTableTest.cpp
@@ -233,7 +233,7 @@ struct FooBarHashTraits {
 
   uint32_t lookupKeyToStorageKey(StringRef S) {
     uint32_t N = Buffer.size();
-    Buffer.insert(Buffer.end(), S.begin(), S.end());
+    llvm::append_range(Buffer, S);
     Buffer.push_back('\0');
     return N;
   }
diff --git a/llvm/unittests/Transforms/IPO/LowerTypeTests.cpp b/llvm/unittests/Transforms/IPO/LowerTypeTests.cpp
index ba13378099ecb..1602826b7252c 100644
--- a/llvm/unittests/Transforms/IPO/LowerTypeTests.cpp
+++ b/llvm/unittests/Transforms/IPO/LowerTypeTests.cpp
@@ -100,7 +100,7 @@ TEST(LowerTypeTests, GlobalLayoutBuilder) {
 
     std::vector<uint64_t> ComputedLayout;
     for (auto &&F : GLB.Fragments)
-      ComputedLayout.insert(ComputedLayout.end(), F.begin(), F.end());
+      llvm::append_range(ComputedLayout, F);
 
     EXPECT_EQ(T.WantLayout, ComputedLayout);
   }
diff --git a/llvm/utils/TableGen/Common/CodeGenRegisters.cpp b/llvm/utils/TableGen/Common/CodeGenRegisters.cpp
index 3a6e828a99f2d..eb142e66faf2f 100644
--- a/llvm/utils/TableGen/Common/CodeGenRegisters.cpp
+++ b/llvm/utils/TableGen/Common/CodeGenRegisters.cpp
@@ -678,7 +678,7 @@ struct TupleExpander : SetTheory::Expander {
       // Take the cost list of the first register in the tuple.
       const ListInit *CostList = Proto->getValueAsListInit("CostPerUse");
       SmallVector<const Init *, 2> CostPerUse;
-      CostPerUse.insert(CostPerUse.end(), CostList->begin(), CostList->end());
+      llvm::append_range(CostPerUse, *CostList);
 
       const StringInit *AsmName = StringInit::get(RK, "");
       if (!RegNames.empty()) {
@@ -1186,7 +1186,7 @@ void CodeGenRegisterClass::extendSuperRegClasses(CodeGenSubRegIndex *SubIdx) {
     return;
 
   SmallVector<CodeGenRegisterClass *> MidRCs;
-  MidRCs.insert(MidRCs.end(), It->second.begin(), It->second.end());
+  llvm::append_range(MidRCs, It->second);
 
   for (CodeGenRegisterClass *MidRC : MidRCs) {
     for (auto &Pair : MidRC->SuperRegClasses) {
@@ -1244,7 +1244,7 @@ CodeGenRegBank::CodeGenRegBank(const RecordKeeper &Records,
     for (const Record *R : Records.getAllDerivedDefinitions("RegisterTuples")) {
       // Expand tuples and merge the vectors
       std::vector<const Record *> TupRegs = *Sets.expand(R);
-      Regs.insert(Regs.end(), TupRegs.begin(), TupRegs.end());
+      llvm::append_range(Regs, TupRegs);
     }
 
     llvm::sort(Regs, LessRecordRegister());
diff --git a/llvm/utils/TableGen/RegisterInfoEmitter.cpp b/llvm/utils/TableGen/RegisterInfoEmitter.cpp
index 45c6db94023b7..98f0d7eaaff38 100644
--- a/llvm/utils/TableGen/RegisterInfoEmitter.cpp
+++ b/llvm/utils/TableGen/RegisterInfoEmitter.cpp
@@ -1487,7 +1487,7 @@ void RegisterInfoEmitter::runTargetDesc(raw_ostream &OS) {
   // each register. Fill with zero for values which are not explicitly given.
   for (const auto &Reg : Regs) {
     auto Costs = Reg.CostPerUse;
-    AllRegCostPerUse.insert(AllRegCostPerUse.end(), Costs.begin(), Costs.end());
+    llvm::append_range(AllRegCostPerUse, Costs);
     if (NumRegCosts > Costs.size())
       AllRegCostPerUse.insert(AllRegCostPerUse.end(),
                               NumRegCosts - Costs.size(), 0);

>From 1c1a207b7a0af87d180204b0d57b351b4bded0c6 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Wed, 16 Apr 2025 10:18:41 -0700
Subject: [PATCH 2/2] Address a comment.

---
 llvm/include/llvm/IR/ModuleSummaryIndex.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/llvm/include/llvm/IR/ModuleSummaryIndex.h b/llvm/include/llvm/IR/ModuleSummaryIndex.h
index b4202fa627621..3f20d40722ca2 100644
--- a/llvm/include/llvm/IR/ModuleSummaryIndex.h
+++ b/llvm/include/llvm/IR/ModuleSummaryIndex.h
@@ -1319,8 +1319,10 @@ class CfiFunctionIndex {
 
   std::vector<StringRef> symbols() const {
     std::vector<StringRef> Symbols;
-    for (auto &[GUID, Syms] : Index)
+    for (auto &[GUID, Syms] : Index) {
+      (void)GUID;
       llvm::append_range(Symbols, Syms);
+    }
     return Symbols;
   }
 



More information about the llvm-commits mailing list