From 3f531552e66f242d4bfc0163be848f9e51259d80 Mon Sep 17 00:00:00 2001 From: SahilPatidar Date: Sat, 28 Jun 2025 11:12:59 +0530 Subject: [REAPPLY][Clang-Repl] Add support for out-of-process execution. #110418 (#144064) This PR introduces out-of-process (OOP) execution support for Clang-Repl. With this enhancement, two new flags, oop-executor and oop-executor-connect, are added to the Clang-Repl interface. These flags enable the launch of an external executor (llvm-jitlink-executor), which handles code execution in a separate process. --- clang/lib/Interpreter/Interpreter.cpp | 39 ++++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 8 deletions(-) (limited to 'clang/lib/Interpreter/Interpreter.cpp') diff --git a/clang/lib/Interpreter/Interpreter.cpp b/clang/lib/Interpreter/Interpreter.cpp index 84feff8..2f11065 100644 --- a/clang/lib/Interpreter/Interpreter.cpp +++ b/clang/lib/Interpreter/Interpreter.cpp @@ -46,6 +46,7 @@ #include "clang/Sema/Lookup.h" #include "clang/Serialization/ObjectFilePCHContainerReader.h" #include "llvm/ExecutionEngine/JITSymbol.h" +#include "llvm/ExecutionEngine/Orc/EPCDynamicLibrarySearchGenerator.h" #include "llvm/ExecutionEngine/Orc/LLJIT.h" #include "llvm/IR/Module.h" #include "llvm/Support/Errc.h" @@ -455,10 +456,11 @@ const char *const Runtimes = R"( )"; llvm::Expected> -Interpreter::create(std::unique_ptr CI) { +Interpreter::create(std::unique_ptr CI, + std::unique_ptr JB) { llvm::Error Err = llvm::Error::success(); - auto Interp = - std::unique_ptr(new Interpreter(std::move(CI), Err)); + auto Interp = std::unique_ptr( + new Interpreter(std::move(CI), Err, JB ? std::move(JB) : nullptr)); if (Err) return std::move(Err); @@ -617,6 +619,25 @@ createJITTargetMachineBuilder(const std::string &TT) { return llvm::orc::JITTargetMachineBuilder(llvm::Triple(TT)); } +llvm::Expected> +Interpreter::createLLJITBuilder( + std::unique_ptr EPC, + llvm::StringRef OrcRuntimePath) { + const std::string &TT = EPC->getTargetTriple().getTriple(); + auto JTMB = createJITTargetMachineBuilder(TT); + if (!JTMB) + return JTMB.takeError(); + auto JB = IncrementalExecutor::createDefaultJITBuilder(std::move(*JTMB)); + if (!JB) + return JB.takeError(); + + (*JB)->setExecutorProcessControl(std::move(EPC)); + (*JB)->setPlatformSetUp( + llvm::orc::ExecutorNativePlatform(OrcRuntimePath.str())); + + return std::move(*JB); +} + llvm::Error Interpreter::CreateExecutor() { if (IncrExecutor) return llvm::make_error("Operation failed. " @@ -756,11 +777,13 @@ llvm::Error Interpreter::LoadDynamicLibrary(const char *name) { if (!EE) return EE.takeError(); - auto &DL = EE->getDataLayout(); - - if (auto DLSG = llvm::orc::DynamicLibrarySearchGenerator::Load( - name, DL.getGlobalPrefix())) - EE->getMainJITDylib().addGenerator(std::move(*DLSG)); + if (llvm::Expected< + std::unique_ptr> + DLSG = llvm::orc::EPCDynamicLibrarySearchGenerator::Load( + EE->getExecutionSession(), name)) + // FIXME: Eventually we should put each library in its own JITDylib and + // turn off process symbols by default. + EE->getProcessSymbolsJITDylib()->addGenerator(std::move(*DLSG)); else return DLSG.takeError(); #endif -- cgit v1.1