================
@@ -347,20 +348,118 @@ const char *const Runtimes = R"(
EXTERN_C void __clang_Interpreter_SetValueNoAlloc(void *This, void *OutVal,
void *OpaqueType, ...);
)";
+#ifndef _WIN32
+llvm::Expected<std::pair<std::unique_ptr<llvm::orc::LLJITBuilder>, pid_t>>
+Interpreter::outOfProcessJITBuilder(OutOfProcessJITConfig OutOfProcessConfig) {
+ std::unique_ptr<llvm::orc::ExecutorProcessControl> EPC;
+ pid_t childPid = -1;
+ if (OutOfProcessConfig.OOPExecutor != "") {
+ // Launch an out-of-process executor locally in a child process.
+ auto ResultOrErr = IncrementalExecutor::launchExecutor(
+ OutOfProcessConfig.OOPExecutor, OutOfProcessConfig.UseSharedMemory,
+ OutOfProcessConfig.SlabAllocateSizeString);
+ if (!ResultOrErr)
+ return ResultOrErr.takeError();
+ childPid = ResultOrErr->second;
+ auto EPCOrErr = std::move(ResultOrErr->first);
+ EPC = std::move(EPCOrErr);
+ } else if (OutOfProcessConfig.OOPExecutorConnect != "") {
+ auto EPCOrErr = IncrementalExecutor::connectTCPSocket(
+ OutOfProcessConfig.OOPExecutorConnect,
+ OutOfProcessConfig.UseSharedMemory,
+ OutOfProcessConfig.SlabAllocateSizeString);
+ if (!EPCOrErr)
+ return EPCOrErr.takeError();
+ EPC = std::move(*EPCOrErr);
+ }
+
+ std::unique_ptr<llvm::orc::LLJITBuilder> JB;
+ if (EPC) {
+ auto JBOrErr = clang::Interpreter::createLLJITBuilder(
+ std::move(EPC), OutOfProcessConfig.OrcRuntimePath);
+ if (!JBOrErr)
+ return JBOrErr.takeError();
+ JB = std::move(*JBOrErr);
+ }
+
+ return std::make_pair(std::move(JB), childPid);
+}
+
+llvm::Expected<std::string>
+Interpreter::getOrcRuntimePath(const driver::ToolChain &TC) {
+ std::optional<std::string> CompilerRTPath = TC.getCompilerRTPath();
+ std::optional<std::string> ResourceDir = TC.getRuntimePath();
+
+ if (!CompilerRTPath) {
+ return llvm::make_error<llvm::StringError>("CompilerRT path not found",
+ std::error_code());
+ }
+
+ const std::array<const char *, 3> OrcRTLibNames = {
+ "liborc_rt.a", "liborc_rt_osx.a", "liborc_rt-x86_64.a"};
+
+ for (const char *LibName : OrcRTLibNames) {
+ llvm::SmallString<256> CandidatePath((*CompilerRTPath).c_str());
+ llvm::sys::path::append(CandidatePath, LibName);
+
+ if (llvm::sys::fs::exists(CandidatePath)) {
+ return CandidatePath.str().str();
+ }
+ }
+
+ return llvm::make_error<llvm::StringError>(
+ llvm::Twine("OrcRuntime library not found in: ") + (*CompilerRTPath),
+ std::error_code());
+}
+#endif
+
llvm::Expected<std::unique_ptr<Interpreter>>
Interpreter::create(std::unique_ptr<CompilerInstance> CI,
- std::unique_ptr<llvm::orc::LLJITBuilder> JB) {
+ std::optional<OutOfProcessJITConfig> OutOfProcessConfig) {
llvm::Error Err = llvm::Error::success();
- auto Interp = std::unique_ptr<Interpreter>(
- new Interpreter(std::move(CI), Err, JB ? std::move(JB) : nullptr));
- if (Err)
- return std::move(Err);
+
+ std::unique_ptr<llvm::orc::LLJITBuilder> JB;
+
+#ifndef _WIN32
----------------
vgvassilev wrote:
Likewise.
https://github.com/llvm/llvm-project/pull/155140
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits