[llvm] [Orc] Drop call-wrapper shortcuts from core ExecutionSession interface (NFC) (PR #84774)
Stefan Gränitz via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 11 08:27:10 PDT 2024
https://github.com/weliveindetail created https://github.com/llvm/llvm-project/pull/84774
These functions are available through the ExecutorProcessControl interface.
>From 80b223b988e5aa7397d21ebd51e5958e31e5e58f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Stefan=20Gr=C3=A4nitz?= <stefan.graenitz at gmail.com>
Date: Mon, 11 Mar 2024 15:37:53 +0100
Subject: [PATCH] [Orc] Drop call-wrapper helper functions from core
ExecutionSession interface (NFC)
These functions are available through the ExecutorProcessControl interface.
---
llvm/include/llvm/ExecutionEngine/Orc/Core.h | 46 -------------------
.../ExecutionEngine/Orc/EPCEHFrameRegistrar.h | 7 +--
llvm/lib/ExecutionEngine/Orc/COFFPlatform.cpp | 9 ++--
.../ExecutionEngine/Orc/ELFNixPlatform.cpp | 9 ++--
.../Orc/EPCDebugObjectRegistrar.cpp | 3 +-
.../Orc/EPCEHFrameRegistrar.cpp | 17 +++----
llvm/lib/ExecutionEngine/Orc/LLJIT.cpp | 12 +++--
.../lib/ExecutionEngine/Orc/MachOPlatform.cpp | 3 +-
llvm/tools/llvm-jitlink/llvm-jitlink.cpp | 8 ++--
...ecutionSessionWrapperFunctionCallsTest.cpp | 15 +++---
10 files changed, 49 insertions(+), 80 deletions(-)
diff --git a/llvm/include/llvm/ExecutionEngine/Orc/Core.h b/llvm/include/llvm/ExecutionEngine/Orc/Core.h
index 45bf9adcf2a4ec..8e9f33fa73bd65 100644
--- a/llvm/include/llvm/ExecutionEngine/Orc/Core.h
+++ b/llvm/include/llvm/ExecutionEngine/Orc/Core.h
@@ -1645,52 +1645,6 @@ class ExecutionSession {
DispatchTask(std::move(T));
}
- /// Run a wrapper function in the executor.
- ///
- /// The wrapper function should be callable as:
- ///
- /// \code{.cpp}
- /// CWrapperFunctionResult fn(uint8_t *Data, uint64_t Size);
- /// \endcode{.cpp}
- ///
- /// The given OnComplete function will be called to return the result.
- template <typename... ArgTs>
- void callWrapperAsync(ArgTs &&... Args) {
- EPC->callWrapperAsync(std::forward<ArgTs>(Args)...);
- }
-
- /// Run a wrapper function in the executor. The wrapper function should be
- /// callable as:
- ///
- /// \code{.cpp}
- /// CWrapperFunctionResult fn(uint8_t *Data, uint64_t Size);
- /// \endcode{.cpp}
- shared::WrapperFunctionResult callWrapper(ExecutorAddr WrapperFnAddr,
- ArrayRef<char> ArgBuffer) {
- return EPC->callWrapper(WrapperFnAddr, ArgBuffer);
- }
-
- /// Run a wrapper function using SPS to serialize the arguments and
- /// deserialize the results.
- template <typename SPSSignature, typename SendResultT, typename... ArgTs>
- void callSPSWrapperAsync(ExecutorAddr WrapperFnAddr, SendResultT &&SendResult,
- const ArgTs &...Args) {
- EPC->callSPSWrapperAsync<SPSSignature, SendResultT, ArgTs...>(
- WrapperFnAddr, std::forward<SendResultT>(SendResult), Args...);
- }
-
- /// Run a wrapper function using SPS to serialize the arguments and
- /// deserialize the results.
- ///
- /// If SPSSignature is a non-void function signature then the second argument
- /// (the first in the Args list) should be a reference to a return value.
- template <typename SPSSignature, typename... WrapperCallArgTs>
- Error callSPSWrapper(ExecutorAddr WrapperFnAddr,
- WrapperCallArgTs &&...WrapperCallArgs) {
- return EPC->callSPSWrapper<SPSSignature, WrapperCallArgTs...>(
- WrapperFnAddr, std::forward<WrapperCallArgTs>(WrapperCallArgs)...);
- }
-
/// Wrap a handler that takes concrete argument types (and a sender for a
/// concrete return type) to produce an AsyncHandlerWrapperFunction. Uses SPS
/// to unpack the arguments and pack the result.
diff --git a/llvm/include/llvm/ExecutionEngine/Orc/EPCEHFrameRegistrar.h b/llvm/include/llvm/ExecutionEngine/Orc/EPCEHFrameRegistrar.h
index 182e9ed1041a63..b17726a1f170a5 100644
--- a/llvm/include/llvm/ExecutionEngine/Orc/EPCEHFrameRegistrar.h
+++ b/llvm/include/llvm/ExecutionEngine/Orc/EPCEHFrameRegistrar.h
@@ -20,6 +20,7 @@ namespace llvm {
namespace orc {
class ExecutionSession;
+class ExecutorProcessControl;
/// Register/Deregisters EH frames in a remote process via a
/// ExecutorProcessControl instance.
@@ -37,17 +38,17 @@ class EPCEHFrameRegistrar : public jitlink::EHFrameRegistrar {
/// Create a EPCEHFrameRegistrar with the given ExecutorProcessControl
/// object and registration/deregistration function addresses.
- EPCEHFrameRegistrar(ExecutionSession &ES,
+ EPCEHFrameRegistrar(ExecutorProcessControl &EPC,
ExecutorAddr RegisterEHFrameSectionWrapper,
ExecutorAddr DeregisterEHFRameSectionWrapper)
- : ES(ES), RegisterEHFrameSectionWrapper(RegisterEHFrameSectionWrapper),
+ : EPC(EPC), RegisterEHFrameSectionWrapper(RegisterEHFrameSectionWrapper),
DeregisterEHFrameSectionWrapper(DeregisterEHFRameSectionWrapper) {}
Error registerEHFrames(ExecutorAddrRange EHFrameSection) override;
Error deregisterEHFrames(ExecutorAddrRange EHFrameSection) override;
private:
- ExecutionSession &ES;
+ ExecutorProcessControl &EPC;
ExecutorAddr RegisterEHFrameSectionWrapper;
ExecutorAddr DeregisterEHFrameSectionWrapper;
};
diff --git a/llvm/lib/ExecutionEngine/Orc/COFFPlatform.cpp b/llvm/lib/ExecutionEngine/Orc/COFFPlatform.cpp
index c8f5a99099eaed..b75a73ff32a155 100644
--- a/llvm/lib/ExecutionEngine/Orc/COFFPlatform.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/COFFPlatform.cpp
@@ -707,21 +707,22 @@ Error COFFPlatform::bootstrapCOFFRuntime(JITDylib &PlatformJD) {
return Err;
// Call bootstrap functions
- if (auto Err = ES.callSPSWrapper<void()>(orc_rt_coff_platform_bootstrap))
+ auto &EPC = ES.getExecutorProcessControl();
+ if (auto Err = EPC.callSPSWrapper<void()>(orc_rt_coff_platform_bootstrap))
return Err;
// Do the pending jitdylib registration actions that we couldn't do
// because orc runtime was not linked fully.
for (auto KV : JDBootstrapStates) {
auto &JDBState = KV.second;
- if (auto Err = ES.callSPSWrapper<void(SPSString, SPSExecutorAddr)>(
+ if (auto Err = EPC.callSPSWrapper<void(SPSString, SPSExecutorAddr)>(
orc_rt_coff_register_jitdylib, JDBState.JDName,
JDBState.HeaderAddr))
return Err;
for (auto &ObjSectionMap : JDBState.ObjectSectionsMaps)
- if (auto Err = ES.callSPSWrapper<void(SPSExecutorAddr,
- SPSCOFFObjectSectionsMap, bool)>(
+ if (auto Err = EPC.callSPSWrapper<void(SPSExecutorAddr,
+ SPSCOFFObjectSectionsMap, bool)>(
orc_rt_coff_register_object_sections, JDBState.HeaderAddr,
ObjSectionMap, false))
return Err;
diff --git a/llvm/lib/ExecutionEngine/Orc/ELFNixPlatform.cpp b/llvm/lib/ExecutionEngine/Orc/ELFNixPlatform.cpp
index 2b6c4b9e7f4316..610e03fb026e57 100644
--- a/llvm/lib/ExecutionEngine/Orc/ELFNixPlatform.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/ELFNixPlatform.cpp
@@ -507,7 +507,8 @@ Error ELFNixPlatform::bootstrapELFNixRuntime(JITDylib &PlatformJD) {
if (!PJDDSOHandle)
return PJDDSOHandle.takeError();
- if (auto Err = ES.callSPSWrapper<void(uint64_t)>(
+ auto &EPC = ES.getExecutorProcessControl();
+ if (auto Err = EPC.callSPSWrapper<void(uint64_t)>(
orc_rt_elfnix_platform_bootstrap,
PJDDSOHandle->getAddress().getValue()))
return Err;
@@ -574,7 +575,8 @@ Error ELFNixPlatform::registerPerObjectSections(
inconvertibleErrorCode());
Error ErrResult = Error::success();
- if (auto Err = ES.callSPSWrapper<shared::SPSError(
+ auto &EPC = ES.getExecutorProcessControl();
+ if (auto Err = EPC.callSPSWrapper<shared::SPSError(
SPSELFPerObjectSectionsToRegister)>(
orc_rt_elfnix_register_object_sections, ErrResult, POSR))
return Err;
@@ -589,7 +591,8 @@ Expected<uint64_t> ELFNixPlatform::createPThreadKey() {
inconvertibleErrorCode());
Expected<uint64_t> Result(0);
- if (auto Err = ES.callSPSWrapper<SPSExpected<uint64_t>(void)>(
+ auto &EPC = ES.getExecutorProcessControl();
+ if (auto Err = EPC.callSPSWrapper<SPSExpected<uint64_t>(void)>(
orc_rt_elfnix_create_pthread_key, Result))
return std::move(Err);
return Result;
diff --git a/llvm/lib/ExecutionEngine/Orc/EPCDebugObjectRegistrar.cpp b/llvm/lib/ExecutionEngine/Orc/EPCDebugObjectRegistrar.cpp
index acd7e5a409fc57..2795d30e5cef40 100644
--- a/llvm/lib/ExecutionEngine/Orc/EPCDebugObjectRegistrar.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/EPCDebugObjectRegistrar.cpp
@@ -51,7 +51,8 @@ Expected<std::unique_ptr<EPCDebugObjectRegistrar>> createJITLoaderGDBRegistrar(
Error EPCDebugObjectRegistrar::registerDebugObject(ExecutorAddrRange TargetMem,
bool AutoRegisterCode) {
- return ES.callSPSWrapper<void(shared::SPSExecutorAddrRange, bool)>(
+ auto &EPC = ES.getExecutorProcessControl();
+ return EPC.callSPSWrapper<void(shared::SPSExecutorAddrRange, bool)>(
RegisterFn, TargetMem, AutoRegisterCode);
}
diff --git a/llvm/lib/ExecutionEngine/Orc/EPCEHFrameRegistrar.cpp b/llvm/lib/ExecutionEngine/Orc/EPCEHFrameRegistrar.cpp
index f15315260ab011..d4b3243a412e77 100644
--- a/llvm/lib/ExecutionEngine/Orc/EPCEHFrameRegistrar.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/EPCEHFrameRegistrar.cpp
@@ -18,30 +18,31 @@ namespace orc {
Expected<std::unique_ptr<EPCEHFrameRegistrar>>
EPCEHFrameRegistrar::Create(ExecutionSession &ES) {
+ auto &EPC = ES.getExecutorProcessControl();
// Lookup addresseses of the registration/deregistration functions in the
// bootstrap map.
ExecutorAddr RegisterEHFrameSectionWrapper;
ExecutorAddr DeregisterEHFrameSectionWrapper;
- if (auto Err = ES.getExecutorProcessControl().getBootstrapSymbols(
- {{RegisterEHFrameSectionWrapper,
- rt::RegisterEHFrameSectionWrapperName},
- {DeregisterEHFrameSectionWrapper,
- rt::DeregisterEHFrameSectionWrapperName}}))
+ if (auto Err =
+ EPC.getBootstrapSymbols({{RegisterEHFrameSectionWrapper,
+ rt::RegisterEHFrameSectionWrapperName},
+ {DeregisterEHFrameSectionWrapper,
+ rt::DeregisterEHFrameSectionWrapperName}}))
return std::move(Err);
return std::make_unique<EPCEHFrameRegistrar>(
- ES, RegisterEHFrameSectionWrapper, DeregisterEHFrameSectionWrapper);
+ EPC, RegisterEHFrameSectionWrapper, DeregisterEHFrameSectionWrapper);
}
Error EPCEHFrameRegistrar::registerEHFrames(ExecutorAddrRange EHFrameSection) {
- return ES.callSPSWrapper<void(SPSExecutorAddrRange)>(
+ return EPC.callSPSWrapper<void(SPSExecutorAddrRange)>(
RegisterEHFrameSectionWrapper, EHFrameSection);
}
Error EPCEHFrameRegistrar::deregisterEHFrames(
ExecutorAddrRange EHFrameSection) {
- return ES.callSPSWrapper<void(SPSExecutorAddrRange)>(
+ return EPC.callSPSWrapper<void(SPSExecutorAddrRange)>(
DeregisterEHFrameSectionWrapper, EHFrameSection);
}
diff --git a/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp b/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
index 79adda5b7bc034..5c3c0d5375d9a6 100644
--- a/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
@@ -614,9 +614,10 @@ Error ORCPlatformSupport::initialize(orc::JITDylib &JD) {
if (auto WrapperAddr = ES.lookup(
MainSearchOrder, J.mangleAndIntern("__orc_rt_jit_dlopen_wrapper"))) {
- return ES.callSPSWrapper<SPSDLOpenSig>(WrapperAddr->getAddress(),
- DSOHandles[&JD], JD.getName(),
- int32_t(ORC_RT_RTLD_LAZY));
+ auto &EPC = ES.getExecutorProcessControl();
+ return EPC.callSPSWrapper<SPSDLOpenSig>(WrapperAddr->getAddress(),
+ DSOHandles[&JD], JD.getName(),
+ int32_t(ORC_RT_RTLD_LAZY));
} else
return WrapperAddr.takeError();
}
@@ -632,8 +633,9 @@ Error ORCPlatformSupport::deinitialize(orc::JITDylib &JD) {
if (auto WrapperAddr = ES.lookup(
MainSearchOrder, J.mangleAndIntern("__orc_rt_jit_dlclose_wrapper"))) {
int32_t result;
- auto E = J.getExecutionSession().callSPSWrapper<SPSDLCloseSig>(
- WrapperAddr->getAddress(), result, DSOHandles[&JD]);
+ auto &EPC = ES.getExecutorProcessControl();
+ auto E = EPC.callSPSWrapper<SPSDLCloseSig>(WrapperAddr->getAddress(),
+ result, DSOHandles[&JD]);
if (E)
return E;
else if (result)
diff --git a/llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp b/llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp
index 994acf5843642a..de355eb491c5bd 100644
--- a/llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp
@@ -769,7 +769,8 @@ Expected<uint64_t> MachOPlatform::createPThreadKey() {
inconvertibleErrorCode());
Expected<uint64_t> Result(0);
- if (auto Err = ES.callSPSWrapper<SPSExpected<uint64_t>(void)>(
+ auto &EPC = ES.getExecutorProcessControl();
+ if (auto Err = EPC.callSPSWrapper<SPSExpected<uint64_t>(void)>(
CreatePThreadKey.Addr, Result))
return std::move(Err);
return Result;
diff --git a/llvm/tools/llvm-jitlink/llvm-jitlink.cpp b/llvm/tools/llvm-jitlink/llvm-jitlink.cpp
index 09b2a5900eb0b7..a8f1e2b295c218 100644
--- a/llvm/tools/llvm-jitlink/llvm-jitlink.cpp
+++ b/llvm/tools/llvm-jitlink/llvm-jitlink.cpp
@@ -2284,14 +2284,15 @@ static Expected<ExecutorSymbolDef> getEntryPoint(Session &S) {
static Expected<int> runWithRuntime(Session &S, ExecutorAddr EntryPointAddr) {
StringRef DemangledEntryPoint = EntryPointName;
- if (S.ES.getTargetTriple().getObjectFormat() == Triple::MachO &&
+ auto &EPC = S.ES.getExecutorProcessControl();
+ if (EPC.getTargetTriple().getObjectFormat() == Triple::MachO &&
DemangledEntryPoint.front() == '_')
DemangledEntryPoint = DemangledEntryPoint.drop_front();
using llvm::orc::shared::SPSString;
using SPSRunProgramSig =
int64_t(SPSString, SPSString, shared::SPSSequence<SPSString>);
int64_t Result;
- if (auto Err = S.ES.callSPSWrapper<SPSRunProgramSig>(
+ if (auto Err = EPC.callSPSWrapper<SPSRunProgramSig>(
EntryPointAddr, Result, S.MainJD->getName(), DemangledEntryPoint,
static_cast<std::vector<std::string> &>(InputArgv)))
return std::move(Err);
@@ -2300,7 +2301,8 @@ static Expected<int> runWithRuntime(Session &S, ExecutorAddr EntryPointAddr) {
static Expected<int> runWithoutRuntime(Session &S,
ExecutorAddr EntryPointAddr) {
- return S.ES.getExecutorProcessControl().runAsMain(EntryPointAddr, InputArgv);
+ auto &EPC = S.ES.getExecutorProcessControl();
+ return EPC.runAsMain(EntryPointAddr, InputArgv);
}
namespace {
diff --git a/llvm/unittests/ExecutionEngine/Orc/ExecutionSessionWrapperFunctionCallsTest.cpp b/llvm/unittests/ExecutionEngine/Orc/ExecutionSessionWrapperFunctionCallsTest.cpp
index 1b79e12ee168c8..1d4d448072ad0a 100644
--- a/llvm/unittests/ExecutionEngine/Orc/ExecutionSessionWrapperFunctionCallsTest.cpp
+++ b/llvm/unittests/ExecutionEngine/Orc/ExecutionSessionWrapperFunctionCallsTest.cpp
@@ -39,7 +39,8 @@ TEST(ExecutionSessionWrapperFunctionCalls, RunWrapperTemplate) {
ExecutionSession ES(cantFail(SelfExecutorProcessControl::Create()));
int32_t Result;
- EXPECT_THAT_ERROR(ES.callSPSWrapper<int32_t(int32_t, int32_t)>(
+ auto &EPC = ES.getExecutorProcessControl();
+ EXPECT_THAT_ERROR(EPC.callSPSWrapper<int32_t(int32_t, int32_t)>(
ExecutorAddr::fromPtr(addWrapper), Result, 2, 3),
Succeeded());
EXPECT_EQ(Result, 5);
@@ -50,10 +51,11 @@ TEST(ExecutionSessionWrapperFunctionCalls, RunVoidWrapperAsyncTemplate) {
ExecutionSession ES(cantFail(SelfExecutorProcessControl::Create()));
std::promise<MSVCPError> RP;
- ES.callSPSWrapperAsync<void()>(ExecutorAddr::fromPtr(voidWrapper),
- [&](Error SerializationErr) {
- RP.set_value(std::move(SerializationErr));
- });
+ auto &EPC = ES.getExecutorProcessControl();
+ EPC.callSPSWrapperAsync<void()>(ExecutorAddr::fromPtr(voidWrapper),
+ [&](Error SerializationErr) {
+ RP.set_value(std::move(SerializationErr));
+ });
Error Err = RP.get_future().get();
EXPECT_THAT_ERROR(std::move(Err), Succeeded());
cantFail(ES.endSession());
@@ -63,7 +65,8 @@ TEST(ExecutionSessionWrapperFunctionCalls, RunNonVoidWrapperAsyncTemplate) {
ExecutionSession ES(cantFail(SelfExecutorProcessControl::Create()));
std::promise<MSVCPExpected<int32_t>> RP;
- ES.callSPSWrapperAsync<int32_t(int32_t, int32_t)>(
+ auto &EPC = ES.getExecutorProcessControl();
+ EPC.callSPSWrapperAsync<int32_t(int32_t, int32_t)>(
ExecutorAddr::fromPtr(addWrapper),
[&](Error SerializationErr, int32_t R) {
if (SerializationErr)
More information about the llvm-commits
mailing list