[clang] [REAPPLY][Clang-Repl] Add support for out-of-process execution. #110418 (PR #144064)

2025-11-10 Thread Vassil Vassilev via cfe-commits

vgvassilev wrote:

Do we have some cache per test suite run to use? Perhaps we can compute that 
once and store it into a global lit cache and don’t re-evaluate many times?

https://github.com/llvm/llvm-project/pull/144064
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [REAPPLY][Clang-Repl] Add support for out-of-process execution. #110418 (PR #144064)

2025-11-10 Thread Vassil Vassilev via cfe-commits

vgvassilev wrote:

CC: @lhames 

https://github.com/llvm/llvm-project/pull/144064
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [REAPPLY][Clang-Repl] Add support for out-of-process execution. #110418 (PR #144064)

2025-11-10 Thread Vlad Serebrennikov via cfe-commits

Endilll wrote:

@SahilPatidar can you address this in a way that works for the intended purpose 
of this patch?

https://github.com/llvm/llvm-project/pull/144064
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [REAPPLY][Clang-Repl] Add support for out-of-process execution. #110418 (PR #144064)

2025-11-10 Thread Vlad Serebrennikov via cfe-commits

Endilll wrote:

I'd like to second Teresa's feedback. I'm working on Clang tests that normally 
take 4-5 seconds to run. This patch added 22 seconds of overhead to each lit 
invocation (average of 10 runs), making the experience significantly worse for 
me. It's not easy for me to ignore lit and run tests manually, because each has 
7 RUN lines all of which differ in a non-trivial way.

https://github.com/llvm/llvm-project/pull/144064
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [REAPPLY][Clang-Repl] Add support for out-of-process execution. #110418 (PR #144064)

2025-10-18 Thread Abhinav Kumar via cfe-commits

kr-2003 wrote:

> I just tracked down slowness running clang tests locally to this change. It's 
> very noticeable if I run a single test, or a single directory of tests.

**Proposed work around for this:**
Determining Out-of-Process JIT support once during the Cmake configure step(not 
runtime), and dump the result into ``lit.site.cfg.py`` as a config variable. 
This eliminates the overhead but will not work in cross-compilation scenarios 
where we build for one target and run the tests on a different. Those bot 
owners will have to manually configure lit for their test environment.


https://github.com/llvm/llvm-project/pull/144064
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [REAPPLY][Clang-Repl] Add support for out-of-process execution. #110418 (PR #144064)

2025-10-17 Thread Teresa Johnson via cfe-commits

teresajohnson wrote:

I just tracked down slowness running clang tests locally to this change. It's 
very noticeable if I run a single test, or a single directory of tests.

When I ctrl-c the stack trace includes:
```
clang_repl_cmd = subprocess.run(
[clang_repl_exe, "-orc-runtime", "-oop-executor"],
```

I ran a single clang test 5 times each with current HEAD and with a "return 
False" right at the start of have_host_out_of_process_jit_feature_support.

Here are the user time comparisons:

```
time.out.off:   User time (seconds): 0.38
time.out.off:   User time (seconds): 0.36
time.out.off:   User time (seconds): 0.34
time.out.off:   User time (seconds): 0.40
time.out.off:   User time (seconds): 0.36
time.out.on:User time (seconds): 17.80
time.out.on:User time (seconds): 17.83
time.out.on:User time (seconds): 17.80
time.out.on:User time (seconds): 17.64
time.out.on:User time (seconds): 17.71
```

Can something be done to prevent this overhead?

https://github.com/llvm/llvm-project/pull/144064
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [REAPPLY][Clang-Repl] Add support for out-of-process execution. #110418 (PR #144064)

2025-07-08 Thread Anutosh Bhat via cfe-commits

https://github.com/anutosh491 milestoned 
https://github.com/llvm/llvm-project/pull/144064
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [REAPPLY][Clang-Repl] Add support for out-of-process execution. #110418 (PR #144064)

2025-06-27 Thread Vassil Vassilev via cfe-commits

https://github.com/vgvassilev closed 
https://github.com/llvm/llvm-project/pull/144064
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [REAPPLY][Clang-Repl] Add support for out-of-process execution. #110418 (PR #144064)

2025-06-27 Thread Vassil Vassilev via cfe-commits

https://github.com/vgvassilev updated 
https://github.com/llvm/llvm-project/pull/144064

>From 05943c9542cd89ae672ddc0f14514e0c7b1e0bd7 Mon Sep 17 00:00:00 2001
From: SahilPatidar 
Date: Tue, 3 Dec 2024 15:07:56 +0530
Subject: [PATCH 1/6] Re-Land: [Clang-Repl] Add support for out-of-process
 execution. #110418

---
 clang/include/clang/Interpreter/Interpreter.h |   7 +-
 .../clang/Interpreter/RemoteJITUtils.h|  38 +++
 clang/lib/Interpreter/CMakeLists.txt  |   1 +
 clang/lib/Interpreter/Interpreter.cpp |  37 ++-
 clang/lib/Interpreter/RemoteJITUtils.cpp  | 267 ++
 clang/tools/clang-repl/CMakeLists.txt |   2 +
 clang/tools/clang-repl/ClangRepl.cpp  | 123 +++-
 7 files changed, 465 insertions(+), 10 deletions(-)
 create mode 100644 clang/include/clang/Interpreter/RemoteJITUtils.h
 create mode 100644 clang/lib/Interpreter/RemoteJITUtils.cpp

diff --git a/clang/include/clang/Interpreter/Interpreter.h 
b/clang/include/clang/Interpreter/Interpreter.h
index f8663e3193a18..78dff1165dcf5 100644
--- a/clang/include/clang/Interpreter/Interpreter.h
+++ b/clang/include/clang/Interpreter/Interpreter.h
@@ -20,6 +20,7 @@
 
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ExecutionEngine/JITSymbol.h"
+#include "llvm/ExecutionEngine/Orc/ExecutorProcessControl.h"
 #include "llvm/ExecutionEngine/Orc/Shared/ExecutorAddress.h"
 #include "llvm/Support/Error.h"
 #include 
@@ -136,10 +137,14 @@ class Interpreter {
 public:
   virtual ~Interpreter();
   static llvm::Expected>
-  create(std::unique_ptr CI);
+  create(std::unique_ptr CI,
+ std::unique_ptr JITBuilder = nullptr);
   static llvm::Expected>
   createWithCUDA(std::unique_ptr CI,
  std::unique_ptr DCI);
+  static llvm::Expected>
+  createLLJITBuilder(std::unique_ptr EPC,
+ llvm::StringRef OrcRuntimePath);
   const ASTContext &getASTContext() const;
   ASTContext &getASTContext();
   const CompilerInstance *getCompilerInstance() const;
diff --git a/clang/include/clang/Interpreter/RemoteJITUtils.h 
b/clang/include/clang/Interpreter/RemoteJITUtils.h
new file mode 100644
index 0..8705a3b1f669d
--- /dev/null
+++ b/clang/include/clang/Interpreter/RemoteJITUtils.h
@@ -0,0 +1,38 @@
+//===-- RemoteJITUtils.h - Utilities for remote-JITing --*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// Utilities for ExecutorProcessControl-based remote JITing with Orc and
+// JITLink.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_INTERPRETER_REMOTEJITUTILS_H
+#define LLVM_CLANG_INTERPRETER_REMOTEJITUTILS_H
+
+#include "llvm/ADT/StringRef.h"
+#include "llvm/ExecutionEngine/Orc/Core.h"
+#include "llvm/ExecutionEngine/Orc/Layer.h"
+#include "llvm/ExecutionEngine/Orc/SimpleRemoteEPC.h"
+#include "llvm/Support/Error.h"
+
+#include 
+#include 
+#include 
+
+llvm::Expected>
+launchExecutor(llvm::StringRef ExecutablePath, bool UseSharedMemory,
+   llvm::StringRef SlabAllocateSizeString);
+
+/// Create a JITLinkExecutor that connects to the given network address
+/// through a TCP socket. A valid NetworkAddress provides hostname and port,
+/// e.g. localhost:2.
+llvm::Expected>
+connectTCPSocket(llvm::StringRef NetworkAddress, bool UseSharedMemory,
+ llvm::StringRef SlabAllocateSizeString);
+
+#endif // LLVM_CLANG_INTERPRETER_REMOTEJITUTILS_H
diff --git a/clang/lib/Interpreter/CMakeLists.txt 
b/clang/lib/Interpreter/CMakeLists.txt
index bf70cdfbee01e..38cf139fa86a6 100644
--- a/clang/lib/Interpreter/CMakeLists.txt
+++ b/clang/lib/Interpreter/CMakeLists.txt
@@ -27,6 +27,7 @@ add_clang_library(clangInterpreter
   Interpreter.cpp
   InterpreterValuePrinter.cpp
   InterpreterUtils.cpp
+  RemoteJITUtils.cpp
   Value.cpp
   ${WASM_SRC}
   PARTIAL_SOURCES_INTENDED
diff --git a/clang/lib/Interpreter/Interpreter.cpp 
b/clang/lib/Interpreter/Interpreter.cpp
index 84feff82c63a7..30051a24662c6 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), Er

[clang] [REAPPLY][Clang-Repl] Add support for out-of-process execution. #110418 (PR #144064)

2025-06-26 Thread via cfe-commits

https://github.com/SahilPatidar updated 
https://github.com/llvm/llvm-project/pull/144064

>From 05943c9542cd89ae672ddc0f14514e0c7b1e0bd7 Mon Sep 17 00:00:00 2001
From: SahilPatidar 
Date: Tue, 3 Dec 2024 15:07:56 +0530
Subject: [PATCH 1/6] Re-Land: [Clang-Repl] Add support for out-of-process
 execution. #110418

---
 clang/include/clang/Interpreter/Interpreter.h |   7 +-
 .../clang/Interpreter/RemoteJITUtils.h|  38 +++
 clang/lib/Interpreter/CMakeLists.txt  |   1 +
 clang/lib/Interpreter/Interpreter.cpp |  37 ++-
 clang/lib/Interpreter/RemoteJITUtils.cpp  | 267 ++
 clang/tools/clang-repl/CMakeLists.txt |   2 +
 clang/tools/clang-repl/ClangRepl.cpp  | 123 +++-
 7 files changed, 465 insertions(+), 10 deletions(-)
 create mode 100644 clang/include/clang/Interpreter/RemoteJITUtils.h
 create mode 100644 clang/lib/Interpreter/RemoteJITUtils.cpp

diff --git a/clang/include/clang/Interpreter/Interpreter.h 
b/clang/include/clang/Interpreter/Interpreter.h
index f8663e3193a18..78dff1165dcf5 100644
--- a/clang/include/clang/Interpreter/Interpreter.h
+++ b/clang/include/clang/Interpreter/Interpreter.h
@@ -20,6 +20,7 @@
 
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ExecutionEngine/JITSymbol.h"
+#include "llvm/ExecutionEngine/Orc/ExecutorProcessControl.h"
 #include "llvm/ExecutionEngine/Orc/Shared/ExecutorAddress.h"
 #include "llvm/Support/Error.h"
 #include 
@@ -136,10 +137,14 @@ class Interpreter {
 public:
   virtual ~Interpreter();
   static llvm::Expected>
-  create(std::unique_ptr CI);
+  create(std::unique_ptr CI,
+ std::unique_ptr JITBuilder = nullptr);
   static llvm::Expected>
   createWithCUDA(std::unique_ptr CI,
  std::unique_ptr DCI);
+  static llvm::Expected>
+  createLLJITBuilder(std::unique_ptr EPC,
+ llvm::StringRef OrcRuntimePath);
   const ASTContext &getASTContext() const;
   ASTContext &getASTContext();
   const CompilerInstance *getCompilerInstance() const;
diff --git a/clang/include/clang/Interpreter/RemoteJITUtils.h 
b/clang/include/clang/Interpreter/RemoteJITUtils.h
new file mode 100644
index 0..8705a3b1f669d
--- /dev/null
+++ b/clang/include/clang/Interpreter/RemoteJITUtils.h
@@ -0,0 +1,38 @@
+//===-- RemoteJITUtils.h - Utilities for remote-JITing --*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// Utilities for ExecutorProcessControl-based remote JITing with Orc and
+// JITLink.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_INTERPRETER_REMOTEJITUTILS_H
+#define LLVM_CLANG_INTERPRETER_REMOTEJITUTILS_H
+
+#include "llvm/ADT/StringRef.h"
+#include "llvm/ExecutionEngine/Orc/Core.h"
+#include "llvm/ExecutionEngine/Orc/Layer.h"
+#include "llvm/ExecutionEngine/Orc/SimpleRemoteEPC.h"
+#include "llvm/Support/Error.h"
+
+#include 
+#include 
+#include 
+
+llvm::Expected>
+launchExecutor(llvm::StringRef ExecutablePath, bool UseSharedMemory,
+   llvm::StringRef SlabAllocateSizeString);
+
+/// Create a JITLinkExecutor that connects to the given network address
+/// through a TCP socket. A valid NetworkAddress provides hostname and port,
+/// e.g. localhost:2.
+llvm::Expected>
+connectTCPSocket(llvm::StringRef NetworkAddress, bool UseSharedMemory,
+ llvm::StringRef SlabAllocateSizeString);
+
+#endif // LLVM_CLANG_INTERPRETER_REMOTEJITUTILS_H
diff --git a/clang/lib/Interpreter/CMakeLists.txt 
b/clang/lib/Interpreter/CMakeLists.txt
index bf70cdfbee01e..38cf139fa86a6 100644
--- a/clang/lib/Interpreter/CMakeLists.txt
+++ b/clang/lib/Interpreter/CMakeLists.txt
@@ -27,6 +27,7 @@ add_clang_library(clangInterpreter
   Interpreter.cpp
   InterpreterValuePrinter.cpp
   InterpreterUtils.cpp
+  RemoteJITUtils.cpp
   Value.cpp
   ${WASM_SRC}
   PARTIAL_SOURCES_INTENDED
diff --git a/clang/lib/Interpreter/Interpreter.cpp 
b/clang/lib/Interpreter/Interpreter.cpp
index 84feff82c63a7..30051a24662c6 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), 

[clang] [REAPPLY][Clang-Repl] Add support for out-of-process execution. #110418 (PR #144064)

2025-06-25 Thread Vassil Vassilev via cfe-commits

https://github.com/vgvassilev approved this pull request.

Modulo that one comment that's left -- LGTM!

https://github.com/llvm/llvm-project/pull/144064
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [REAPPLY][Clang-Repl] Add support for out-of-process execution. #110418 (PR #144064)

2025-06-25 Thread via cfe-commits

SahilPatidar wrote:

Will do.

https://github.com/llvm/llvm-project/pull/144064
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [REAPPLY][Clang-Repl] Add support for out-of-process execution. #110418 (PR #144064)

2025-06-25 Thread via cfe-commits

https://github.com/SahilPatidar updated 
https://github.com/llvm/llvm-project/pull/144064

>From 05943c9542cd89ae672ddc0f14514e0c7b1e0bd7 Mon Sep 17 00:00:00 2001
From: SahilPatidar 
Date: Tue, 3 Dec 2024 15:07:56 +0530
Subject: [PATCH 1/5] Re-Land: [Clang-Repl] Add support for out-of-process
 execution. #110418

---
 clang/include/clang/Interpreter/Interpreter.h |   7 +-
 .../clang/Interpreter/RemoteJITUtils.h|  38 +++
 clang/lib/Interpreter/CMakeLists.txt  |   1 +
 clang/lib/Interpreter/Interpreter.cpp |  37 ++-
 clang/lib/Interpreter/RemoteJITUtils.cpp  | 267 ++
 clang/tools/clang-repl/CMakeLists.txt |   2 +
 clang/tools/clang-repl/ClangRepl.cpp  | 123 +++-
 7 files changed, 465 insertions(+), 10 deletions(-)
 create mode 100644 clang/include/clang/Interpreter/RemoteJITUtils.h
 create mode 100644 clang/lib/Interpreter/RemoteJITUtils.cpp

diff --git a/clang/include/clang/Interpreter/Interpreter.h 
b/clang/include/clang/Interpreter/Interpreter.h
index f8663e3193a18..78dff1165dcf5 100644
--- a/clang/include/clang/Interpreter/Interpreter.h
+++ b/clang/include/clang/Interpreter/Interpreter.h
@@ -20,6 +20,7 @@
 
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ExecutionEngine/JITSymbol.h"
+#include "llvm/ExecutionEngine/Orc/ExecutorProcessControl.h"
 #include "llvm/ExecutionEngine/Orc/Shared/ExecutorAddress.h"
 #include "llvm/Support/Error.h"
 #include 
@@ -136,10 +137,14 @@ class Interpreter {
 public:
   virtual ~Interpreter();
   static llvm::Expected>
-  create(std::unique_ptr CI);
+  create(std::unique_ptr CI,
+ std::unique_ptr JITBuilder = nullptr);
   static llvm::Expected>
   createWithCUDA(std::unique_ptr CI,
  std::unique_ptr DCI);
+  static llvm::Expected>
+  createLLJITBuilder(std::unique_ptr EPC,
+ llvm::StringRef OrcRuntimePath);
   const ASTContext &getASTContext() const;
   ASTContext &getASTContext();
   const CompilerInstance *getCompilerInstance() const;
diff --git a/clang/include/clang/Interpreter/RemoteJITUtils.h 
b/clang/include/clang/Interpreter/RemoteJITUtils.h
new file mode 100644
index 0..8705a3b1f669d
--- /dev/null
+++ b/clang/include/clang/Interpreter/RemoteJITUtils.h
@@ -0,0 +1,38 @@
+//===-- RemoteJITUtils.h - Utilities for remote-JITing --*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// Utilities for ExecutorProcessControl-based remote JITing with Orc and
+// JITLink.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_INTERPRETER_REMOTEJITUTILS_H
+#define LLVM_CLANG_INTERPRETER_REMOTEJITUTILS_H
+
+#include "llvm/ADT/StringRef.h"
+#include "llvm/ExecutionEngine/Orc/Core.h"
+#include "llvm/ExecutionEngine/Orc/Layer.h"
+#include "llvm/ExecutionEngine/Orc/SimpleRemoteEPC.h"
+#include "llvm/Support/Error.h"
+
+#include 
+#include 
+#include 
+
+llvm::Expected>
+launchExecutor(llvm::StringRef ExecutablePath, bool UseSharedMemory,
+   llvm::StringRef SlabAllocateSizeString);
+
+/// Create a JITLinkExecutor that connects to the given network address
+/// through a TCP socket. A valid NetworkAddress provides hostname and port,
+/// e.g. localhost:2.
+llvm::Expected>
+connectTCPSocket(llvm::StringRef NetworkAddress, bool UseSharedMemory,
+ llvm::StringRef SlabAllocateSizeString);
+
+#endif // LLVM_CLANG_INTERPRETER_REMOTEJITUTILS_H
diff --git a/clang/lib/Interpreter/CMakeLists.txt 
b/clang/lib/Interpreter/CMakeLists.txt
index bf70cdfbee01e..38cf139fa86a6 100644
--- a/clang/lib/Interpreter/CMakeLists.txt
+++ b/clang/lib/Interpreter/CMakeLists.txt
@@ -27,6 +27,7 @@ add_clang_library(clangInterpreter
   Interpreter.cpp
   InterpreterValuePrinter.cpp
   InterpreterUtils.cpp
+  RemoteJITUtils.cpp
   Value.cpp
   ${WASM_SRC}
   PARTIAL_SOURCES_INTENDED
diff --git a/clang/lib/Interpreter/Interpreter.cpp 
b/clang/lib/Interpreter/Interpreter.cpp
index 84feff82c63a7..30051a24662c6 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), 

[clang] [REAPPLY][Clang-Repl] Add support for out-of-process execution. #110418 (PR #144064)

2025-06-18 Thread Vassil Vassilev via cfe-commits


@@ -0,0 +1,267 @@
+//===-- RemoteJITUtils.cpp - Utilities for remote-JITing *- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// FIXME: Unify this code with similar functionality in llvm-jitlink.
+//
+//===--===//
+
+#include "clang/Interpreter/RemoteJITUtils.h"
+
+#include "llvm/ADT/StringExtras.h"
+#include "llvm/ExecutionEngine/Orc/DebugObjectManagerPlugin.h"
+#include "llvm/ExecutionEngine/Orc/EPCDebugObjectRegistrar.h"
+#include "llvm/ExecutionEngine/Orc/EPCDynamicLibrarySearchGenerator.h"
+#include "llvm/ExecutionEngine/Orc/MapperJITLinkMemoryManager.h"
+#include "llvm/ExecutionEngine/Orc/Shared/OrcRTBridge.h"
+#include "llvm/ExecutionEngine/Orc/Shared/SimpleRemoteEPCUtils.h"
+#include "llvm/ExecutionEngine/Orc/TargetProcess/JITLoaderGDB.h"
+#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/Path.h"
+
+#ifdef LLVM_ON_UNIX
+#include 
+#include 
+#include 
+#include 
+#endif // LLVM_ON_UNIX
+
+using namespace llvm;
+using namespace llvm::orc;
+
+Expected getSlabAllocSize(StringRef SizeString) {
+  SizeString = SizeString.trim();
+
+  uint64_t Units = 1024;
+
+  if (SizeString.ends_with_insensitive("kb"))
+SizeString = SizeString.drop_back(2).rtrim();
+  else if (SizeString.ends_with_insensitive("mb")) {
+Units = 1024 * 1024;
+SizeString = SizeString.drop_back(2).rtrim();
+  } else if (SizeString.ends_with_insensitive("gb")) {
+Units = 1024 * 1024 * 1024;
+SizeString = SizeString.drop_back(2).rtrim();
+  }
+
+  uint64_t SlabSize = 0;
+  if (SizeString.getAsInteger(10, SlabSize))
+return make_error("Invalid numeric format for slab size",
+   inconvertibleErrorCode());
+
+  return SlabSize * Units;
+}
+
+Expected>
+createSharedMemoryManager(SimpleRemoteEPC &SREPC,
+  StringRef SlabAllocateSizeString) {
+  SharedMemoryMapper::SymbolAddrs SAs;
+  if (auto Err = SREPC.getBootstrapSymbols(
+  {{SAs.Instance, rt::ExecutorSharedMemoryMapperServiceInstanceName},
+   {SAs.Reserve,
+rt::ExecutorSharedMemoryMapperServiceReserveWrapperName},
+   {SAs.Initialize,
+rt::ExecutorSharedMemoryMapperServiceInitializeWrapperName},
+   {SAs.Deinitialize,
+rt::ExecutorSharedMemoryMapperServiceDeinitializeWrapperName},
+   {SAs.Release,
+rt::ExecutorSharedMemoryMapperServiceReleaseWrapperName}}))
+return std::move(Err);
+
+#ifdef _WIN32
+  size_t SlabSize = 1024 * 1024;
+#else
+  size_t SlabSize = 1024 * 1024 * 1024;
+#endif
+
+  if (!SlabAllocateSizeString.empty()) {
+if (auto S = getSlabAllocSize(SlabAllocateSizeString))

vgvassilev wrote:

Can we spell out the type?

https://github.com/llvm/llvm-project/pull/144064
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [REAPPLY][Clang-Repl] Add support for out-of-process execution. #110418 (PR #144064)

2025-06-18 Thread Vassil Vassilev via cfe-commits


@@ -756,11 +777,11 @@ 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 (auto DLSG = llvm::orc::EPCDynamicLibrarySearchGenerator::Load(

vgvassilev wrote:

Can we spell out the type here?

https://github.com/llvm/llvm-project/pull/144064
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [REAPPLY][Clang-Repl] Add support for out-of-process execution. #110418 (PR #144064)

2025-06-18 Thread Vassil Vassilev via cfe-commits


@@ -0,0 +1,267 @@
+//===-- RemoteJITUtils.cpp - Utilities for remote-JITing *- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// FIXME: Unify this code with similar functionality in llvm-jitlink.
+//
+//===--===//
+
+#include "clang/Interpreter/RemoteJITUtils.h"
+
+#include "llvm/ADT/StringExtras.h"
+#include "llvm/ExecutionEngine/Orc/DebugObjectManagerPlugin.h"
+#include "llvm/ExecutionEngine/Orc/EPCDebugObjectRegistrar.h"
+#include "llvm/ExecutionEngine/Orc/EPCDynamicLibrarySearchGenerator.h"
+#include "llvm/ExecutionEngine/Orc/MapperJITLinkMemoryManager.h"
+#include "llvm/ExecutionEngine/Orc/Shared/OrcRTBridge.h"
+#include "llvm/ExecutionEngine/Orc/Shared/SimpleRemoteEPCUtils.h"
+#include "llvm/ExecutionEngine/Orc/TargetProcess/JITLoaderGDB.h"
+#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/Path.h"
+
+#ifdef LLVM_ON_UNIX
+#include 
+#include 
+#include 
+#include 
+#endif // LLVM_ON_UNIX
+
+using namespace llvm;
+using namespace llvm::orc;
+
+Expected getSlabAllocSize(StringRef SizeString) {
+  SizeString = SizeString.trim();
+
+  uint64_t Units = 1024;
+
+  if (SizeString.ends_with_insensitive("kb"))
+SizeString = SizeString.drop_back(2).rtrim();
+  else if (SizeString.ends_with_insensitive("mb")) {
+Units = 1024 * 1024;
+SizeString = SizeString.drop_back(2).rtrim();
+  } else if (SizeString.ends_with_insensitive("gb")) {
+Units = 1024 * 1024 * 1024;
+SizeString = SizeString.drop_back(2).rtrim();
+  }
+
+  uint64_t SlabSize = 0;
+  if (SizeString.getAsInteger(10, SlabSize))
+return make_error("Invalid numeric format for slab size",
+   inconvertibleErrorCode());
+
+  return SlabSize * Units;
+}
+
+Expected>
+createSharedMemoryManager(SimpleRemoteEPC &SREPC,
+  StringRef SlabAllocateSizeString) {
+  SharedMemoryMapper::SymbolAddrs SAs;
+  if (auto Err = SREPC.getBootstrapSymbols(
+  {{SAs.Instance, rt::ExecutorSharedMemoryMapperServiceInstanceName},
+   {SAs.Reserve,
+rt::ExecutorSharedMemoryMapperServiceReserveWrapperName},
+   {SAs.Initialize,
+rt::ExecutorSharedMemoryMapperServiceInitializeWrapperName},
+   {SAs.Deinitialize,
+rt::ExecutorSharedMemoryMapperServiceDeinitializeWrapperName},
+   {SAs.Release,
+rt::ExecutorSharedMemoryMapperServiceReleaseWrapperName}}))
+return std::move(Err);
+
+#ifdef _WIN32
+  size_t SlabSize = 1024 * 1024;
+#else
+  size_t SlabSize = 1024 * 1024 * 1024;
+#endif
+
+  if (!SlabAllocateSizeString.empty()) {
+if (auto S = getSlabAllocSize(SlabAllocateSizeString))
+  SlabSize = *S;
+else
+  return S.takeError();
+  }
+
+  return MapperJITLinkMemoryManager::CreateWithMapper(
+  SlabSize, SREPC, SAs);
+}
+
+Expected>
+launchExecutor(StringRef ExecutablePath, bool UseSharedMemory,
+   llvm::StringRef SlabAllocateSizeString) {
+#ifndef LLVM_ON_UNIX
+  // FIXME: Add support for Windows.
+  return make_error("-" + ExecutablePath +
+ " not supported on non-unix platforms",
+ inconvertibleErrorCode());
+#elif !LLVM_ENABLE_THREADS
+  // Out of process mode using SimpleRemoteEPC depends on threads.
+  return make_error(
+  "-" + ExecutablePath +
+  " requires threads, but LLVM was built with "
+  "LLVM_ENABLE_THREADS=Off",
+  inconvertibleErrorCode());
+#else
+
+  if (!sys::fs::can_execute(ExecutablePath))
+return make_error(
+formatv("Specified executor invalid: {0}", ExecutablePath),
+inconvertibleErrorCode());
+
+  constexpr int ReadEnd = 0;
+  constexpr int WriteEnd = 1;
+
+  // Pipe FDs.
+  int ToExecutor[2];
+  int FromExecutor[2];
+
+  pid_t ChildPID;
+
+  // Create pipes to/from the executor..
+  if (pipe(ToExecutor) != 0 || pipe(FromExecutor) != 0)
+return make_error("Unable to create pipe for executor",
+   inconvertibleErrorCode());
+
+  ChildPID = fork();
+
+  if (ChildPID == 0) {
+// In the child...
+
+// Close the parent ends of the pipes
+close(ToExecutor[WriteEnd]);
+close(FromExecutor[ReadEnd]);
+
+// Execute the child process.
+std::unique_ptr ExecutorPath, FDSpecifier;
+{
+  ExecutorPath = std::make_unique(ExecutablePath.size() + 1);
+  strcpy(ExecutorPath.get(), ExecutablePath.data());
+
+  std::string FDSpecifierStr("filedescs=");
+  FDSpecifierStr += utostr(ToExecutor[ReadEnd]);
+  FDSpecifierStr += ',';
+  FDSpecifierStr += utostr(FromExecutor[WriteEnd]);
+  FDSpecifier = std::make_unique(FD

[clang] [REAPPLY][Clang-Repl] Add support for out-of-process execution. #110418 (PR #144064)

2025-06-15 Thread via cfe-commits

SahilPatidar wrote:

> Is there a reason to be a draft?

Just to make sure there were no build failures.

https://github.com/llvm/llvm-project/pull/144064
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [REAPPLY][Clang-Repl] Add support for out-of-process execution. #110418 (PR #144064)

2025-06-15 Thread via cfe-commits

https://github.com/SahilPatidar updated 
https://github.com/llvm/llvm-project/pull/144064

>From 05943c9542cd89ae672ddc0f14514e0c7b1e0bd7 Mon Sep 17 00:00:00 2001
From: SahilPatidar 
Date: Tue, 3 Dec 2024 15:07:56 +0530
Subject: [PATCH 1/4] Re-Land: [Clang-Repl] Add support for out-of-process
 execution. #110418

---
 clang/include/clang/Interpreter/Interpreter.h |   7 +-
 .../clang/Interpreter/RemoteJITUtils.h|  38 +++
 clang/lib/Interpreter/CMakeLists.txt  |   1 +
 clang/lib/Interpreter/Interpreter.cpp |  37 ++-
 clang/lib/Interpreter/RemoteJITUtils.cpp  | 267 ++
 clang/tools/clang-repl/CMakeLists.txt |   2 +
 clang/tools/clang-repl/ClangRepl.cpp  | 123 +++-
 7 files changed, 465 insertions(+), 10 deletions(-)
 create mode 100644 clang/include/clang/Interpreter/RemoteJITUtils.h
 create mode 100644 clang/lib/Interpreter/RemoteJITUtils.cpp

diff --git a/clang/include/clang/Interpreter/Interpreter.h 
b/clang/include/clang/Interpreter/Interpreter.h
index f8663e3193a18..78dff1165dcf5 100644
--- a/clang/include/clang/Interpreter/Interpreter.h
+++ b/clang/include/clang/Interpreter/Interpreter.h
@@ -20,6 +20,7 @@
 
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ExecutionEngine/JITSymbol.h"
+#include "llvm/ExecutionEngine/Orc/ExecutorProcessControl.h"
 #include "llvm/ExecutionEngine/Orc/Shared/ExecutorAddress.h"
 #include "llvm/Support/Error.h"
 #include 
@@ -136,10 +137,14 @@ class Interpreter {
 public:
   virtual ~Interpreter();
   static llvm::Expected>
-  create(std::unique_ptr CI);
+  create(std::unique_ptr CI,
+ std::unique_ptr JITBuilder = nullptr);
   static llvm::Expected>
   createWithCUDA(std::unique_ptr CI,
  std::unique_ptr DCI);
+  static llvm::Expected>
+  createLLJITBuilder(std::unique_ptr EPC,
+ llvm::StringRef OrcRuntimePath);
   const ASTContext &getASTContext() const;
   ASTContext &getASTContext();
   const CompilerInstance *getCompilerInstance() const;
diff --git a/clang/include/clang/Interpreter/RemoteJITUtils.h 
b/clang/include/clang/Interpreter/RemoteJITUtils.h
new file mode 100644
index 0..8705a3b1f669d
--- /dev/null
+++ b/clang/include/clang/Interpreter/RemoteJITUtils.h
@@ -0,0 +1,38 @@
+//===-- RemoteJITUtils.h - Utilities for remote-JITing --*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// Utilities for ExecutorProcessControl-based remote JITing with Orc and
+// JITLink.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_INTERPRETER_REMOTEJITUTILS_H
+#define LLVM_CLANG_INTERPRETER_REMOTEJITUTILS_H
+
+#include "llvm/ADT/StringRef.h"
+#include "llvm/ExecutionEngine/Orc/Core.h"
+#include "llvm/ExecutionEngine/Orc/Layer.h"
+#include "llvm/ExecutionEngine/Orc/SimpleRemoteEPC.h"
+#include "llvm/Support/Error.h"
+
+#include 
+#include 
+#include 
+
+llvm::Expected>
+launchExecutor(llvm::StringRef ExecutablePath, bool UseSharedMemory,
+   llvm::StringRef SlabAllocateSizeString);
+
+/// Create a JITLinkExecutor that connects to the given network address
+/// through a TCP socket. A valid NetworkAddress provides hostname and port,
+/// e.g. localhost:2.
+llvm::Expected>
+connectTCPSocket(llvm::StringRef NetworkAddress, bool UseSharedMemory,
+ llvm::StringRef SlabAllocateSizeString);
+
+#endif // LLVM_CLANG_INTERPRETER_REMOTEJITUTILS_H
diff --git a/clang/lib/Interpreter/CMakeLists.txt 
b/clang/lib/Interpreter/CMakeLists.txt
index bf70cdfbee01e..38cf139fa86a6 100644
--- a/clang/lib/Interpreter/CMakeLists.txt
+++ b/clang/lib/Interpreter/CMakeLists.txt
@@ -27,6 +27,7 @@ add_clang_library(clangInterpreter
   Interpreter.cpp
   InterpreterValuePrinter.cpp
   InterpreterUtils.cpp
+  RemoteJITUtils.cpp
   Value.cpp
   ${WASM_SRC}
   PARTIAL_SOURCES_INTENDED
diff --git a/clang/lib/Interpreter/Interpreter.cpp 
b/clang/lib/Interpreter/Interpreter.cpp
index 84feff82c63a7..30051a24662c6 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), 

[clang] [REAPPLY][Clang-Repl] Add support for out-of-process execution. #110418 (PR #144064)

2025-06-15 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (SahilPatidar)


Changes

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.

---

Patch is 28.12 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/144064.diff


9 Files Affected:

- (modified) clang/include/clang/Interpreter/Interpreter.h (+6-1) 
- (added) clang/include/clang/Interpreter/RemoteJITUtils.h (+38) 
- (modified) clang/lib/Interpreter/CMakeLists.txt (+1) 
- (modified) clang/lib/Interpreter/Interpreter.cpp (+29-8) 
- (added) clang/lib/Interpreter/RemoteJITUtils.cpp (+267) 
- (added) clang/test/Interpreter/out-of-process.cpp (+88) 
- (modified) clang/test/lit.cfg.py (+25) 
- (modified) clang/tools/clang-repl/CMakeLists.txt (+2) 
- (modified) clang/tools/clang-repl/ClangRepl.cpp (+122-1) 


``diff
diff --git a/clang/include/clang/Interpreter/Interpreter.h 
b/clang/include/clang/Interpreter/Interpreter.h
index f8663e3193a18..78dff1165dcf5 100644
--- a/clang/include/clang/Interpreter/Interpreter.h
+++ b/clang/include/clang/Interpreter/Interpreter.h
@@ -20,6 +20,7 @@
 
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ExecutionEngine/JITSymbol.h"
+#include "llvm/ExecutionEngine/Orc/ExecutorProcessControl.h"
 #include "llvm/ExecutionEngine/Orc/Shared/ExecutorAddress.h"
 #include "llvm/Support/Error.h"
 #include 
@@ -136,10 +137,14 @@ class Interpreter {
 public:
   virtual ~Interpreter();
   static llvm::Expected>
-  create(std::unique_ptr CI);
+  create(std::unique_ptr CI,
+ std::unique_ptr JITBuilder = nullptr);
   static llvm::Expected>
   createWithCUDA(std::unique_ptr CI,
  std::unique_ptr DCI);
+  static llvm::Expected>
+  createLLJITBuilder(std::unique_ptr EPC,
+ llvm::StringRef OrcRuntimePath);
   const ASTContext &getASTContext() const;
   ASTContext &getASTContext();
   const CompilerInstance *getCompilerInstance() const;
diff --git a/clang/include/clang/Interpreter/RemoteJITUtils.h 
b/clang/include/clang/Interpreter/RemoteJITUtils.h
new file mode 100644
index 0..8705a3b1f669d
--- /dev/null
+++ b/clang/include/clang/Interpreter/RemoteJITUtils.h
@@ -0,0 +1,38 @@
+//===-- RemoteJITUtils.h - Utilities for remote-JITing --*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// Utilities for ExecutorProcessControl-based remote JITing with Orc and
+// JITLink.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_INTERPRETER_REMOTEJITUTILS_H
+#define LLVM_CLANG_INTERPRETER_REMOTEJITUTILS_H
+
+#include "llvm/ADT/StringRef.h"
+#include "llvm/ExecutionEngine/Orc/Core.h"
+#include "llvm/ExecutionEngine/Orc/Layer.h"
+#include "llvm/ExecutionEngine/Orc/SimpleRemoteEPC.h"
+#include "llvm/Support/Error.h"
+
+#include 
+#include 
+#include 
+
+llvm::Expected>
+launchExecutor(llvm::StringRef ExecutablePath, bool UseSharedMemory,
+   llvm::StringRef SlabAllocateSizeString);
+
+/// Create a JITLinkExecutor that connects to the given network address
+/// through a TCP socket. A valid NetworkAddress provides hostname and port,
+/// e.g. localhost:2.
+llvm::Expected>
+connectTCPSocket(llvm::StringRef NetworkAddress, bool UseSharedMemory,
+ llvm::StringRef SlabAllocateSizeString);
+
+#endif // LLVM_CLANG_INTERPRETER_REMOTEJITUTILS_H
diff --git a/clang/lib/Interpreter/CMakeLists.txt 
b/clang/lib/Interpreter/CMakeLists.txt
index bf70cdfbee01e..38cf139fa86a6 100644
--- a/clang/lib/Interpreter/CMakeLists.txt
+++ b/clang/lib/Interpreter/CMakeLists.txt
@@ -27,6 +27,7 @@ add_clang_library(clangInterpreter
   Interpreter.cpp
   InterpreterValuePrinter.cpp
   InterpreterUtils.cpp
+  RemoteJITUtils.cpp
   Value.cpp
   ${WASM_SRC}
   PARTIAL_SOURCES_INTENDED
diff --git a/clang/lib/Interpreter/Interpreter.cpp 
b/clang/lib/Interpreter/Interpreter.cpp
index 84feff82c63a7..30051a24662c6 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::cre

[clang] [REAPPLY][Clang-Repl] Add support for out-of-process execution. #110418 (PR #144064)

2025-06-15 Thread via cfe-commits

https://github.com/SahilPatidar ready_for_review 
https://github.com/llvm/llvm-project/pull/144064
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [REAPPLY][Clang-Repl] Add support for out-of-process execution. #110418 (PR #144064)

2025-06-14 Thread Vassil Vassilev via cfe-commits

vgvassilev wrote:

Looks a reasonable way forward. Is there a reason to be a draft?

https://github.com/llvm/llvm-project/pull/144064
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [REAPPLY][Clang-Repl] Add support for out-of-process execution. #110418 (PR #144064)

2025-06-13 Thread via cfe-commits

https://github.com/SahilPatidar updated 
https://github.com/llvm/llvm-project/pull/144064

>From 05943c9542cd89ae672ddc0f14514e0c7b1e0bd7 Mon Sep 17 00:00:00 2001
From: SahilPatidar 
Date: Tue, 3 Dec 2024 15:07:56 +0530
Subject: [PATCH 1/3] Re-Land: [Clang-Repl] Add support for out-of-process
 execution. #110418

---
 clang/include/clang/Interpreter/Interpreter.h |   7 +-
 .../clang/Interpreter/RemoteJITUtils.h|  38 +++
 clang/lib/Interpreter/CMakeLists.txt  |   1 +
 clang/lib/Interpreter/Interpreter.cpp |  37 ++-
 clang/lib/Interpreter/RemoteJITUtils.cpp  | 267 ++
 clang/tools/clang-repl/CMakeLists.txt |   2 +
 clang/tools/clang-repl/ClangRepl.cpp  | 123 +++-
 7 files changed, 465 insertions(+), 10 deletions(-)
 create mode 100644 clang/include/clang/Interpreter/RemoteJITUtils.h
 create mode 100644 clang/lib/Interpreter/RemoteJITUtils.cpp

diff --git a/clang/include/clang/Interpreter/Interpreter.h 
b/clang/include/clang/Interpreter/Interpreter.h
index f8663e3193a18..78dff1165dcf5 100644
--- a/clang/include/clang/Interpreter/Interpreter.h
+++ b/clang/include/clang/Interpreter/Interpreter.h
@@ -20,6 +20,7 @@
 
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ExecutionEngine/JITSymbol.h"
+#include "llvm/ExecutionEngine/Orc/ExecutorProcessControl.h"
 #include "llvm/ExecutionEngine/Orc/Shared/ExecutorAddress.h"
 #include "llvm/Support/Error.h"
 #include 
@@ -136,10 +137,14 @@ class Interpreter {
 public:
   virtual ~Interpreter();
   static llvm::Expected>
-  create(std::unique_ptr CI);
+  create(std::unique_ptr CI,
+ std::unique_ptr JITBuilder = nullptr);
   static llvm::Expected>
   createWithCUDA(std::unique_ptr CI,
  std::unique_ptr DCI);
+  static llvm::Expected>
+  createLLJITBuilder(std::unique_ptr EPC,
+ llvm::StringRef OrcRuntimePath);
   const ASTContext &getASTContext() const;
   ASTContext &getASTContext();
   const CompilerInstance *getCompilerInstance() const;
diff --git a/clang/include/clang/Interpreter/RemoteJITUtils.h 
b/clang/include/clang/Interpreter/RemoteJITUtils.h
new file mode 100644
index 0..8705a3b1f669d
--- /dev/null
+++ b/clang/include/clang/Interpreter/RemoteJITUtils.h
@@ -0,0 +1,38 @@
+//===-- RemoteJITUtils.h - Utilities for remote-JITing --*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// Utilities for ExecutorProcessControl-based remote JITing with Orc and
+// JITLink.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_INTERPRETER_REMOTEJITUTILS_H
+#define LLVM_CLANG_INTERPRETER_REMOTEJITUTILS_H
+
+#include "llvm/ADT/StringRef.h"
+#include "llvm/ExecutionEngine/Orc/Core.h"
+#include "llvm/ExecutionEngine/Orc/Layer.h"
+#include "llvm/ExecutionEngine/Orc/SimpleRemoteEPC.h"
+#include "llvm/Support/Error.h"
+
+#include 
+#include 
+#include 
+
+llvm::Expected>
+launchExecutor(llvm::StringRef ExecutablePath, bool UseSharedMemory,
+   llvm::StringRef SlabAllocateSizeString);
+
+/// Create a JITLinkExecutor that connects to the given network address
+/// through a TCP socket. A valid NetworkAddress provides hostname and port,
+/// e.g. localhost:2.
+llvm::Expected>
+connectTCPSocket(llvm::StringRef NetworkAddress, bool UseSharedMemory,
+ llvm::StringRef SlabAllocateSizeString);
+
+#endif // LLVM_CLANG_INTERPRETER_REMOTEJITUTILS_H
diff --git a/clang/lib/Interpreter/CMakeLists.txt 
b/clang/lib/Interpreter/CMakeLists.txt
index bf70cdfbee01e..38cf139fa86a6 100644
--- a/clang/lib/Interpreter/CMakeLists.txt
+++ b/clang/lib/Interpreter/CMakeLists.txt
@@ -27,6 +27,7 @@ add_clang_library(clangInterpreter
   Interpreter.cpp
   InterpreterValuePrinter.cpp
   InterpreterUtils.cpp
+  RemoteJITUtils.cpp
   Value.cpp
   ${WASM_SRC}
   PARTIAL_SOURCES_INTENDED
diff --git a/clang/lib/Interpreter/Interpreter.cpp 
b/clang/lib/Interpreter/Interpreter.cpp
index 84feff82c63a7..30051a24662c6 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),