Skip to content

Commit 17cf95a

Browse files
author
kr-2003
committed
remote jit execution
1 parent 3d3c82d commit 17cf95a

File tree

4 files changed

+39
-8
lines changed

4 files changed

+39
-8
lines changed

include/CppInterOp/CppInterOp.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ CPPINTEROP_API void GetOperator(TCppScope_t scope, Operator op,
609609
///\returns nullptr on failure.
610610
CPPINTEROP_API TInterp_t
611611
CreateInterpreter(const std::vector<const char*>& Args = {},
612-
const std::vector<const char*>& GpuArgs = {});
612+
const std::vector<const char*>& GpuArgs = {}, bool is_out_of_process = false);
613613

614614
/// Deletes an instance of an interpreter.
615615
///\param[in] I - the interpreter to be deleted, if nullptr, deletes the last.

lib/CppInterOp/Compatibility.h

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,10 +200,20 @@ inline void codeComplete(std::vector<std::string>& Results,
200200

201201
#include "llvm/Support/Error.h"
202202

203+
#include "clang/Interpreter/RemoteJITUtils.h"
204+
#include "clang/Basic/Version.h"
205+
#include "llvm/TargetParser/Host.h"
206+
207+
#include "llvm/ExecutionEngine/Orc/Debugging/DebuggerSupport.h"
208+
209+
#include "llvm/Support/CommandLine.h"
210+
211+
static llvm::ExitOnError ExitOnError;
212+
203213
namespace compat {
204214

205215
inline std::unique_ptr<clang::Interpreter>
206-
createClangInterpreter(std::vector<const char*>& args) {
216+
createClangInterpreter(std::vector<const char*>& args, bool is_out_of_process) {
207217
auto has_arg = [](const char* x, llvm::StringRef match = "cuda") {
208218
llvm::StringRef Arg = x;
209219
Arg = Arg.trim().ltrim('-');
@@ -241,10 +251,31 @@ createClangInterpreter(std::vector<const char*>& args) {
241251
(*ciOrErr)->LoadRequestedPlugins();
242252
if (CudaEnabled)
243253
DeviceCI->LoadRequestedPlugins();
254+
255+
std::unique_ptr<llvm::orc::LLJITBuilder> JB;
256+
257+
if(is_out_of_process) {
258+
std::string OOPExecutor = "/Users/abhinavkumar/Desktop/Coding/CERN_HSF_COMPILER_RESEARCH/llvm-project-test/build/bin/llvm-jitlink-executor";
259+
bool UseSharedMemory = false;
260+
std::string SlabAllocateSizeString = "";
261+
std::unique_ptr<llvm::orc::ExecutorProcessControl> EPC;
262+
EPC = ExitOnError(
263+
launchExecutor(OOPExecutor, UseSharedMemory, SlabAllocateSizeString));
264+
265+
266+
std::string OrcRuntimePath = "/Users/abhinavkumar/Desktop/Coding/CERN_HSF_COMPILER_RESEARCH/llvm-project-test/build/lib/clang/20/lib/darwin/liborc_rt_osx.a";
267+
if (EPC) {
268+
269+
CB.SetTargetTriple(EPC->getTargetTriple().getTriple());
270+
JB = ExitOnError(
271+
clang::Interpreter::createLLJITBuilder(std::move(EPC), OrcRuntimePath));
272+
}
273+
}
274+
244275
auto innerOrErr =
245276
CudaEnabled ? clang::Interpreter::createWithCUDA(std::move(*ciOrErr),
246277
std::move(DeviceCI))
247-
: clang::Interpreter::create(std::move(*ciOrErr));
278+
: clang::Interpreter::create(std::move(*ciOrErr), std::move(JB));
248279

249280
if (!innerOrErr) {
250281
llvm::logAllUnhandledErrors(innerOrErr.takeError(), llvm::errs(),

lib/CppInterOp/CppInterOp.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2911,11 +2911,11 @@ static std::string MakeResourcesPath() {
29112911
} // namespace
29122912

29132913
TInterp_t CreateInterpreter(const std::vector<const char*>& Args /*={}*/,
2914-
const std::vector<const char*>& GpuArgs /*={}*/) {
2914+
const std::vector<const char*>& GpuArgs /*={}*/, bool is_out_of_process) {
29152915
std::string MainExecutableName = sys::fs::getMainExecutable(nullptr, nullptr);
29162916
std::string ResourceDir = MakeResourcesPath();
29172917
std::vector<const char*> ClingArgv = {"-resource-dir", ResourceDir.c_str(),
2918-
"-std=c++14"};
2918+
"-std=c++14", "-gdwarf-4", "-O0"};
29192919
ClingArgv.insert(ClingArgv.begin(), MainExecutableName.c_str());
29202920
#ifdef _WIN32
29212921
// FIXME : Workaround Sema::PushDeclContext assert on windows
@@ -2955,7 +2955,7 @@ TInterp_t CreateInterpreter(const std::vector<const char*>& Args /*={}*/,
29552955
auto I = new compat::Interpreter(ClingArgv.size(), &ClingArgv[0]);
29562956
#else
29572957
auto Interp = compat::Interpreter::create(static_cast<int>(ClingArgv.size()),
2958-
ClingArgv.data());
2958+
ClingArgv.data(), nullptr, {}, nullptr, true, is_out_of_process);
29592959
if (!Interp)
29602960
return nullptr;
29612961
auto* I = Interp.release();

lib/CppInterOp/CppInterOpInterpreter.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,15 +150,15 @@ class Interpreter {
150150
create(int argc, const char* const* argv, const char* llvmdir = nullptr,
151151
const std::vector<std::shared_ptr<clang::ModuleFileExtension>>&
152152
moduleExtensions = {},
153-
void* extraLibHandle = nullptr, bool noRuntime = true) {
153+
void* extraLibHandle = nullptr, bool noRuntime = true, bool is_out_of_process = false) {
154154
// Initialize all targets (required for device offloading)
155155
llvm::InitializeAllTargetInfos();
156156
llvm::InitializeAllTargets();
157157
llvm::InitializeAllTargetMCs();
158158
llvm::InitializeAllAsmPrinters();
159159

160160
std::vector<const char*> vargs(argv + 1, argv + argc);
161-
auto CI = compat::createClangInterpreter(vargs);
161+
auto CI = compat::createClangInterpreter(vargs, is_out_of_process);
162162
if (!CI) {
163163
llvm::errs() << "Interpreter creation failed\n";
164164
return nullptr;

0 commit comments

Comments
 (0)