Skip to content

Commit

Permalink
[ORC] Move CWrapperFunctionResult out of the detail:: namespace.
Browse files Browse the repository at this point in the history
This type has been moved up into the llvm::orc::shared namespace.

This type was originally put in the detail:: namespace on the assumption that
few (if any) LLVM source files would need to use it. In practice it has been
needed in many places, and will continue to be needed until/unless
OrcTargetProcess is fully merged into the ORC runtime.
  • Loading branch information
lhames committed Oct 30, 2021
1 parent 2d48b19 commit 213666f
Show file tree
Hide file tree
Showing 19 changed files with 58 additions and 63 deletions.
Expand Up @@ -456,7 +456,7 @@ class SelfExecutorProcessControl
void writeBuffersAsync(ArrayRef<tpctypes::BufferWrite> Ws,
WriteResultFn OnWriteComplete) override;

static shared::detail::CWrapperFunctionResult
static shared::CWrapperFunctionResult
jitDispatchViaWrapperFunctionManager(void *Ctx, const void *FnTag,
const char *Data, size_t Size);

Expand Down
Expand Up @@ -81,8 +81,8 @@ struct WrapperFunctionCall {
: Func(Func), ArgData(ArgData) {}

shared::WrapperFunctionResult run() {
using FnTy = shared::detail::CWrapperFunctionResult(const char *ArgData,
size_t ArgSize);
using FnTy =
shared::CWrapperFunctionResult(const char *ArgData, size_t ArgSize);
return shared::WrapperFunctionResult(
Func.toPtr<FnTy *>()(ArgData.Start.toPtr<const char *>(),
static_cast<size_t>(ArgData.size().getValue())));
Expand Down
Expand Up @@ -23,24 +23,18 @@ namespace llvm {
namespace orc {
namespace shared {

namespace detail {

// DO NOT USE DIRECTLY.
// Must be kept in-sync with compiler-rt/lib/orc/c-api.h.
union CWrapperFunctionResultDataUnion {
char *ValuePtr;
char Value[sizeof(ValuePtr)];
};

// DO NOT USE DIRECTLY.
// Must be kept in-sync with compiler-rt/lib/orc/c-api.h.
typedef struct {
CWrapperFunctionResultDataUnion Data;
size_t Size;
} CWrapperFunctionResult;

} // end namespace detail

/// C++ wrapper function result: Same as CWrapperFunctionResult but
/// auto-releases memory.
class WrapperFunctionResult {
Expand All @@ -49,11 +43,11 @@ class WrapperFunctionResult {
WrapperFunctionResult() { init(R); }

/// Create a WrapperFunctionResult by taking ownership of a
/// detail::CWrapperFunctionResult.
/// CWrapperFunctionResult.
///
/// Warning: This should only be used by clients writing wrapper-function
/// caller utilities (like TargetProcessControl).
WrapperFunctionResult(detail::CWrapperFunctionResult R) : R(R) {
WrapperFunctionResult(CWrapperFunctionResult R) : R(R) {
// Reset R.
init(R);
}
Expand All @@ -78,12 +72,12 @@ class WrapperFunctionResult {
free(R.Data.ValuePtr);
}

/// Release ownership of the contained detail::CWrapperFunctionResult.
/// Release ownership of the contained CWrapperFunctionResult.
/// Warning: Do not use -- this method will be removed in the future. It only
/// exists to temporarily support some code that will eventually be moved to
/// the ORC runtime.
detail::CWrapperFunctionResult release() {
detail::CWrapperFunctionResult Tmp;
CWrapperFunctionResult release() {
CWrapperFunctionResult Tmp;
init(Tmp);
std::swap(R, Tmp);
return Tmp;
Expand Down Expand Up @@ -164,12 +158,12 @@ class WrapperFunctionResult {
}

private:
static void init(detail::CWrapperFunctionResult &R) {
static void init(CWrapperFunctionResult &R) {
R.Data.ValuePtr = nullptr;
R.Size = 0;
}

detail::CWrapperFunctionResult R;
CWrapperFunctionResult R;
};

namespace detail {
Expand Down
Expand Up @@ -16,7 +16,7 @@
#include "llvm/ExecutionEngine/Orc/Shared/WrapperFunctionUtils.h"
#include <cstdint>

extern "C" llvm::orc::shared::detail::CWrapperFunctionResult
extern "C" llvm::orc::shared::CWrapperFunctionResult
llvm_orc_registerJITLoaderGDBWrapper(const char *Data, uint64_t Size);

#endif // LLVM_EXECUTIONENGINE_ORC_TARGETPROCESS_JITLOADERGDB_H
Expand Up @@ -37,22 +37,22 @@ Error deregisterEHFrameSection(const void *EHFrameSectionAddr,
/// call. This function expects the direct address and size of the eh-frame
/// section to register as its arguments (it does not treat its arguments as
/// pointers to an SPS-serialized arg buffer).
extern "C" llvm::orc::shared::detail::CWrapperFunctionResult
extern "C" llvm::orc::shared::CWrapperFunctionResult
llvm_orc_registerEHFrameSectionCustomDirectWrapper(
const char *EHFrameSectionAddr, uint64_t Size);

/// An eh-frame deregistration utility suitable for use as a support function
/// call. This function expects the direct address and size of the eh-frame
/// section to register as its arguments (it does not treat its arguments as
/// pointers to an SPS-serialized arg buffer).
extern "C" llvm::orc::shared::detail::CWrapperFunctionResult
extern "C" llvm::orc::shared::CWrapperFunctionResult
llvm_orc_deregisterEHFrameSectionCustomDirectWrapper(
const char *EHFrameSectionAddr, uint64_t Size);

extern "C" llvm::orc::shared::detail::CWrapperFunctionResult
extern "C" llvm::orc::shared::CWrapperFunctionResult
llvm_orc_registerEHFrameSectionWrapper(const char *Data, uint64_t Size);

extern "C" llvm::orc::shared::detail::CWrapperFunctionResult
extern "C" llvm::orc::shared::CWrapperFunctionResult
llvm_orc_deregisterEHFrameSectionWrapper(const char *Data, uint64_t Size);

#endif // LLVM_EXECUTIONENGINE_ORC_TARGETPROCESS_REGISTEREHFRAMES_H
Expand Up @@ -46,10 +46,10 @@ class SimpleExecutorDylibManager : public ExecutorBootstrapService {
private:
using DylibsMap = DenseMap<uint64_t, sys::DynamicLibrary>;

static llvm::orc::shared::detail::CWrapperFunctionResult
static llvm::orc::shared::CWrapperFunctionResult
openWrapper(const char *ArgData, size_t ArgSize);

static llvm::orc::shared::detail::CWrapperFunctionResult
static llvm::orc::shared::CWrapperFunctionResult
lookupWrapper(const char *ArgData, size_t ArgSize);

std::mutex M;
Expand Down
Expand Up @@ -50,13 +50,13 @@ class SimpleExecutorMemoryManager : public ExecutorBootstrapService {

Error deallocateImpl(void *Base, Allocation &A);

static llvm::orc::shared::detail::CWrapperFunctionResult
static llvm::orc::shared::CWrapperFunctionResult
reserveWrapper(const char *ArgData, size_t ArgSize);

static llvm::orc::shared::detail::CWrapperFunctionResult
static llvm::orc::shared::CWrapperFunctionResult
finalizeWrapper(const char *ArgData, size_t ArgSize);

static llvm::orc::shared::detail::CWrapperFunctionResult
static llvm::orc::shared::CWrapperFunctionResult
deallocateWrapper(const char *ArgData, size_t ArgSize);

std::mutex M;
Expand Down
Expand Up @@ -151,9 +151,10 @@ class SimpleRemoteEPCServer : public SimpleRemoteEPCTransportClient {
shared::WrapperFunctionResult
doJITDispatch(const void *FnTag, const char *ArgData, size_t ArgSize);

static shared::detail::CWrapperFunctionResult
jitDispatchEntry(void *DispatchCtx, const void *FnTag, const char *ArgData,
size_t ArgSize);
static shared::CWrapperFunctionResult jitDispatchEntry(void *DispatchCtx,
const void *FnTag,
const char *ArgData,
size_t ArgSize);

uint64_t getNextSeqNo() { return NextSeqNo++; }
void releaseSeqNo(uint64_t) {}
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/ExecutionEngine/Orc/ExecutorProcessControl.cpp
Expand Up @@ -125,7 +125,7 @@ void SelfExecutorProcessControl::callWrapperAsync(ExecutorAddr WrapperFnAddr,
IncomingWFRHandler SendResult,
ArrayRef<char> ArgBuffer) {
using WrapperFnTy =
shared::detail::CWrapperFunctionResult (*)(const char *Data, size_t Size);
shared::CWrapperFunctionResult (*)(const char *Data, size_t Size);
auto *WrapperFn = WrapperFnAddr.toPtr<WrapperFnTy>();
SendResult(WrapperFn(ArgBuffer.data(), ArgBuffer.size()));
}
Expand Down Expand Up @@ -170,7 +170,7 @@ void SelfExecutorProcessControl::writeBuffersAsync(
OnWriteComplete(Error::success());
}

shared::detail::CWrapperFunctionResult
shared::CWrapperFunctionResult
SelfExecutorProcessControl::jitDispatchViaWrapperFunctionManager(
void *Ctx, const void *FnTag, const char *Data, size_t Size) {

Expand Down
Expand Up @@ -93,7 +93,7 @@ static void registerJITLoaderGDBImpl(ExecutorAddrRange DebugObjRange) {
__jit_debug_register_code();
}

extern "C" orc::shared::detail::CWrapperFunctionResult
extern "C" orc::shared::CWrapperFunctionResult
llvm_orc_registerJITLoaderGDBWrapper(const char *Data, uint64_t Size) {
using namespace orc::shared;
return WrapperFunction<void(SPSExecutorAddrRange)>::handle(
Expand Down
6 changes: 3 additions & 3 deletions llvm/lib/ExecutionEngine/Orc/TargetProcess/OrcRTBootstrap.cpp
Expand Up @@ -22,7 +22,7 @@ namespace orc {
namespace rt_bootstrap {

template <typename WriteT, typename SPSWriteT>
static llvm::orc::shared::detail::CWrapperFunctionResult
static llvm::orc::shared::CWrapperFunctionResult
writeUIntsWrapper(const char *ArgData, size_t ArgSize) {
return WrapperFunction<void(SPSSequence<SPSWriteT>)>::handle(
ArgData, ArgSize,
Expand All @@ -33,7 +33,7 @@ writeUIntsWrapper(const char *ArgData, size_t ArgSize) {
.release();
}

static llvm::orc::shared::detail::CWrapperFunctionResult
static llvm::orc::shared::CWrapperFunctionResult
writeBuffersWrapper(const char *ArgData, size_t ArgSize) {
return WrapperFunction<void(SPSSequence<SPSMemoryAccessBufferWrite>)>::handle(
ArgData, ArgSize,
Expand All @@ -45,7 +45,7 @@ writeBuffersWrapper(const char *ArgData, size_t ArgSize) {
.release();
}

static llvm::orc::shared::detail::CWrapperFunctionResult
static llvm::orc::shared::CWrapperFunctionResult
runAsMainWrapper(const char *ArgData, size_t ArgSize) {
return WrapperFunction<rt::SPSRunAsMainSignature>::handle(
ArgData, ArgSize,
Expand Down
12 changes: 6 additions & 6 deletions llvm/lib/ExecutionEngine/Orc/TargetProcess/RegisterEHFrames.cpp
Expand Up @@ -158,22 +158,22 @@ Error deregisterEHFrameSection(const void *EHFrameSectionAddr,
} // end namespace orc
} // end namespace llvm

extern "C" llvm::orc::shared::detail::CWrapperFunctionResult
extern "C" llvm::orc::shared::CWrapperFunctionResult
llvm_orc_registerEHFrameSectionCustomDirectWrapper(
const char *EHFrameSectionAddr, uint64_t Size) {
if (auto Err = registerEHFrameSection(EHFrameSectionAddr, Size))
return WrapperFunctionResult::createOutOfBandError(toString(std::move(Err)))
.release();
return llvm::orc::shared::detail::CWrapperFunctionResult();
return llvm::orc::shared::CWrapperFunctionResult();
}

extern "C" llvm::orc::shared::detail::CWrapperFunctionResult
extern "C" llvm::orc::shared::CWrapperFunctionResult
llvm_orc_deregisterEHFrameSectionCustomDirectWrapper(
const char *EHFrameSectionAddr, uint64_t Size) {
if (auto Err = deregisterEHFrameSection(EHFrameSectionAddr, Size))
return WrapperFunctionResult::createOutOfBandError(toString(std::move(Err)))
.release();
return llvm::orc::shared::detail::CWrapperFunctionResult();
return llvm::orc::shared::CWrapperFunctionResult();
}

static Error registerEHFrameWrapper(ExecutorAddr Addr, uint64_t Size) {
Expand All @@ -184,14 +184,14 @@ static Error deregisterEHFrameWrapper(ExecutorAddr Addr, uint64_t Size) {
return llvm::orc::deregisterEHFrameSection(Addr.toPtr<const void *>(), Size);
}

extern "C" orc::shared::detail::CWrapperFunctionResult
extern "C" orc::shared::CWrapperFunctionResult
llvm_orc_registerEHFrameSectionWrapper(const char *Data, uint64_t Size) {
return WrapperFunction<SPSError(SPSExecutorAddr, uint64_t)>::handle(
Data, Size, registerEHFrameWrapper)
.release();
}

extern "C" orc::shared::detail::CWrapperFunctionResult
extern "C" orc::shared::CWrapperFunctionResult
llvm_orc_deregisterEHFrameSectionWrapper(const char *Data, uint64_t Size) {
return WrapperFunction<SPSError(SPSExecutorAddr, uint64_t)>::handle(
Data, Size, deregisterEHFrameWrapper)
Expand Down
Expand Up @@ -104,7 +104,7 @@ void SimpleExecutorDylibManager::addBootstrapSymbols(
ExecutorAddr::fromPtr(&lookupWrapper);
}

llvm::orc::shared::detail::CWrapperFunctionResult
llvm::orc::shared::CWrapperFunctionResult
SimpleExecutorDylibManager::openWrapper(const char *ArgData, size_t ArgSize) {
return shared::
WrapperFunction<rt::SPSSimpleExecutorDylibManagerOpenSignature>::handle(
Expand All @@ -114,7 +114,7 @@ SimpleExecutorDylibManager::openWrapper(const char *ArgData, size_t ArgSize) {
.release();
}

llvm::orc::shared::detail::CWrapperFunctionResult
llvm::orc::shared::CWrapperFunctionResult
SimpleExecutorDylibManager::lookupWrapper(const char *ArgData, size_t ArgSize) {
return shared::
WrapperFunction<rt::SPSSimpleExecutorDylibManagerLookupSignature>::handle(
Expand Down
Expand Up @@ -223,7 +223,7 @@ Error SimpleExecutorMemoryManager::deallocateImpl(void *Base, Allocation &A) {
return Err;
}

llvm::orc::shared::detail::CWrapperFunctionResult
llvm::orc::shared::CWrapperFunctionResult
SimpleExecutorMemoryManager::reserveWrapper(const char *ArgData,
size_t ArgSize) {
return shared::WrapperFunction<
Expand All @@ -234,7 +234,7 @@ SimpleExecutorMemoryManager::reserveWrapper(const char *ArgData,
.release();
}

llvm::orc::shared::detail::CWrapperFunctionResult
llvm::orc::shared::CWrapperFunctionResult
SimpleExecutorMemoryManager::finalizeWrapper(const char *ArgData,
size_t ArgSize) {
return shared::WrapperFunction<
Expand All @@ -245,7 +245,7 @@ SimpleExecutorMemoryManager::finalizeWrapper(const char *ArgData,
.release();
}

llvm::orc::shared::detail::CWrapperFunctionResult
llvm::orc::shared::CWrapperFunctionResult
SimpleExecutorMemoryManager::deallocateWrapper(const char *ArgData,
size_t ArgSize) {
return shared::WrapperFunction<
Expand Down
Expand Up @@ -246,7 +246,7 @@ void SimpleRemoteEPCServer::handleCallWrapper(
SimpleRemoteEPCArgBytesVector ArgBytes) {
D->dispatch([this, RemoteSeqNo, TagAddr, ArgBytes = std::move(ArgBytes)]() {
using WrapperFnTy =
shared::detail::CWrapperFunctionResult (*)(const char *, size_t);
shared::CWrapperFunctionResult (*)(const char *, size_t);
auto *Fn = TagAddr.toPtr<WrapperFnTy>();
shared::WrapperFunctionResult ResultBytes(
Fn(ArgBytes.data(), ArgBytes.size()));
Expand Down Expand Up @@ -281,7 +281,7 @@ SimpleRemoteEPCServer::doJITDispatch(const void *FnTag, const char *ArgData,
return ResultF.get();
}

shared::detail::CWrapperFunctionResult
shared::CWrapperFunctionResult
SimpleRemoteEPCServer::jitDispatchEntry(void *DispatchCtx, const void *FnTag,
const char *ArgData, size_t ArgSize) {
return reinterpret_cast<SimpleRemoteEPCServer *>(DispatchCtx)
Expand Down
Expand Up @@ -78,24 +78,24 @@ class SimpleAllocator {
DenseMap<void *, sys::OwningMemoryBlock> Blocks;
};

llvm::orc::shared::detail::CWrapperFunctionResult
testReserve(const char *ArgData, size_t ArgSize) {
llvm::orc::shared::CWrapperFunctionResult testReserve(const char *ArgData,
size_t ArgSize) {
return WrapperFunction<rt::SPSSimpleExecutorMemoryManagerReserveSignature>::
handle(ArgData, ArgSize,
makeMethodWrapperHandler(&SimpleAllocator::reserve))
.release();
}

llvm::orc::shared::detail::CWrapperFunctionResult
testFinalize(const char *ArgData, size_t ArgSize) {
llvm::orc::shared::CWrapperFunctionResult testFinalize(const char *ArgData,
size_t ArgSize) {
return WrapperFunction<rt::SPSSimpleExecutorMemoryManagerFinalizeSignature>::
handle(ArgData, ArgSize,
makeMethodWrapperHandler(&SimpleAllocator::finalize))
.release();
}

llvm::orc::shared::detail::CWrapperFunctionResult
testDeallocate(const char *ArgData, size_t ArgSize) {
llvm::orc::shared::CWrapperFunctionResult testDeallocate(const char *ArgData,
size_t ArgSize) {
return WrapperFunction<
rt::SPSSimpleExecutorMemoryManagerDeallocateSignature>::
handle(ArgData, ArgSize,
Expand Down
Expand Up @@ -18,8 +18,8 @@ using namespace llvm::orc::shared;
namespace {

template <typename WriteT, typename SPSWriteT>
llvm::orc::shared::detail::CWrapperFunctionResult
testWriteUInts(const char *ArgData, size_t ArgSize) {
llvm::orc::shared::CWrapperFunctionResult testWriteUInts(const char *ArgData,
size_t ArgSize) {
return WrapperFunction<void(SPSSequence<SPSWriteT>)>::handle(
ArgData, ArgSize,
[](std::vector<WriteT> Ws) {
Expand All @@ -29,8 +29,8 @@ testWriteUInts(const char *ArgData, size_t ArgSize) {
.release();
}

llvm::orc::shared::detail::CWrapperFunctionResult
testWriteBuffers(const char *ArgData, size_t ArgSize) {
llvm::orc::shared::CWrapperFunctionResult testWriteBuffers(const char *ArgData,
size_t ArgSize) {
return WrapperFunction<void(SPSSequence<SPSMemoryAccessBufferWrite>)>::handle(
ArgData, ArgSize,
[](std::vector<tpctypes::BufferWrite> Ws) {
Expand Down

0 comments on commit 213666f

Please sign in to comment.