[llvm] [ExecutionEngine] Avoid repeated hash lookups (NFC) (PR #133615)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Sat Mar 29 21:21:45 PDT 2025
https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/133615
None
>From 79d4f93d66dee20f0930849f9b4ef20ec52758db Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Sat, 29 Mar 2025 18:51:25 -0700
Subject: [PATCH] [ExecutionEngine] Avoid repeated hash lookups (NFC)
---
llvm/lib/ExecutionEngine/JITLink/EHFrameSupport.cpp | 3 +--
llvm/lib/ExecutionEngine/Orc/COFFVCRuntimeSupport.cpp | 3 +--
llvm/lib/ExecutionEngine/Orc/Core.cpp | 7 +++----
llvm/lib/ExecutionEngine/Orc/IRPartitionLayer.cpp | 3 +--
llvm/lib/ExecutionEngine/Orc/LLJIT.cpp | 6 ++----
llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp | 6 ++----
llvm/lib/ExecutionEngine/Orc/SimpleRemoteEPC.cpp | 3 +--
7 files changed, 11 insertions(+), 20 deletions(-)
diff --git a/llvm/lib/ExecutionEngine/JITLink/EHFrameSupport.cpp b/llvm/lib/ExecutionEngine/JITLink/EHFrameSupport.cpp
index 72e5f701f89a7..abe9ae7a3da16 100644
--- a/llvm/lib/ExecutionEngine/JITLink/EHFrameSupport.cpp
+++ b/llvm/lib/ExecutionEngine/JITLink/EHFrameSupport.cpp
@@ -70,8 +70,7 @@ Error EHFrameEdgeFixer::operator()(LinkGraph &G) {
// Sort eh-frame blocks into address order to ensure we visit CIEs before
// their child FDEs.
std::vector<Block *> EHFrameBlocks;
- for (auto *B : EHFrame->blocks())
- EHFrameBlocks.push_back(B);
+ llvm::append_range(EHFrameBlocks, EHFrame->blocks());
llvm::sort(EHFrameBlocks, [](const Block *LHS, const Block *RHS) {
return LHS->getAddress() < RHS->getAddress();
});
diff --git a/llvm/lib/ExecutionEngine/Orc/COFFVCRuntimeSupport.cpp b/llvm/lib/ExecutionEngine/Orc/COFFVCRuntimeSupport.cpp
index 94f696fa20863..c785381175284 100644
--- a/llvm/lib/ExecutionEngine/Orc/COFFVCRuntimeSupport.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/COFFVCRuntimeSupport.cpp
@@ -86,8 +86,7 @@ Error COFFVCRuntimeBootstrapper::loadVCRuntime(
if (!G)
return G.takeError();
- for (auto &Lib : (*G)->getImportedDynamicLibraries())
- ImportedLibraries.push_back(Lib);
+ llvm::append_range(ImportedLibraries, (*G)->getImportedDynamicLibraries());
JD.addGenerator(std::move(*G));
diff --git a/llvm/lib/ExecutionEngine/Orc/Core.cpp b/llvm/lib/ExecutionEngine/Orc/Core.cpp
index d6673552e39fd..cbed057950aea 100644
--- a/llvm/lib/ExecutionEngine/Orc/Core.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/Core.cpp
@@ -127,8 +127,7 @@ void UnsatisfiedSymbolDependencies::log(raw_ostream &OS) const {
SymbolsNotFound::SymbolsNotFound(std::shared_ptr<SymbolStringPool> SSP,
SymbolNameSet Symbols)
: SSP(std::move(SSP)) {
- for (auto &Sym : Symbols)
- this->Symbols.push_back(Sym);
+ llvm::append_range(this->Symbols, Symbols);
assert(!this->Symbols.empty() && "Can not fail to resolve an empty set");
}
@@ -2387,8 +2386,8 @@ void ExecutionSession::OL_applyQueryPhase1(
// Build the definition generator stack for this JITDylib.
runSessionLocked([&] {
IPLS->CurDefGeneratorStack.reserve(JD.DefGenerators.size());
- for (auto &DG : reverse(JD.DefGenerators))
- IPLS->CurDefGeneratorStack.push_back(DG);
+ llvm::append_range(IPLS->CurDefGeneratorStack,
+ reverse(JD.DefGenerators));
});
// Flag that we've done our initialization.
diff --git a/llvm/lib/ExecutionEngine/Orc/IRPartitionLayer.cpp b/llvm/lib/ExecutionEngine/Orc/IRPartitionLayer.cpp
index 9ad171beac7fe..1a37469c35d2e 100644
--- a/llvm/lib/ExecutionEngine/Orc/IRPartitionLayer.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/IRPartitionLayer.cpp
@@ -260,8 +260,7 @@ void IRPartitionLayer::emitPartition(
{
std::vector<const GlobalValue *> HashGVs;
HashGVs.reserve(GVsToExtract->size());
- for (const auto *GV : *GVsToExtract)
- HashGVs.push_back(GV);
+ llvm::append_range(HashGVs, *GVsToExtract);
llvm::sort(HashGVs, [](const GlobalValue *LHS, const GlobalValue *RHS) {
return LHS->getName() < RHS->getName();
});
diff --git a/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp b/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
index 7d385f4cf2fbb..21ebe82c8a71a 100644
--- a/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
@@ -57,8 +57,7 @@ Function *addHelperAndWrapper(Module &M, StringRef WrapperName,
std::vector<Type *> HelperArgTypes;
for (auto *Arg : HelperPrefixArgs)
HelperArgTypes.push_back(Arg->getType());
- for (auto *T : WrapperFnType->params())
- HelperArgTypes.push_back(T);
+ llvm::append_range(HelperArgTypes, WrapperFnType->params());
auto *HelperFnType =
FunctionType::get(WrapperFnType->getReturnType(), HelperArgTypes, false);
auto *HelperFn = Function::Create(HelperFnType, GlobalValue::ExternalLinkage,
@@ -72,8 +71,7 @@ Function *addHelperAndWrapper(Module &M, StringRef WrapperName,
IRBuilder<> IB(EntryBlock);
std::vector<Value *> HelperArgs;
- for (auto *Arg : HelperPrefixArgs)
- HelperArgs.push_back(Arg);
+ llvm::append_range(HelperArgs, HelperPrefixArgs);
for (auto &Arg : WrapperFn->args())
HelperArgs.push_back(&Arg);
auto *HelperResult = IB.CreateCall(HelperFn, HelperArgs);
diff --git a/llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp b/llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp
index 498d438bc25d4..90194d7fcc119 100644
--- a/llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp
@@ -1676,10 +1676,8 @@ Error MachOPlatform::MachOPlatformPlugin::prepareSymbolTableRegistration(
// those names.
{
SmallVector<jitlink::Symbol *> SymsToProcess;
- for (auto *Sym : G.defined_symbols())
- SymsToProcess.push_back(Sym);
- for (auto *Sym : G.absolute_symbols())
- SymsToProcess.push_back(Sym);
+ llvm::append_range(SymsToProcess, G.defined_symbols());
+ llvm::append_range(SymsToProcess, G.absolute_symbols());
for (auto *Sym : SymsToProcess) {
if (!Sym->hasName())
diff --git a/llvm/lib/ExecutionEngine/Orc/SimpleRemoteEPC.cpp b/llvm/lib/ExecutionEngine/Orc/SimpleRemoteEPC.cpp
index 53d5e049798aa..3d816785cb76d 100644
--- a/llvm/lib/ExecutionEngine/Orc/SimpleRemoteEPC.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/SimpleRemoteEPC.cpp
@@ -47,8 +47,7 @@ lookupSymbolsAsyncHelper(EPCGenericDylibManager &DylibMgr,
return Complete(R.takeError());
Result.push_back({});
Result.back().reserve(R->size());
- for (auto Addr : *R)
- Result.back().push_back(Addr);
+ llvm::append_range(Result.back(), *R);
lookupSymbolsAsyncHelper(
DylibMgr, Request.drop_front(), std::move(Result),
More information about the llvm-commits
mailing list