https://github.com/kr-2003 updated https://github.com/llvm/llvm-project/pull/157358
>From 4410aeb08dc14a4f29c9ec0e8730a1bde3386665 Mon Sep 17 00:00:00 2001 From: kr-2003 <kumar.kr.abhi...@gmail.com> Date: Mon, 8 Sep 2025 00:19:44 +0530 Subject: [PATCH 1/4] [clang-repl] Adding custom lambda in launchExecutor --- clang/include/clang/Interpreter/Interpreter.h | 4 +++- clang/lib/Interpreter/IncrementalExecutor.cpp | 6 +++++- clang/lib/Interpreter/IncrementalExecutor.h | 3 ++- clang/lib/Interpreter/Interpreter.cpp | 2 +- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/clang/include/clang/Interpreter/Interpreter.h b/clang/include/clang/Interpreter/Interpreter.h index 61af7bf762d5e..54be57684c03f 100644 --- a/clang/include/clang/Interpreter/Interpreter.h +++ b/clang/include/clang/Interpreter/Interpreter.h @@ -135,11 +135,13 @@ class Interpreter { std::string OrcRuntimePath = ""; /// PID of the out-of-process JIT executor. uint32_t ExecutorPID = 0; + /// Custom lambda to be executed inside child process/executor + std::function<void()> CustomizeFork = nullptr; JITConfig() : IsOutOfProcess(false), OOPExecutor(""), OOPExecutorConnect(""), UseSharedMemory(false), SlabAllocateSize(0), OrcRuntimePath(""), - ExecutorPID(0) {} + ExecutorPID(0), CustomizeFork(nullptr) {} }; protected: diff --git a/clang/lib/Interpreter/IncrementalExecutor.cpp b/clang/lib/Interpreter/IncrementalExecutor.cpp index b0eb7d0e9f072..0cf11939fefd1 100644 --- a/clang/lib/Interpreter/IncrementalExecutor.cpp +++ b/clang/lib/Interpreter/IncrementalExecutor.cpp @@ -138,7 +138,8 @@ IncrementalExecutor::getSymbolAddress(llvm::StringRef Name, Expected<std::unique_ptr<llvm::jitlink::JITLinkMemoryManager>> createSharedMemoryManager(llvm::orc::SimpleRemoteEPC &SREPC, - unsigned SlabAllocateSize) { + unsigned SlabAllocateSize, + std::function<void()> CustomizeFork) { llvm::orc::SharedMemoryMapper::SymbolAddrs SAs; if (auto Err = SREPC.getBootstrapSymbols( {{SAs.Instance, @@ -215,6 +216,9 @@ IncrementalExecutor::launchExecutor(llvm::StringRef ExecutablePath, close(ToExecutor[WriteEnd]); close(FromExecutor[ReadEnd]); + if (CustomizeFork) + CustomizeFork(); + // Execute the child process. std::unique_ptr<char[]> ExecutorPath, FDSpecifier; { diff --git a/clang/lib/Interpreter/IncrementalExecutor.h b/clang/lib/Interpreter/IncrementalExecutor.h index d091535166770..bb1ec33452515 100644 --- a/clang/lib/Interpreter/IncrementalExecutor.h +++ b/clang/lib/Interpreter/IncrementalExecutor.h @@ -79,7 +79,8 @@ class IncrementalExecutor { static llvm::Expected< std::pair<std::unique_ptr<llvm::orc::SimpleRemoteEPC>, uint32_t>> launchExecutor(llvm::StringRef ExecutablePath, bool UseSharedMemory, - unsigned SlabAllocateSize); + unsigned SlabAllocateSize, + std::function<void()> CustomizeFork = nullptr); #if LLVM_ON_UNIX && LLVM_ENABLE_THREADS static llvm::Expected<std::unique_ptr<llvm::orc::SimpleRemoteEPC>> diff --git a/clang/lib/Interpreter/Interpreter.cpp b/clang/lib/Interpreter/Interpreter.cpp index 043e0c1e5754e..e17229a853a6f 100644 --- a/clang/lib/Interpreter/Interpreter.cpp +++ b/clang/lib/Interpreter/Interpreter.cpp @@ -355,7 +355,7 @@ Interpreter::outOfProcessJITBuilder(JITConfig Config) { if (!Config.OOPExecutor.empty()) { // Launch an out-of-process executor locally in a child process. auto ResultOrErr = IncrementalExecutor::launchExecutor( - Config.OOPExecutor, Config.UseSharedMemory, Config.SlabAllocateSize); + Config.OOPExecutor, Config.UseSharedMemory, Config.SlabAllocateSize, Config.CustomizeFork); if (!ResultOrErr) return ResultOrErr.takeError(); childPid = ResultOrErr->second; >From 0a09e011672db57c4a041a3719144dd90afdeb8d Mon Sep 17 00:00:00 2001 From: kr-2003 <kumar.kr.abhi...@gmail.com> Date: Mon, 8 Sep 2025 00:20:09 +0530 Subject: [PATCH 2/4] Formatting changes --- clang/lib/Interpreter/IncrementalExecutor.cpp | 2 +- clang/lib/Interpreter/Interpreter.cpp | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/clang/lib/Interpreter/IncrementalExecutor.cpp b/clang/lib/Interpreter/IncrementalExecutor.cpp index 0cf11939fefd1..792ecb08c5f33 100644 --- a/clang/lib/Interpreter/IncrementalExecutor.cpp +++ b/clang/lib/Interpreter/IncrementalExecutor.cpp @@ -139,7 +139,7 @@ IncrementalExecutor::getSymbolAddress(llvm::StringRef Name, Expected<std::unique_ptr<llvm::jitlink::JITLinkMemoryManager>> createSharedMemoryManager(llvm::orc::SimpleRemoteEPC &SREPC, unsigned SlabAllocateSize, - std::function<void()> CustomizeFork) { + std::function<void()> CustomizeFork) { llvm::orc::SharedMemoryMapper::SymbolAddrs SAs; if (auto Err = SREPC.getBootstrapSymbols( {{SAs.Instance, diff --git a/clang/lib/Interpreter/Interpreter.cpp b/clang/lib/Interpreter/Interpreter.cpp index e17229a853a6f..2425a628b59b9 100644 --- a/clang/lib/Interpreter/Interpreter.cpp +++ b/clang/lib/Interpreter/Interpreter.cpp @@ -355,7 +355,8 @@ Interpreter::outOfProcessJITBuilder(JITConfig Config) { if (!Config.OOPExecutor.empty()) { // Launch an out-of-process executor locally in a child process. auto ResultOrErr = IncrementalExecutor::launchExecutor( - Config.OOPExecutor, Config.UseSharedMemory, Config.SlabAllocateSize, Config.CustomizeFork); + Config.OOPExecutor, Config.UseSharedMemory, Config.SlabAllocateSize, + Config.CustomizeFork); if (!ResultOrErr) return ResultOrErr.takeError(); childPid = ResultOrErr->second; >From 268826a35221f15549d595226d709922bca98abc Mon Sep 17 00:00:00 2001 From: kr-2003 <kumar.kr.abhi...@gmail.com> Date: Mon, 8 Sep 2025 00:35:44 +0530 Subject: [PATCH 3/4] Formatting changes & fixing bug --- clang/lib/Interpreter/IncrementalExecutor.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/clang/lib/Interpreter/IncrementalExecutor.cpp b/clang/lib/Interpreter/IncrementalExecutor.cpp index 792ecb08c5f33..5bec3b44a0dc0 100644 --- a/clang/lib/Interpreter/IncrementalExecutor.cpp +++ b/clang/lib/Interpreter/IncrementalExecutor.cpp @@ -173,7 +173,8 @@ createSharedMemoryManager(llvm::orc::SimpleRemoteEPC &SREPC, llvm::Expected<std::pair<std::unique_ptr<llvm::orc::SimpleRemoteEPC>, uint32_t>> IncrementalExecutor::launchExecutor(llvm::StringRef ExecutablePath, bool UseSharedMemory, - unsigned SlabAllocateSize) { + unsigned SlabAllocateSize, + std::function<void()> CustomizeFork) { #ifndef LLVM_ON_UNIX // FIXME: Add support for Windows. return llvm::make_error<llvm::StringError>( >From cf4c8766088524ad3b7ffe4d927325185c8c262a Mon Sep 17 00:00:00 2001 From: kr-2003 <kumar.kr.abhi...@gmail.com> Date: Mon, 8 Sep 2025 00:49:32 +0530 Subject: [PATCH 4/4] Removing extra arg from sharedMem --- clang/lib/Interpreter/IncrementalExecutor.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/clang/lib/Interpreter/IncrementalExecutor.cpp b/clang/lib/Interpreter/IncrementalExecutor.cpp index 5bec3b44a0dc0..45620fcd358c8 100644 --- a/clang/lib/Interpreter/IncrementalExecutor.cpp +++ b/clang/lib/Interpreter/IncrementalExecutor.cpp @@ -138,8 +138,7 @@ IncrementalExecutor::getSymbolAddress(llvm::StringRef Name, Expected<std::unique_ptr<llvm::jitlink::JITLinkMemoryManager>> createSharedMemoryManager(llvm::orc::SimpleRemoteEPC &SREPC, - unsigned SlabAllocateSize, - std::function<void()> CustomizeFork) { + unsigned SlabAllocateSize) { llvm::orc::SharedMemoryMapper::SymbolAddrs SAs; if (auto Err = SREPC.getBootstrapSymbols( {{SAs.Instance, _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits