diff options
author | SahilPatidar <patidarsahil2001@gmail.com> | 2025-06-28 11:12:59 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-06-28 08:42:59 +0300 |
commit | 3f531552e66f242d4bfc0163be848f9e51259d80 (patch) | |
tree | a739d7d65a274b37e614375d66adc73c4cd38aa6 /clang/lib/Interpreter/Interpreter.cpp | |
parent | ac9204de7d4f9010506474b532654fa4bd15edfc (diff) | |
download | llvm-3f531552e66f242d4bfc0163be848f9e51259d80.zip llvm-3f531552e66f242d4bfc0163be848f9e51259d80.tar.gz llvm-3f531552e66f242d4bfc0163be848f9e51259d80.tar.bz2 |
[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.
Diffstat (limited to 'clang/lib/Interpreter/Interpreter.cpp')
-rw-r--r-- | clang/lib/Interpreter/Interpreter.cpp | 39 |
1 files changed, 31 insertions, 8 deletions
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<std::unique_ptr<Interpreter>> -Interpreter::create(std::unique_ptr<CompilerInstance> CI) { +Interpreter::create(std::unique_ptr<CompilerInstance> CI, + std::unique_ptr<llvm::orc::LLJITBuilder> JB) { llvm::Error Err = llvm::Error::success(); - auto Interp = - std::unique_ptr<Interpreter>(new Interpreter(std::move(CI), Err)); + auto Interp = std::unique_ptr<Interpreter>( + 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<std::unique_ptr<llvm::orc::LLJITBuilder>> +Interpreter::createLLJITBuilder( + std::unique_ptr<llvm::orc::ExecutorProcessControl> 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<llvm::StringError>("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<llvm::orc::EPCDynamicLibrarySearchGenerator>> + 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 |