Skip to content

Commit 0fa9c8f

Browse files
author
kr-2003
committed
addition of oop jit execution
1 parent c031963 commit 0fa9c8f

19 files changed

+805
-68
lines changed

.github/actions/Build_LLVM/action.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ runs:
4949
git apply -v ../patches/llvm/clang${{ matrix.clang-runtime }}-*.patch
5050
echo "Apply clang${{ matrix.clang-runtime }}-*.patch patches:"
5151
fi
52+
if [[ "${{ matrix.llvm_enable_runtimes }}" == "clang;compile-rt" ]]; then
53+
git apply -v ../patches/llvm/out-of-process-jit-execution.patch
54+
echo "Apply out-of-process-jit-execution.patch:"
55+
fi
5256
cd build
5357
cmake -DLLVM_ENABLE_PROJECTS="${{ matrix.llvm_enable_projects}}" \
5458
-DLLVM_TARGETS_TO_BUILD="${{ matrix.llvm_targets_to_build }}" \
@@ -64,6 +68,13 @@ runs:
6468
-DLLVM_INCLUDE_TESTS=OFF \
6569
../llvm
6670
ninja clang clangInterpreter clangStaticAnalyzerCore -j ${{ env.ncpus }}
71+
if [[ "${{ matrix.llvm_enable_runtimes }}" == "clang;compile-rt" ]]; then
72+
if [[ "${{ runner.os }}" == "Linux" ]]; then
73+
ninja clang clang-repl llvm-jitlink-executor orc_rt -j $(nproc --all)
74+
elif [[ "${{ runner.os }}" == "macOS" ]]; then
75+
ninja clang clang-repl llvm-jitlink-executor orc_rt -j $(nproc --all)
76+
fi
77+
fi
6778
cd ./tools/
6879
rm -rf $(find . -maxdepth 1 ! -name "clang" ! -name ".")
6980
cd ..

.github/workflows/MacOS-arm.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
clang-runtime: '20'
2929
cling: Off
3030
cppyy: Off
31-
llvm_enable_projects: "clang"
31+
llvm_enable_projects: "clang;compiler-rt"
3232
llvm_targets_to_build: "host"
3333
- name: osx15-arm-clang-clang-repl-19-cppyy
3434
os: macos-15

.github/workflows/MacOS.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
clang-runtime: '20'
2929
cling: Off
3030
cppyy: Off
31-
llvm_enable_projects: "clang"
31+
llvm_enable_projects: "clang;compiler-rt"
3232
llvm_targets_to_build: "host"
3333
- name: osx13-x86-clang-clang-repl-19-cppyy
3434
os: macos-13

.github/workflows/Ubuntu-arm.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
clang-runtime: '20'
2929
cling: Off
3030
cppyy: Off
31-
llvm_enable_projects: "clang"
31+
llvm_enable_projects: "clang;compiler-rt"
3232
llvm_targets_to_build: "host;NVPTX"
3333
coverage: true
3434
- name: ubu24-arm-gcc12-clang-repl-20

.github/workflows/Ubuntu.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
clang-runtime: '20'
2929
cling: Off
3030
cppyy: Off
31-
llvm_enable_projects: "clang"
31+
llvm_enable_projects: "clang;compiler-rt"
3232
llvm_targets_to_build: "host;NVPTX"
3333
- name: ubu24-x86-gcc12-clang-repl-19-cppyy
3434
os: ubuntu-24.04

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,9 @@ else()
305305
message(FATAL_ERROR "We need either CPPINTEROP_USE_CLING or CPPINTEROP_USE_REPL")
306306
endif()
307307

308+
string(REGEX REPLACE "/build/lib/cmake/llvm$" "" LLVM_SOURCE_DIR "${LLVM_DIR}")
309+
add_definitions(-DLLVM_SOURCE_DIR="${LLVM_SOURCE_DIR}")
310+
308311
include_directories(SYSTEM ${CLANG_INCLUDE_DIRS})
309312
include_directories(SYSTEM ${LLVM_INCLUDE_DIRS})
310313
separate_arguments(LLVM_DEFINITIONS_LIST NATIVE_COMMAND ${LLVM_DEFINITIONS})

README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,13 @@ git apply -v clang{version}-*.patch
125125

126126
on Windows.
127127

128+
If you want to have out-of-process JIT execution enabled in CppInterOp, then apply this patch on Linux and MacOS environment.
129+
> Note that this patch will not work for Windows because out-of-process JIT execution is currently implemented for Linux and MacOS only.
130+
131+
```bash
132+
git apply -v ../CppInterOp/patches/llvm/out-of-process-jit-execution.patch
133+
```
134+
128135
##### Build Clang-REPL
129136

130137
Clang-REPL is an interpreter that CppInterOp works alongside. Build Clang (and
@@ -180,6 +187,30 @@ $env:LLVM_DIR= $PWD.Path
180187
cd ..\
181188
```
182189

190+
##### Build Clang-REPL with Out-of-Process JIT Execution
191+
192+
To have ``Out-of-Process JIT Execution`` enabled, run following commands to build clang and clang-repl to support this feature:
193+
> Only for Linux and Macos
194+
```bash
195+
mkdir build
196+
cd build
197+
cmake -DLLVM_ENABLE_PROJECTS="clang;compiler-rt \
198+
-DLLVM_TARGETS_TO_BUILD="host;NVPTX" \
199+
-DCMAKE_BUILD_TYPE=Release \
200+
-DLLVM_ENABLE_ASSERTIONS=ON \
201+
-DCLANG_ENABLE_STATIC_ANALYZER=OFF \
202+
-DCLANG_ENABLE_ARCMT=OFF \
203+
-DCLANG_ENABLE_FORMAT=OFF \
204+
-DCLANG_ENABLE_BOOTSTRAP=OFF \
205+
../llvm
206+
207+
## For Linux
208+
cmake --build . --target clang clang-repl llvm-jitlink-executor orc_rt --parallel $(nproc --all)
209+
210+
## For MacOS
211+
cmake --build . --target clang clang-repl llvm-jitlink-executor orc_rt_osx --parallel $(nproc --all)
212+
```
213+
183214
#### Build Cling and related dependencies
184215
185216
Besides the Clang-REPL interpreter, CppInterOp also works alongside the Cling

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 = {}, bool is_out_of_process = false);
612+
const std::vector<const char*>& GpuArgs = {}, bool outOfProcess = 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: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ static llvm::ExitOnError ExitOnError;
214214
namespace compat {
215215

216216
inline std::unique_ptr<clang::Interpreter>
217-
createClangInterpreter(std::vector<const char*>& args, bool is_out_of_process) {
217+
createClangInterpreter(std::vector<const char*>& args, bool outOfProcess) {
218218
auto has_arg = [](const char* x, llvm::StringRef match = "cuda") {
219219
llvm::StringRef Arg = x;
220220
Arg = Arg.trim().ltrim('-');
@@ -255,7 +255,7 @@ createClangInterpreter(std::vector<const char*>& args, bool is_out_of_process) {
255255

256256
std::unique_ptr<llvm::orc::LLJITBuilder> JB;
257257

258-
if(is_out_of_process) {
258+
if(outOfProcess) {
259259
std::string OOPExecutor = "/Users/abhinavkumar/Desktop/Coding/CERN_HSF_COMPILER_RESEARCH/llvm-project-test/build/bin/llvm-jitlink-executor";
260260
bool UseSharedMemory = false;
261261
std::string SlabAllocateSizeString = "";
@@ -283,24 +283,7 @@ createClangInterpreter(std::vector<const char*>& args, bool is_out_of_process) {
283283
"Failed to build Interpreter:");
284284
return nullptr;
285285
}
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));
286+
304287
if (CudaEnabled) {
305288
if (auto Err = (*innerOrErr)->LoadDynamicLibrary("libcudart.so")) {
306289
llvm::logAllUnhandledErrors(std::move(Err), llvm::errs(),
@@ -310,7 +293,6 @@ createClangInterpreter(std::vector<const char*>& args, bool is_out_of_process) {
310293
}
311294

312295
return std::move(*innerOrErr);
313-
// return interpreter;
314296
}
315297

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

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, bool is_out_of_process = false) {
153+
void* extraLibHandle = nullptr, bool noRuntime = true, bool outOfProcess = 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, is_out_of_process);
161+
auto CI = compat::createClangInterpreter(vargs, outOfProcess);
162162
if (!CI) {
163163
llvm::errs() << "Interpreter creation failed\n";
164164
return nullptr;

0 commit comments

Comments
 (0)