[llvm] [Orc] Add NotifyCreated callback for LLJITBuilder (PR #84175)
Stefan Gränitz via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 7 08:33:38 PST 2024
https://github.com/weliveindetail updated https://github.com/llvm/llvm-project/pull/84175
>From 5de083a0dcfdec9a15de04152807715e4091e2ea Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Stefan=20Gr=C3=A4nitz?= <stefan.graenitz at gmail.com>
Date: Wed, 6 Mar 2024 15:07:10 +0100
Subject: [PATCH 1/2] [Orc] Add NotifyCreated callback for LLJITBuilder
---
llvm/include/llvm/ExecutionEngine/Orc/LLJIT.h | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/llvm/include/llvm/ExecutionEngine/Orc/LLJIT.h b/llvm/include/llvm/ExecutionEngine/Orc/LLJIT.h
index 76d16e63df2815..ea6ee785028c31 100644
--- a/llvm/include/llvm/ExecutionEngine/Orc/LLJIT.h
+++ b/llvm/include/llvm/ExecutionEngine/Orc/LLJIT.h
@@ -311,6 +311,8 @@ class LLJITBuilderState {
using PlatformSetupFunction = unique_function<Expected<JITDylibSP>(LLJIT &J)>;
+ using NotifyCreatedFunction = std::function<void(LLJIT &)>;
+
std::unique_ptr<ExecutorProcessControl> EPC;
std::unique_ptr<ExecutionSession> ES;
std::optional<JITTargetMachineBuilder> JTMB;
@@ -321,6 +323,7 @@ class LLJITBuilderState {
CompileFunctionCreator CreateCompileFunction;
unique_function<Error(LLJIT &)> PrePlatformSetup;
PlatformSetupFunction SetUpPlatform;
+ NotifyCreatedFunction NotifyCreated;
unsigned NumCompileThreads = 0;
/// Called prior to JIT class construcion to fix up defaults.
@@ -441,6 +444,16 @@ class LLJITBuilderSetters {
return impl();
}
+ /// Set up a callback after successful construction of the JIT.
+ ///
+ /// This is useful to attach generators to JITDylibs or inject initial symbol
+ /// definitions.
+ SetterImpl &
+ setNotifyCreatedCallback(LLJITBuilderState::NotifyCreatedFunction Callback) {
+ impl().NotifyCreated = std::move(Callback);
+ return impl();
+ }
+
/// Set the number of compile threads to use.
///
/// If set to zero, compilation will be performed on the execution thread when
@@ -474,6 +487,10 @@ class LLJITBuilderSetters {
std::unique_ptr<JITType> J(new JITType(impl(), Err));
if (Err)
return std::move(Err);
+
+ if (impl().NotifyCreated)
+ impl().NotifyCreated(*J);
+
return std::move(J);
}
>From 93638c9a68827a8dec326ea65f336fa2cc27eff7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Stefan=20Gr=C3=A4nitz?= <stefan.graenitz at gmail.com>
Date: Thu, 7 Mar 2024 17:32:17 +0100
Subject: [PATCH 2/2] fixup! [Orc] Add NotifyCreated callback for LLJITBuilder
Change the return type to allow Error results
---
llvm/include/llvm/ExecutionEngine/Orc/LLJIT.h | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/llvm/include/llvm/ExecutionEngine/Orc/LLJIT.h b/llvm/include/llvm/ExecutionEngine/Orc/LLJIT.h
index ea6ee785028c31..d5682fcaa28b79 100644
--- a/llvm/include/llvm/ExecutionEngine/Orc/LLJIT.h
+++ b/llvm/include/llvm/ExecutionEngine/Orc/LLJIT.h
@@ -311,7 +311,7 @@ class LLJITBuilderState {
using PlatformSetupFunction = unique_function<Expected<JITDylibSP>(LLJIT &J)>;
- using NotifyCreatedFunction = std::function<void(LLJIT &)>;
+ using NotifyCreatedFunction = std::function<Error(LLJIT &)>;
std::unique_ptr<ExecutorProcessControl> EPC;
std::unique_ptr<ExecutionSession> ES;
@@ -489,7 +489,8 @@ class LLJITBuilderSetters {
return std::move(Err);
if (impl().NotifyCreated)
- impl().NotifyCreated(*J);
+ if (Error Err = impl().NotifyCreated(*J))
+ return Err;
return std::move(J);
}
More information about the llvm-commits
mailing list