Skip to content

Commit f78129e

Browse files
[Orc] Add NotifyCreated callback for LLJITBuilder (#84175)
This is useful to attach generators to JITDylibs or inject initial symbol definitions.
1 parent a0c7714 commit f78129e

File tree

1 file changed

+18
-0
lines changed
  • llvm/include/llvm/ExecutionEngine/Orc

1 file changed

+18
-0
lines changed

llvm/include/llvm/ExecutionEngine/Orc/LLJIT.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,8 @@ class LLJITBuilderState {
311311

312312
using PlatformSetupFunction = unique_function<Expected<JITDylibSP>(LLJIT &J)>;
313313

314+
using NotifyCreatedFunction = std::function<Error(LLJIT &)>;
315+
314316
std::unique_ptr<ExecutorProcessControl> EPC;
315317
std::unique_ptr<ExecutionSession> ES;
316318
std::optional<JITTargetMachineBuilder> JTMB;
@@ -321,6 +323,7 @@ class LLJITBuilderState {
321323
CompileFunctionCreator CreateCompileFunction;
322324
unique_function<Error(LLJIT &)> PrePlatformSetup;
323325
PlatformSetupFunction SetUpPlatform;
326+
NotifyCreatedFunction NotifyCreated;
324327
unsigned NumCompileThreads = 0;
325328

326329
/// Called prior to JIT class construcion to fix up defaults.
@@ -441,6 +444,16 @@ class LLJITBuilderSetters {
441444
return impl();
442445
}
443446

447+
/// Set up a callback after successful construction of the JIT.
448+
///
449+
/// This is useful to attach generators to JITDylibs or inject initial symbol
450+
/// definitions.
451+
SetterImpl &
452+
setNotifyCreatedCallback(LLJITBuilderState::NotifyCreatedFunction Callback) {
453+
impl().NotifyCreated = std::move(Callback);
454+
return impl();
455+
}
456+
444457
/// Set the number of compile threads to use.
445458
///
446459
/// If set to zero, compilation will be performed on the execution thread when
@@ -474,6 +487,11 @@ class LLJITBuilderSetters {
474487
std::unique_ptr<JITType> J(new JITType(impl(), Err));
475488
if (Err)
476489
return std::move(Err);
490+
491+
if (impl().NotifyCreated)
492+
if (Error Err = impl().NotifyCreated(*J))
493+
return Err;
494+
477495
return std::move(J);
478496
}
479497

0 commit comments

Comments
 (0)