Skip to content

Commit 645dd32

Browse files
kr-2003kr-2003
andauthored
[clang-repl] Sink RemoteJITUtils into Interpreter class. NFC (#155140)
This is a refactoring PR. It sinks RemoteJITUtils into Interpreter and IncrementalExecutor classes. --------- Co-authored-by: kr-2003 <[email protected]>
1 parent 3216bf1 commit 645dd32

File tree

8 files changed

+491
-370
lines changed

8 files changed

+491
-370
lines changed

clang/include/clang/Interpreter/Interpreter.h

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "llvm/ExecutionEngine/Orc/ExecutorProcessControl.h"
2424
#include "llvm/ExecutionEngine/Orc/Shared/ExecutorAddress.h"
2525
#include "llvm/Support/Error.h"
26+
#include <cstdint>
2627
#include <memory>
2728
#include <vector>
2829

@@ -36,6 +37,10 @@ class ThreadSafeContext;
3637

3738
namespace clang {
3839

40+
namespace driver {
41+
class ToolChain;
42+
} // namespace driver
43+
3944
class CompilerInstance;
4045
class CXXRecordDecl;
4146
class Decl;
@@ -115,15 +120,38 @@ class Interpreter {
115120
/// An optional compiler instance for CUDA offloading
116121
std::unique_ptr<CompilerInstance> DeviceCI;
117122

123+
public:
124+
struct JITConfig {
125+
/// Indicates whether out-of-process JIT execution is enabled.
126+
bool IsOutOfProcess = false;
127+
/// Path to the out-of-process JIT executor.
128+
std::string OOPExecutor = "";
129+
std::string OOPExecutorConnect = "";
130+
/// Indicates whether to use shared memory for communication.
131+
bool UseSharedMemory = false;
132+
/// Representing the slab allocation size for memory management in kb.
133+
unsigned SlabAllocateSize = 0;
134+
/// Path to the ORC runtime library.
135+
std::string OrcRuntimePath = "";
136+
/// PID of the out-of-process JIT executor.
137+
uint32_t ExecutorPID = 0;
138+
139+
JITConfig()
140+
: IsOutOfProcess(false), OOPExecutor(""), OOPExecutorConnect(""),
141+
UseSharedMemory(false), SlabAllocateSize(0), OrcRuntimePath(""),
142+
ExecutorPID(0) {}
143+
};
144+
118145
protected:
119146
// Derived classes can use an extended interface of the Interpreter.
120147
Interpreter(std::unique_ptr<CompilerInstance> Instance, llvm::Error &Err,
121148
std::unique_ptr<llvm::orc::LLJITBuilder> JITBuilder = nullptr,
122-
std::unique_ptr<clang::ASTConsumer> Consumer = nullptr);
149+
std::unique_ptr<clang::ASTConsumer> Consumer = nullptr,
150+
JITConfig Config = JITConfig());
123151

124152
// Create the internal IncrementalExecutor, or re-create it after calling
125153
// ResetExecutor().
126-
llvm::Error CreateExecutor();
154+
llvm::Error CreateExecutor(JITConfig Config = JITConfig());
127155

128156
// Delete the internal IncrementalExecutor. This causes a hard shutdown of the
129157
// JIT engine. In particular, it doesn't run cleanup or destructors.
@@ -132,14 +160,19 @@ class Interpreter {
132160
public:
133161
virtual ~Interpreter();
134162
static llvm::Expected<std::unique_ptr<Interpreter>>
135-
create(std::unique_ptr<CompilerInstance> CI,
136-
std::unique_ptr<llvm::orc::LLJITBuilder> JITBuilder = nullptr);
163+
create(std::unique_ptr<CompilerInstance> CI, JITConfig Config = {});
137164
static llvm::Expected<std::unique_ptr<Interpreter>>
138165
createWithCUDA(std::unique_ptr<CompilerInstance> CI,
139166
std::unique_ptr<CompilerInstance> DCI);
140167
static llvm::Expected<std::unique_ptr<llvm::orc::LLJITBuilder>>
141168
createLLJITBuilder(std::unique_ptr<llvm::orc::ExecutorProcessControl> EPC,
142169
llvm::StringRef OrcRuntimePath);
170+
static llvm::Expected<
171+
std::pair<std::unique_ptr<llvm::orc::LLJITBuilder>, uint32_t>>
172+
outOfProcessJITBuilder(JITConfig Config);
173+
static llvm::Expected<std::string>
174+
getOrcRuntimePath(const driver::ToolChain &TC);
175+
143176
const ASTContext &getASTContext() const;
144177
ASTContext &getASTContext();
145178
const CompilerInstance *getCompilerInstance() const;
@@ -170,6 +203,8 @@ class Interpreter {
170203
llvm::Expected<llvm::orc::ExecutorAddr>
171204
getSymbolAddressFromLinkerName(llvm::StringRef LinkerName) const;
172205

206+
uint32_t getOutOfProcessExecutorPID() const;
207+
173208
private:
174209
size_t getEffectivePTUSize() const;
175210
void markUserCodeStart();

clang/include/clang/Interpreter/RemoteJITUtils.h

Lines changed: 0 additions & 38 deletions
This file was deleted.

clang/lib/Interpreter/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ add_clang_library(clangInterpreter
2828
Interpreter.cpp
2929
InterpreterValuePrinter.cpp
3030
InterpreterUtils.cpp
31-
RemoteJITUtils.cpp
3231
Value.cpp
3332
InterpreterValuePrinter.cpp
3433
${WASM_SRC}

0 commit comments

Comments
 (0)