Skip to content

Commit 58bb645

Browse files
author
kr-2003
committed
redirection in out-of-process JIT
1 parent b207b1f commit 58bb645

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

clang/include/clang/Interpreter/RemoteJITUtils.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@
2727

2828
llvm::Expected<std::unique_ptr<llvm::orc::SimpleRemoteEPC>>
2929
launchExecutor(llvm::StringRef ExecutablePath, bool UseSharedMemory,
30-
llvm::StringRef SlabAllocateSizeString, int stdin_fd = STDIN_FILENO, int stdout_fd = STDOUT_FILENO, int stderr_fd = STDERR_FILENO);
30+
llvm::StringRef SlabAllocateSizeString,
31+
int stdin_fd = STDIN_FILENO, int stdout_fd = STDOUT_FILENO,
32+
int stderr_fd = STDERR_FILENO);
3133

3234
/// Create a JITLinkExecutor that connects to the given network address
3335
/// through a TCP socket. A valid NetworkAddress provides hostname and port,
@@ -36,8 +38,12 @@ llvm::Expected<std::unique_ptr<llvm::orc::SimpleRemoteEPC>>
3638
connectTCPSocket(llvm::StringRef NetworkAddress, bool UseSharedMemory,
3739
llvm::StringRef SlabAllocateSizeString);
3840

39-
/// Get the PID of the last launched executor.
40-
/// This is useful for debugging or for cleanup purposes.
41+
42+
/// Returns PID of last launched executor.
4143
pid_t getLastLaunchedExecutorPID();
4244

45+
/// Returns PID of nth launched executor.
46+
/// 1-based indexing.
47+
pid_t getNthLaunchedExecutorPID(int n);
48+
4349
#endif // LLVM_CLANG_INTERPRETER_REMOTEJITUTILS_H

clang/lib/Interpreter/RemoteJITUtils.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
using namespace llvm;
3434
using namespace llvm::orc;
3535

36-
static std::atomic<pid_t> LaunchedExecutorPID{-1};
36+
static std::vector<pid_t> LaunchedExecutorPID;
3737

3838
Expected<uint64_t> getSlabAllocSize(StringRef SizeString) {
3939
SizeString = SizeString.trim();
@@ -93,7 +93,8 @@ createSharedMemoryManager(SimpleRemoteEPC &SREPC,
9393

9494
Expected<std::unique_ptr<SimpleRemoteEPC>>
9595
launchExecutor(StringRef ExecutablePath, bool UseSharedMemory,
96-
llvm::StringRef SlabAllocateSizeString, int stdin_fd, int stdout_fd, int stderr_fd) {
96+
llvm::StringRef SlabAllocateSizeString, int stdin_fd,
97+
int stdout_fd, int stderr_fd) {
9798
#ifndef LLVM_ON_UNIX
9899
// FIXME: Add support for Windows.
99100
return make_error<StringError>("-" + ExecutablePath +
@@ -175,7 +176,7 @@ launchExecutor(StringRef ExecutablePath, bool UseSharedMemory,
175176
exit(1);
176177
}
177178
} else {
178-
LaunchedExecutorPID = ChildPID;
179+
LaunchedExecutorPID.push_back(ChildPID);
179180
}
180181
// else we're the parent...
181182

@@ -287,6 +288,12 @@ connectTCPSocket(StringRef NetworkAddress, bool UseSharedMemory,
287288
#endif
288289
}
289290

290-
pid_t getLastLaunchedExecutorPID() {
291-
return LaunchedExecutorPID;
291+
pid_t getLastLaunchedExecutorPID() {
292+
if(!LaunchedExecutorPID.size()) return -1;
293+
return LaunchedExecutorPID.back();
294+
}
295+
296+
pid_t getNthLaunchedExecutorPID(int n) {
297+
if (n - 1 < 0 || n - 1 >= static_cast<int>(LaunchedExecutorPID.size())) return -1;
298+
return LaunchedExecutorPID.at(n - 1);
292299
}

0 commit comments

Comments
 (0)