[clang] [clang-repl] Rework layering of incremental executors. (PR #175448)
Anutosh Bhat via cfe-commits
cfe-commits at lists.llvm.org
Mon Jan 12 01:43:00 PST 2026
https://github.com/anutosh491 approved this pull request.
Looks great to me
Here's what I did
1) Fetched the commit and built it for wasm.
- Ran `node ./ClangReplInterpreterTests.js` and everything passes as expected
```
anutosh491 at Anutoshs-MacBook-Air Interpreter % node ./ClangReplInterpreterTests.js
[==========] Running 27 tests from 5 test suites.
[----------] Global test environment set-up.
[----------] 2 tests from IncrementalCompilerBuilder
[ RUN ] IncrementalCompilerBuilder.SetCompilerArgs
[ OK ] IncrementalCompilerBuilder.SetCompilerArgs (32 ms)
....
....
....
[ OK ] CodeCompletionTest.NestedInvocations (44 ms)
[ RUN ] CodeCompletionTest.TemplateFunctions
[ OK ] CodeCompletionTest.TemplateFunctions (62 ms)
[----------] 12 tests from CodeCompletionTest (710 ms total)
[----------] Global test environment tear-down
[==========] 27 tests from 5 test suites ran. (2060 ms total)
[ PASSED ] 23 tests.
[ SKIPPED ] 4 tests, listed below:
[ SKIPPED ] IncrementalCompilerBuilder.SetTargetTriple
[ SKIPPED ] InterpreterTest.UndoCommand
[ SKIPPED ] InterpreterExtensionsTest.DefaultCrossJIT
[ SKIPPED ] InterpreterExtensionsTest.CustomCrossJIT
```
- Tried it in a demo playground
<img width="783" height="420" alt="image" src="https://github.com/user-attachments/assets/d27aee4c-508b-4468-99df-536d88f19d06" />
2) The next step what I did is, based on my comment above https://github.com/llvm/llvm-project/pull/175448#issuecomment-3737055710, I tried having a wasm build with no orc related symbols whatsoever/ not compiling any orc jit lib
A quick rough diff for that would be
```
diff --git a/clang/include/clang/Interpreter/IncrementalExecutor.h b/clang/include/clang/Interpreter/IncrementalExecutor.h
index 913da9230a94..be72696e4cfa 100644
--- a/clang/include/clang/Interpreter/IncrementalExecutor.h
+++ b/clang/include/clang/Interpreter/IncrementalExecutor.h
@@ -33,6 +33,7 @@ class Compilation;
class IncrementalExecutorBuilder {
public:
+#ifndef __EMSCRIPTEN__
/// Indicates whether out-of-process JIT execution is enabled.
bool IsOutOfProcess = false;
/// Path to the out-of-process JIT executor.
@@ -50,8 +51,12 @@ public:
std::function<void()> CustomizeFork = nullptr;
/// An optional code model to provide to the JITTargetMachineBuilder
std::optional<llvm::CodeModel::Model> CM = std::nullopt;
+#endif
+
/// An optional external IncrementalExecutor
std::unique_ptr<IncrementalExecutor> IE;
+
+#ifndef __EMSCRIPTEN__
/// An optional external orc jit builder
std::unique_ptr<llvm::orc::LLJITBuilder> JITBuilder;
/// A default callback that can be used in the IncrementalCompilerBuilder to
@@ -60,6 +65,7 @@ public:
UpdateOrcRuntimePathCB = [this](const driver::Compilation &C) {
return UpdateOrcRuntimePath(C);
};
+#endif
~IncrementalExecutorBuilder();
@@ -67,7 +73,9 @@ public:
create(llvm::orc::ThreadSafeContext &TSC, const clang::TargetInfo &TI);
private:
+#ifndef __EMSCRIPTEN__
llvm::Error UpdateOrcRuntimePath(const driver::Compilation &C);
+#endif
};
struct PartialTranslationUnit;
diff --git a/clang/lib/Interpreter/CMakeLists.txt b/clang/lib/Interpreter/CMakeLists.txt
index 01d3295d1ac3..50fcd99b8a08 100644
--- a/clang/lib/Interpreter/CMakeLists.txt
+++ b/clang/lib/Interpreter/CMakeLists.txt
@@ -1,17 +1,23 @@
set(LLVM_LINK_COMPONENTS
- core
- native
- MC
- Option
- OrcJit
- OrcDebugging
- OrcShared
- OrcTargetProcess
- Support
- Target
- TargetParser
- TransformUtils
- )
+ core
+ native
+ MC
+ Option
+ Support
+ Target
+ TargetParser
+ TransformUtils
+)
+
+# Only add ORC JIT-related components for non-Emscripten builds
+if(NOT EMSCRIPTEN)
+ list(APPEND LLVM_LINK_COMPONENTS
+ OrcJit
+ OrcDebugging
+ OrcShared
+ OrcTargetProcess
+ )
+endif()
if (EMSCRIPTEN AND "lld" IN_LIST LLVM_ENABLE_PROJECTS)
set(WASM_SRC Wasm.cpp)
@@ -19,12 +25,11 @@ if (EMSCRIPTEN AND "lld" IN_LIST LLVM_ENABLE_PROJECTS)
set(COMMON_LINK lldCommon)
endif()
-add_clang_library(clangInterpreter
+set(INTERPRETER_SOURCES
DeviceOffload.cpp
CodeCompletion.cpp
IncrementalAction.cpp
IncrementalExecutor.cpp
- OrcIncrementalExecutor.cpp
IncrementalParser.cpp
Interpreter.cpp
InterpreterValuePrinter.cpp
@@ -32,6 +37,15 @@ add_clang_library(clangInterpreter
Value.cpp
InterpreterValuePrinter.cpp
${WASM_SRC}
+)
+
+# Only include OrcIncrementalExecutor for non-Emscripten builds
+if(NOT EMSCRIPTEN)
+ list(APPEND INTERPRETER_SOURCES OrcIncrementalExecutor.cpp)
+endif()
+
+add_clang_library(clangInterpreter
+ ${INTERPRETER_SOURCES}
PARTIAL_SOURCES_INTENDED
DEPENDS
@@ -53,7 +67,7 @@ add_clang_library(clangInterpreter
clangSerialization
${WASM_LINK}
${COMMON_LINK}
- )
+)
if ((MINGW OR CYGWIN) AND BUILD_SHARED_LIBS)
# The DLLs are supposed to export all symbols (except for ones that are
diff --git a/clang/lib/Interpreter/IncrementalExecutor.cpp b/clang/lib/Interpreter/IncrementalExecutor.cpp
index 001651522c32..0d3c08297c1d 100644
--- a/clang/lib/Interpreter/IncrementalExecutor.cpp
+++ b/clang/lib/Interpreter/IncrementalExecutor.cpp
@@ -11,10 +11,11 @@
//===----------------------------------------------------------------------===//
#include "clang/Interpreter/IncrementalExecutor.h"
-#include "OrcIncrementalExecutor.h"
#ifdef __EMSCRIPTEN__
-#include "Wasm.h"
-#endif // __EMSCRIPTEN__
+ #include "Wasm.h"
+#else
+ #include "OrcIncrementalExecutor.h"
+#endif
#include "clang/Basic/TargetInfo.h"
#include "clang/Driver/Compilation.h"
@@ -26,17 +27,19 @@
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/Twine.h"
-#include "llvm/ExecutionEngine/JITLink/JITLinkMemoryManager.h"
-#include "llvm/ExecutionEngine/Orc/Debugging/DebuggerSupport.h"
-#include "llvm/ExecutionEngine/Orc/EPCDynamicLibrarySearchGenerator.h"
-#include "llvm/ExecutionEngine/Orc/ExecutionUtils.h"
-#include "llvm/ExecutionEngine/Orc/ExecutorProcessControl.h"
-#include "llvm/ExecutionEngine/Orc/JITTargetMachineBuilder.h"
-#include "llvm/ExecutionEngine/Orc/LLJIT.h"
-#include "llvm/ExecutionEngine/Orc/MapperJITLinkMemoryManager.h"
-#include "llvm/ExecutionEngine/Orc/Shared/OrcRTBridge.h"
-#include "llvm/ExecutionEngine/Orc/Shared/SimpleRemoteEPCUtils.h"
-#include "llvm/ExecutionEngine/Orc/SimpleRemoteEPC.h"
+#ifndef __EMSCRIPTEN__
+ #include "llvm/ExecutionEngine/JITLink/JITLinkMemoryManager.h"
+ #include "llvm/ExecutionEngine/Orc/Debugging/DebuggerSupport.h"
+ #include "llvm/ExecutionEngine/Orc/EPCDynamicLibrarySearchGenerator.h"
+ #include "llvm/ExecutionEngine/Orc/ExecutionUtils.h"
+ #include "llvm/ExecutionEngine/Orc/ExecutorProcessControl.h"
+ #include "llvm/ExecutionEngine/Orc/JITTargetMachineBuilder.h"
+ #include "llvm/ExecutionEngine/Orc/LLJIT.h"
+ #include "llvm/ExecutionEngine/Orc/MapperJITLinkMemoryManager.h"
+ #include "llvm/ExecutionEngine/Orc/Shared/OrcRTBridge.h"
+ #include "llvm/ExecutionEngine/Orc/Shared/SimpleRemoteEPCUtils.h"
+ #include "llvm/ExecutionEngine/Orc/SimpleRemoteEPC.h"
+#endif
#include "llvm/Support/Error.h"
#include "llvm/Support/FileSystem.h"
@@ -63,6 +66,7 @@
namespace clang {
IncrementalExecutorBuilder::~IncrementalExecutorBuilder() = default;
+#ifndef __EMSCRIPTEN__
static llvm::Expected<llvm::orc::JITTargetMachineBuilder>
createJITTargetMachineBuilder(const llvm::Triple &TT) {
if (TT.getTriple() == llvm::sys::getProcessTriple())
@@ -368,12 +372,20 @@ outOfProcessJITBuilder(const IncrementalExecutorBuilder &IncrExecutorBuilder) {
return std::make_pair(std::move(JB), childPid);
}
+#endif // !__EMSCRIPTEN__
llvm::Expected<std::unique_ptr<IncrementalExecutor>>
IncrementalExecutorBuilder::create(llvm::orc::ThreadSafeContext &TSC,
const clang::TargetInfo &TI) {
if (IE)
return std::move(IE);
+
+#ifdef __EMSCRIPTEN__
+ (void)TSC;
+ (void)TI;
+ return std::make_unique<WasmIncrementalExecutor>();
+#else
+
llvm::Triple TT = TI.getTriple();
if (!TT.isOSWindows() && IsOutOfProcess) {
if (!JITBuilder) {
@@ -403,18 +415,16 @@ IncrementalExecutorBuilder::create(llvm::orc::ThreadSafeContext &TSC,
llvm::Error Err = llvm::Error::success();
std::unique_ptr<IncrementalExecutor> Executor;
-#ifdef __EMSCRIPTEN__
- Executor = std::make_unique<WasmIncrementalExecutor>();
-#else
Executor = std::make_unique<OrcIncrementalExecutor>(TSC, *JITBuilder, Err);
-#endif
if (Err)
return std::move(Err);
return std::move(Executor);
+#endif
}
+#ifndef __EMSCRIPTEN__
llvm::Error IncrementalExecutorBuilder::UpdateOrcRuntimePath(
const clang::driver::Compilation &C) {
if (!IsOutOfProcess)
@@ -506,5 +516,6 @@ llvm::Error IncrementalExecutorBuilder::UpdateOrcRuntimePath(
llvm::formatv("OrcRuntime library not found in: {0}", Joined).str(),
llvm::inconvertibleErrorCode());
}
+#endif // !__EMSCRIPTEN__
} // end namespace clang
```
**This wasm build on libclangInterpreter.a would be devoid of any ORC influence. And then again I ran the tests. All tests pass as expected and the binary size is much smaller as we need.**
Shall raise a PR with my rough draft soon and we can review it further there.
https://github.com/llvm/llvm-project/pull/175448
More information about the cfe-commits
mailing list