[llvm] [ORC] Use SmallVector/SmallString for small hot paths (PR #148379)
Bogdan Vetrenko via llvm-commits
llvm-commits at lists.llvm.org
Sat Jul 12 12:26:15 PDT 2025
https://github.com/bv2k4 updated https://github.com/llvm/llvm-project/pull/148379
>From 0623a934156c98909d762051bc3e52a55b80318f Mon Sep 17 00:00:00 2001
From: Bogdan Vetrenko <b.vetrenko at yandex.ru>
Date: Sat, 12 Jul 2025 18:35:45 +0300
Subject: [PATCH] [ORC] Use SmallVector/SmallString for small hot paths
---
llvm/lib/ExecutionEngine/Orc/LLJIT.cpp | 18 ++++++++----------
1 file changed, 8 insertions(+), 10 deletions(-)
diff --git a/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp b/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
index 67bb7dd8ad08f..f36760ee4433d 100644
--- a/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
@@ -8,6 +8,7 @@
#include "llvm/ExecutionEngine/Orc/LLJIT.h"
+#include "llvm/ADT/SmallString.h"
#include "llvm/Analysis/TargetLibraryInfo.h"
#include "llvm/Config/llvm-config.h" // for LLVM_ENABLE_THREADS
#include "llvm/ExecutionEngine/Orc/COFFPlatform.h"
@@ -331,7 +332,7 @@ class GenericLLVMIRPlatformSupport : public LLJIT::PlatformSupport {
Initializers.push_back(KV.second.getAddress());
}
- return Initializers;
+ return std::vector<ExecutorAddr>(Initializers.begin(), Initializers.end());;
}
Expected<std::vector<ExecutorAddr>> getDeinitializers(JITDylib &JD) {
@@ -392,7 +393,7 @@ class GenericLLVMIRPlatformSupport : public LLJIT::PlatformSupport {
DeInitializers.push_back(KV.second.getAddress());
}
- return DeInitializers;
+ return std::vector<ExecutorAddr>(DeInitializers.begin(), DeInitializers.end());;
}
/// Issue lookups for all init symbols required to initialize JD (and any
@@ -518,13 +519,10 @@ GlobalCtorDtorScraper::operator()(ThreadSafeModule TSM,
// If there's no llvm.global_c/dtor or it's just a decl then skip.
if (!GlobalCOrDtors || GlobalCOrDtors->isDeclaration())
return Error::success();
- std::string InitOrDeInitFunctionName;
- if (isCtor)
- raw_string_ostream(InitOrDeInitFunctionName)
- << InitFunctionPrefix << M.getModuleIdentifier();
- else
- raw_string_ostream(InitOrDeInitFunctionName)
- << DeInitFunctionPrefix << M.getModuleIdentifier();
+ SmallString<64> InitOrDeInitFunctionName;
+ raw_svector_ostream(InitOrDeInitFunctionName)
+ << (isCtor ? InitFunctionPrefix : DeInitFunctionPrefix)
+ << M.getModuleIdentifier();
MangleAndInterner Mangle(PS.getExecutionSession(), M.getDataLayout());
auto InternedInitOrDeInitName = Mangle(InitOrDeInitFunctionName);
@@ -536,7 +534,7 @@ GlobalCtorDtorScraper::operator()(ThreadSafeModule TSM,
FunctionType::get(Type::getVoidTy(Ctx), {}, false),
GlobalValue::ExternalLinkage, InitOrDeInitFunctionName, &M);
InitOrDeInitFunc->setVisibility(GlobalValue::HiddenVisibility);
- std::vector<std::pair<Function *, unsigned>> InitsOrDeInits;
+ SmallVector<std::pair<Function *, unsigned>, 8> InitsOrDeInits;
auto COrDtors = isCtor ? getConstructors(M) : getDestructors(M);
for (auto E : COrDtors)
More information about the llvm-commits
mailing list