Skip to content

Commit c031963

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

File tree

10 files changed

+61
-41
lines changed

10 files changed

+61
-41
lines changed

lib/CppInterOp/Compatibility.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ static inline char* GetEnv(const char* Var_Name) {
7979

8080
// std::regex breaks pytorch's jit: pytorch/pytorch#49460
8181
#include "llvm/Support/Regex.h"
82+
#include "llvm/ExecutionEngine/Orc/ExecutionUtils.h"
8283

8384
#ifdef CPPINTEROP_USE_CLING
8485

@@ -282,6 +283,24 @@ createClangInterpreter(std::vector<const char*>& args, bool is_out_of_process) {
282283
"Failed to build Interpreter:");
283284
return nullptr;
284285
}
286+
// auto interpreter = std::move(*innerOrErr);
287+
288+
// // Add your hardcoded static library
289+
// auto JOrErr = interpreter->getExecutionEngine();
290+
// if (!JOrErr) {
291+
// llvm::logAllUnhandledErrors(JOrErr.takeError(), llvm::errs(),
292+
// "Failed to get execution engine:");
293+
// return nullptr;
294+
// }
295+
// auto& J = *JOrErr;
296+
// std::string libpath = "/Users/abhinavkumar/Desktop/Coding/CERN_HSF_COMPILER_RESEARCH/llvm-project-test/build/lib/libclangInterpreter.a";
297+
// auto generator = ExitOnError(
298+
// llvm::orc::StaticLibraryDefinitionGenerator::Load(
299+
// J.getObjLinkingLayer(),
300+
// libpath.c_str()
301+
// )
302+
// );
303+
// J.getMainJITDylib().addGenerator(std::move(generator));
285304
if (CudaEnabled) {
286305
if (auto Err = (*innerOrErr)->LoadDynamicLibrary("libcudart.so")) {
287306
llvm::logAllUnhandledErrors(std::move(Err), llvm::errs(),
@@ -291,6 +310,7 @@ createClangInterpreter(std::vector<const char*>& args, bool is_out_of_process) {
291310
}
292311

293312
return std::move(*innerOrErr);
313+
// return interpreter;
294314
}
295315

296316
inline void maybeMangleDeclName(const clang::GlobalDecl& GD,

unittests/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ endfunction()
5151

5252
add_subdirectory(CppInterOp)
5353

54-
add_custom_target(check-cppinterop COMMAND ${CMAKE_CTEST_COMMAND} -V --build-config $<CONFIG>
54+
add_custom_target(check-cppinterop COMMAND ${CMAKE_CTEST_COMMAND} -V
5555
DEPENDS CppInterOpUnitTests WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
5656

5757
set_target_properties(check-cppinterop PROPERTIES FOLDER "CppInterOp tests")

unittests/CppInterOp/DynamicLibraryManagerTest.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ TEST(DynamicLibraryManagerTest, Sanity) {
2929
GTEST_SKIP() << "Test fails with Cling on Windows";
3030
#endif
3131

32-
EXPECT_TRUE(Cpp::CreateInterpreter());
32+
EXPECT_TRUE(Cpp::CreateInterpreter({}, {}, true));
3333
EXPECT_FALSE(Cpp::GetFunctionAddress("ret_zero"));
3434

3535
std::string BinaryPath = GetExecutablePath(/*Argv0=*/nullptr);
@@ -75,7 +75,7 @@ TEST(DynamicLibraryManagerTest, BasicSymbolLookup) {
7575
#endif
7676
#endif
7777

78-
ASSERT_TRUE(Cpp::CreateInterpreter());
78+
ASSERT_TRUE(Cpp::CreateInterpreter({}, {}, true));
7979
EXPECT_FALSE(Cpp::GetFunctionAddress("ret_zero"));
8080

8181
// Load the library manually. Use known preload path (MEMFS path)

unittests/CppInterOp/EnumReflectionTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ TEST(EnumReflectionTest, GetEnums) {
338338
int myVariable;
339339
)";
340340

341-
Cpp::CreateInterpreter();
341+
Cpp::CreateInterpreter({}, {}, true);
342342
Interp->declare(code);
343343
std::vector<std::string> enumNames1, enumNames2, enumNames3, enumNames4;
344344
Cpp::TCppScope_t globalscope = Cpp::GetScope("", 0);

unittests/CppInterOp/FunctionReflectionTest.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,7 @@ TEST(FunctionReflectionTest, InstantiateTemplateFunctionFromString) {
645645
if (llvm::sys::RunningOnValgrind())
646646
GTEST_SKIP() << "XFAIL due to Valgrind report";
647647
std::vector<const char*> interpreter_args = { "-include", "new" };
648-
Cpp::CreateInterpreter(interpreter_args);
648+
Cpp::CreateInterpreter(interpreter_args, {}, true);
649649
std::string code = R"(#include <memory>)";
650650
Interp->process(code);
651651
const char* str = "std::make_unique<int,int>";
@@ -1927,7 +1927,7 @@ TEST(FunctionReflectionTest, Construct) {
19271927
GTEST_SKIP() << "Disabled on Windows. Needs fixing.";
19281928
#endif
19291929
std::vector<const char*> interpreter_args = {"-include", "new"};
1930-
Cpp::CreateInterpreter(interpreter_args);
1930+
Cpp::CreateInterpreter(interpreter_args, {}, true);
19311931

19321932
Interp->declare(R"(
19331933
#include <new>
@@ -1991,7 +1991,7 @@ TEST(FunctionReflectionTest, ConstructNested) {
19911991
#endif
19921992

19931993
std::vector<const char*> interpreter_args = {"-include", "new"};
1994-
Cpp::CreateInterpreter(interpreter_args);
1994+
Cpp::CreateInterpreter(interpreter_args, {}, true);
19951995

19961996
Interp->declare(R"(
19971997
#include <new>
@@ -2052,7 +2052,7 @@ TEST(FunctionReflectionTest, Destruct) {
20522052
#endif
20532053

20542054
std::vector<const char*> interpreter_args = {"-include", "new"};
2055-
Cpp::CreateInterpreter(interpreter_args);
2055+
Cpp::CreateInterpreter(interpreter_args, {}, true);
20562056

20572057
Interp->declare(R"(
20582058
#include <new>
@@ -2104,7 +2104,7 @@ TEST(FunctionReflectionTest, UndoTest) {
21042104
#ifdef EMSCRIPTEN
21052105
GTEST_SKIP() << "Test fails for Emscipten builds";
21062106
#else
2107-
Cpp::CreateInterpreter();
2107+
Cpp::CreateInterpreter({}, {}, true);
21082108
EXPECT_EQ(Cpp::Process("int a = 5;"), 0);
21092109
EXPECT_EQ(Cpp::Process("int b = 10;"), 0);
21102110
EXPECT_EQ(Cpp::Process("int x = 5;"), 0);

unittests/CppInterOp/InterpreterTest.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ TEST(InterpreterTest, DISABLED_DebugFlag) {
3636
#else
3737
TEST(InterpreterTest, DebugFlag) {
3838
#endif // NDEBUG
39-
Cpp::CreateInterpreter();
39+
Cpp::CreateInterpreter({}, {}, true);
4040
EXPECT_FALSE(Cpp::IsDebugOutputEnabled());
4141
std::string cerrs;
4242
testing::internal::CaptureStderr();
@@ -81,9 +81,9 @@ TEST(InterpreterTest, Evaluate) {
8181
}
8282

8383
TEST(InterpreterTest, DeleteInterpreter) {
84-
auto* I1 = Cpp::CreateInterpreter();
85-
auto* I2 = Cpp::CreateInterpreter();
86-
auto* I3 = Cpp::CreateInterpreter();
84+
auto* I1 = Cpp::CreateInterpreter({}, {}, true);
85+
auto* I2 = Cpp::CreateInterpreter({}, {}, true);
86+
auto* I3 = Cpp::CreateInterpreter({}, {}, true);
8787
EXPECT_TRUE(I1 && I2 && I3) << "Failed to create interpreters";
8888

8989
EXPECT_EQ(I3, Cpp::GetInterpreter()) << "I3 is not active";
@@ -100,9 +100,9 @@ TEST(InterpreterTest, DeleteInterpreter) {
100100

101101
TEST(InterpreterTest, ActivateInterpreter) {
102102
EXPECT_FALSE(Cpp::ActivateInterpreter(nullptr));
103-
auto* Cpp14 = Cpp::CreateInterpreter({"-std=c++14"});
104-
auto* Cpp17 = Cpp::CreateInterpreter({"-std=c++17"});
105-
auto* Cpp20 = Cpp::CreateInterpreter({"-std=c++20"});
103+
auto* Cpp14 = Cpp::CreateInterpreter({"-std=c++14"}, {}, true);
104+
auto* Cpp17 = Cpp::CreateInterpreter({"-std=c++17"}, {}, true);
105+
auto* Cpp20 = Cpp::CreateInterpreter({"-std=c++20"}, {}, true);
106106

107107
EXPECT_TRUE(Cpp14 && Cpp17 && Cpp20);
108108
EXPECT_TRUE(Cpp::Evaluate("__cplusplus") == 202002L)
@@ -128,7 +128,7 @@ TEST(InterpreterTest, Process) {
128128
if (llvm::sys::RunningOnValgrind())
129129
GTEST_SKIP() << "XFAIL due to Valgrind report";
130130
std::vector<const char*> interpreter_args = { "-include", "new" };
131-
auto* I = Cpp::CreateInterpreter(interpreter_args);
131+
auto* I = Cpp::CreateInterpreter(interpreter_args, {}, true);
132132
EXPECT_TRUE(Cpp::Process("") == 0);
133133
EXPECT_TRUE(Cpp::Process("int a = 12;") == 0);
134134
EXPECT_FALSE(Cpp::Process("error_here;") == 0);
@@ -160,7 +160,7 @@ TEST(InterpreterTest, EmscriptenExceptionHandling) {
160160
"-mllvm", "-enable-emscripten-sjlj"
161161
};
162162

163-
Cpp::CreateInterpreter(Args);
163+
Cpp::CreateInterpreter(Args, {}, true);
164164

165165
const char* tryCatchCode = R"(
166166
try {
@@ -174,7 +174,7 @@ TEST(InterpreterTest, EmscriptenExceptionHandling) {
174174
}
175175

176176
TEST(InterpreterTest, CreateInterpreter) {
177-
auto* I = Cpp::CreateInterpreter();
177+
auto* I = Cpp::CreateInterpreter({}, {}, true);
178178
EXPECT_TRUE(I);
179179
// Check if the default standard is c++14
180180

@@ -186,7 +186,7 @@ TEST(InterpreterTest, CreateInterpreter) {
186186
EXPECT_TRUE(Cpp::GetNamed("cpp14"));
187187
EXPECT_FALSE(Cpp::GetNamed("cppUnknown"));
188188

189-
I = Cpp::CreateInterpreter({"-std=c++17"});
189+
I = Cpp::CreateInterpreter({"-std=c++17"}, {}, true);
190190
Cpp::Declare("#if __cplusplus==201703L\n"
191191
"int cpp17() { return 2017; }\n"
192192
"#else\n"
@@ -238,7 +238,7 @@ TEST(InterpreterTest, DISABLED_DetectResourceDir) {
238238
#ifdef _WIN32
239239
GTEST_SKIP() << "Disabled on Windows. Needs fixing.";
240240
#endif
241-
Cpp::CreateInterpreter();
241+
Cpp::CreateInterpreter({}, {}, true);
242242
EXPECT_STRNE(Cpp::DetectResourceDir().c_str(), Cpp::GetResourceDir());
243243
llvm::SmallString<256> Clang(LLVM_BINARY_DIR);
244244
llvm::sys::path::append(Clang, "bin", "clang");
@@ -288,7 +288,7 @@ TEST(InterpreterTest, IncludePaths) {
288288

289289
TEST(InterpreterTest, CodeCompletion) {
290290
#if CLANG_VERSION_MAJOR >= 18 || defined(CPPINTEROP_USE_CLING)
291-
Cpp::CreateInterpreter();
291+
Cpp::CreateInterpreter({}, {}, true);
292292
std::vector<std::string> cc;
293293
Cpp::Declare("int foo = 12;");
294294
Cpp::CodeComplete(cc, "f", 1, 2);

unittests/CppInterOp/ScopeReflectionTest.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ TEST(ScopeReflectionTest, IsBuiltin) {
175175

176176
std::vector<const char*> interpreter_args = { "-include", "new" };
177177

178-
Cpp::CreateInterpreter(interpreter_args);
178+
Cpp::CreateInterpreter(interpreter_args, {}, true);
179179
ASTContext &C = Interp->getCI()->getASTContext();
180180
EXPECT_TRUE(Cpp::IsBuiltin(C.BoolTy.getAsOpaquePtr()));
181181
EXPECT_TRUE(Cpp::IsBuiltin(C.CharTy.getAsOpaquePtr()));
@@ -465,7 +465,7 @@ TEST(ScopeReflectionTest, GetScope) {
465465
typedef N::C T;
466466
)";
467467

468-
Cpp::CreateInterpreter();
468+
Cpp::CreateInterpreter({}, {}, true);
469469
Interp->declare(code);
470470
Cpp::TCppScope_t tu = Cpp::GetScope("", 0);
471471
Cpp::TCppScope_t ns_N = Cpp::GetScope("N", 0);
@@ -490,7 +490,7 @@ TEST(ScopeReflectionTest, GetScopefromCompleteName) {
490490
}
491491
)";
492492

493-
Cpp::CreateInterpreter();
493+
Cpp::CreateInterpreter({}, {}, true);
494494

495495
Interp->declare(code);
496496
EXPECT_EQ(Cpp::GetQualifiedName(Cpp::GetScopeFromCompleteName("N1")), "N1");
@@ -517,7 +517,7 @@ TEST(ScopeReflectionTest, GetNamed) {
517517

518518
std::vector<const char*> interpreter_args = {"-include", "new"};
519519

520-
Cpp::CreateInterpreter(interpreter_args);
520+
Cpp::CreateInterpreter(interpreter_args, {}, true);
521521

522522
Interp->declare(code);
523523
Cpp::TCppScope_t ns_N1 = Cpp::GetNamed("N1", nullptr);
@@ -556,7 +556,7 @@ TEST(ScopeReflectionTest, GetParentScope) {
556556
}
557557
)";
558558

559-
Cpp::CreateInterpreter();
559+
Cpp::CreateInterpreter({}, {}, true);
560560

561561
Interp->declare(code);
562562
Cpp::TCppScope_t ns_N1 = Cpp::GetNamed("N1");
@@ -895,7 +895,7 @@ TEST(ScopeReflectionTest, InstantiateTemplateFunctionFromString) {
895895
if (llvm::sys::RunningOnValgrind())
896896
GTEST_SKIP() << "XFAIL due to Valgrind report";
897897
std::vector<const char*> interpreter_args = {"-include", "new"};
898-
Cpp::CreateInterpreter(interpreter_args);
898+
Cpp::CreateInterpreter(interpreter_args, {}, true);
899899
std::string code = R"(#include <memory>)";
900900
Interp->process(code);
901901
const char* str = "std::make_unique<int,int>";
@@ -1044,15 +1044,15 @@ TEST(ScopeReflectionTest, IncludeVector) {
10441044
#include <iostream>
10451045
)";
10461046
std::vector<const char*> interpreter_args = {"-include", "new"};
1047-
Cpp::CreateInterpreter(interpreter_args);
1047+
Cpp::CreateInterpreter(interpreter_args, {}, true);
10481048
Interp->declare(code);
10491049
}
10501050

10511051
TEST(ScopeReflectionTest, GetOperator) {
10521052
if (llvm::sys::RunningOnValgrind())
10531053
GTEST_SKIP() << "XFAIL due to Valgrind report";
10541054

1055-
Cpp::CreateInterpreter();
1055+
Cpp::CreateInterpreter({}, {}, true);
10561056

10571057
std::string code = R"(
10581058
class MyClass {

unittests/CppInterOp/TypeReflectionTest.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ TEST(TypeReflectionTest, GetCanonicalType) {
108108
}
109109

110110
TEST(TypeReflectionTest, GetType) {
111-
Cpp::CreateInterpreter();
111+
Cpp::CreateInterpreter({}, {}, true);
112112

113113
std::string code = R"(
114114
class A {};
@@ -345,7 +345,7 @@ TEST(TypeReflectionTest, IsUnderlyingTypeRecordType) {
345345
}
346346

347347
TEST(TypeReflectionTest, GetComplexType) {
348-
Cpp::CreateInterpreter();
348+
Cpp::CreateInterpreter({}, {}, true);
349349

350350
auto get_complex_type_as_string = [&](const std::string &element_type) {
351351
auto ElementQT = Cpp::GetType(element_type);
@@ -558,7 +558,7 @@ TEST(TypeReflectionTest, IsSmartPtrType) {
558558
GTEST_SKIP() << "XFAIL due to Valgrind report";
559559

560560
std::vector<const char*> interpreter_args = {"-include", "new"};
561-
Cpp::CreateInterpreter(interpreter_args);
561+
Cpp::CreateInterpreter(interpreter_args, {}, true);
562562

563563
Interp->declare(R"(
564564
#include <memory>
@@ -597,7 +597,7 @@ TEST(TypeReflectionTest, IsSmartPtrType) {
597597

598598
TEST(TypeReflectionTest, IsFunctionPointerType) {
599599
std::vector<const char*> interpreter_args = {"-include", "new"};
600-
Cpp::CreateInterpreter(interpreter_args);
600+
Cpp::CreateInterpreter(interpreter_args, {}, true);
601601

602602
Interp->declare(R"(
603603
typedef int (*int_func)(int, int);

unittests/CppInterOp/Utils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ void TestUtils::GetAllTopLevelDecls(
2020
const std::string& code, std::vector<Decl*>& Decls,
2121
bool filter_implicitGenerated /* = false */,
2222
const std::vector<const char*>& interpreter_args /* = {} */) {
23-
Cpp::CreateInterpreter(interpreter_args);
23+
Cpp::CreateInterpreter(interpreter_args, {}, true);
2424
#ifdef CPPINTEROP_USE_CLING
2525
cling::Transaction *T = nullptr;
2626
Interp->declare(code, &T);

unittests/CppInterOp/VariableReflectionTest.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ TEST(VariableReflectionTest, GetTypeAsString) {
180180
}
181181
)";
182182

183-
Cpp::CreateInterpreter();
183+
Cpp::CreateInterpreter({}, {}, true);
184184
EXPECT_EQ(Cpp::Declare(code.c_str()), 0);
185185

186186
Cpp::TCppScope_t wrapper =
@@ -343,7 +343,7 @@ TEST(VariableReflectionTest, VariableOffsetsWithInheritance) {
343343
GTEST_SKIP() << "XFAIL due to Valgrind report";
344344

345345
std::vector<const char*> interpreter_args = {"-include", "new"};
346-
Cpp::CreateInterpreter(interpreter_args);
346+
Cpp::CreateInterpreter(interpreter_args, {}, true);
347347

348348
Cpp::Declare("#include<string>");
349349

@@ -520,7 +520,7 @@ TEST(VariableReflectionTest, StaticConstExprDatamember) {
520520
GTEST_SKIP() << "Disabled on Windows. Needs fixing.";
521521
#endif
522522

523-
Cpp::CreateInterpreter();
523+
Cpp::CreateInterpreter({}, {}, true);
524524

525525
Cpp::Declare(R"(
526526
class MyClass {
@@ -592,7 +592,7 @@ TEST(VariableReflectionTest, StaticConstExprDatamember) {
592592
}
593593

594594
TEST(VariableReflectionTest, GetEnumConstantDatamembers) {
595-
Cpp::CreateInterpreter();
595+
Cpp::CreateInterpreter({}, {}, true);
596596

597597
Cpp::Declare(R"(
598598
class MyEnumClass {
@@ -616,7 +616,7 @@ TEST(VariableReflectionTest, GetEnumConstantDatamembers) {
616616
}
617617

618618
TEST(VariableReflectionTest, Is_Get_Pointer) {
619-
Cpp::CreateInterpreter();
619+
Cpp::CreateInterpreter({}, {}, true);
620620
std::vector<Decl*> Decls;
621621
std::string code = R"(
622622
class A {};
@@ -648,7 +648,7 @@ TEST(VariableReflectionTest, Is_Get_Pointer) {
648648
}
649649

650650
TEST(VariableReflectionTest, Is_Get_Reference) {
651-
Cpp::CreateInterpreter();
651+
Cpp::CreateInterpreter({}, {}, true);
652652
std::vector<Decl*> Decls;
653653
std::string code = R"(
654654
class A {};

0 commit comments

Comments
 (0)