mirror of
https://github.com/RPCSX/llvm.git
synced 2024-11-24 12:19:53 +00:00
[ORC] clang-format code that was touched in r267457. NFC.
Commit r267457 made a lot of type-substitutions threw off code formatting and alignment. This patch should tidy those changes up. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@267475 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
02e4498043
commit
3869f2a5ab
@ -32,15 +32,11 @@ extern "C" {
|
||||
typedef struct LLVMOrcOpaqueJITStack *LLVMOrcJITStackRef;
|
||||
typedef uint32_t LLVMOrcModuleHandle;
|
||||
typedef uint64_t LLVMOrcTargetAddress;
|
||||
typedef uint64_t (*LLVMOrcSymbolResolverFn)(const char *Name,
|
||||
void *LookupCtx);
|
||||
typedef uint64_t (*LLVMOrcSymbolResolverFn)(const char *Name, void *LookupCtx);
|
||||
typedef uint64_t (*LLVMOrcLazyCompileCallbackFn)(LLVMOrcJITStackRef JITStack,
|
||||
void *CallbackCtx);
|
||||
|
||||
typedef enum {
|
||||
LLVMOrcErrSuccess = 0,
|
||||
LLVMOrcErrGeneric
|
||||
} LLVMOrcErrorCode;
|
||||
typedef enum { LLVMOrcErrSuccess = 0, LLVMOrcErrGeneric } LLVMOrcErrorCode;
|
||||
|
||||
/**
|
||||
* Create an ORC JIT stack.
|
||||
@ -114,8 +110,8 @@ LLVMOrcAddLazilyCompiledIR(LLVMOrcJITStackRef JITStack, LLVMModuleRef Mod,
|
||||
/**
|
||||
* Add an object file.
|
||||
*/
|
||||
LLVMOrcModuleHandle
|
||||
LLVMOrcAddObjectFile(LLVMOrcJITStackRef JITStack, LLVMObjectFileRef Obj,
|
||||
LLVMOrcModuleHandle LLVMOrcAddObjectFile(LLVMOrcJITStackRef JITStack,
|
||||
LLVMObjectFileRef Obj,
|
||||
LLVMOrcSymbolResolverFn SymbolResolver,
|
||||
void *SymbolResolverCtx);
|
||||
|
||||
|
@ -29,7 +29,6 @@ namespace orc {
|
||||
/// @brief Target-independent base class for compile callback management.
|
||||
class JITCompileCallbackManager {
|
||||
public:
|
||||
|
||||
typedef std::function<TargetAddress()> CompileFtor;
|
||||
|
||||
/// @brief Handle to a newly created compile callback. Can be used to get an
|
||||
@ -44,6 +43,7 @@ public:
|
||||
void setCompileAction(CompileFtor Compile) {
|
||||
this->Compile = std::move(Compile);
|
||||
}
|
||||
|
||||
private:
|
||||
TargetAddress Addr;
|
||||
CompileFtor &Compile;
|
||||
@ -69,8 +69,10 @@ public:
|
||||
// Found a callback handler. Yank this trampoline out of the active list and
|
||||
// put it back in the available trampolines list, then try to run the
|
||||
// handler's compile and update actions.
|
||||
// Moving the trampoline ID back to the available list first means there's at
|
||||
// least one available trampoline if the compile action triggers a request for
|
||||
// Moving the trampoline ID back to the available list first means there's
|
||||
// at
|
||||
// least one available trampoline if the compile action triggers a request
|
||||
// for
|
||||
// a new one.
|
||||
auto Compile = std::move(I->second);
|
||||
ActiveTrampolines.erase(I);
|
||||
@ -116,7 +118,6 @@ protected:
|
||||
std::vector<TargetAddress> AvailableTrampolines;
|
||||
|
||||
private:
|
||||
|
||||
TargetAddress getAvailableTrampolineAddr() {
|
||||
if (this->AvailableTrampolines.empty())
|
||||
grow();
|
||||
@ -137,7 +138,6 @@ private:
|
||||
template <typename TargetT>
|
||||
class LocalJITCompileCallbackManager : public JITCompileCallbackManager {
|
||||
public:
|
||||
|
||||
/// @brief Construct a InProcessJITCompileCallbackManager.
|
||||
/// @param ErrorHandlerAddress The address of an error handler in the target
|
||||
/// process to be used if a compile callback fails.
|
||||
@ -146,11 +146,9 @@ public:
|
||||
|
||||
/// Set up the resolver block.
|
||||
std::error_code EC;
|
||||
ResolverBlock =
|
||||
sys::OwningMemoryBlock(
|
||||
sys::Memory::allocateMappedMemory(TargetT::ResolverCodeSize, nullptr,
|
||||
sys::Memory::MF_READ |
|
||||
sys::Memory::MF_WRITE, EC));
|
||||
ResolverBlock = sys::OwningMemoryBlock(sys::Memory::allocateMappedMemory(
|
||||
TargetT::ResolverCodeSize, nullptr,
|
||||
sys::Memory::MF_READ | sys::Memory::MF_WRITE, EC));
|
||||
assert(!EC && "Failed to allocate resolver block");
|
||||
|
||||
TargetT::writeResolverCode(static_cast<uint8_t *>(ResolverBlock.base()),
|
||||
@ -163,13 +161,11 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
static TargetAddress reenter(void *CCMgr, void *TrampolineId) {
|
||||
JITCompileCallbackManager *Mgr =
|
||||
static_cast<JITCompileCallbackManager *>(CCMgr);
|
||||
return Mgr->executeCompileCallback(
|
||||
static_cast<TargetAddress>(
|
||||
reinterpret_cast<uintptr_t>(TrampolineId)));
|
||||
static_cast<TargetAddress>(reinterpret_cast<uintptr_t>(TrampolineId)));
|
||||
}
|
||||
|
||||
void grow() override {
|
||||
@ -177,13 +173,11 @@ private:
|
||||
|
||||
std::error_code EC;
|
||||
auto TrampolineBlock =
|
||||
sys::OwningMemoryBlock(
|
||||
sys::Memory::allocateMappedMemory(sys::Process::getPageSize(), nullptr,
|
||||
sys::Memory::MF_READ |
|
||||
sys::Memory::MF_WRITE, EC));
|
||||
sys::OwningMemoryBlock(sys::Memory::allocateMappedMemory(
|
||||
sys::Process::getPageSize(), nullptr,
|
||||
sys::Memory::MF_READ | sys::Memory::MF_WRITE, EC));
|
||||
assert(!EC && "Failed to allocate trampoline block");
|
||||
|
||||
|
||||
unsigned NumTrampolines =
|
||||
(sys::Process::getPageSize() - TargetT::PointerSize) /
|
||||
TargetT::TrampolineSize;
|
||||
@ -212,7 +206,6 @@ private:
|
||||
/// @brief Base class for managing collections of named indirect stubs.
|
||||
class IndirectStubsManager {
|
||||
public:
|
||||
|
||||
/// @brief Map type for initializing the manager. See init.
|
||||
typedef StringMap<std::pair<TargetAddress, JITSymbolFlags>> StubInitsMap;
|
||||
|
||||
@ -236,6 +229,7 @@ public:
|
||||
|
||||
/// @brief Change the value of the implementation pointer for the stub.
|
||||
virtual Error updatePointer(StringRef Name, TargetAddress NewAddr) = 0;
|
||||
|
||||
private:
|
||||
virtual void anchor();
|
||||
};
|
||||
@ -245,7 +239,6 @@ private:
|
||||
template <typename TargetT>
|
||||
class LocalIndirectStubsManager : public IndirectStubsManager {
|
||||
public:
|
||||
|
||||
Error createStub(StringRef StubName, TargetAddress StubAddr,
|
||||
JITSymbolFlags StubFlags) override {
|
||||
if (auto Err = reserveStubs(1))
|
||||
@ -304,7 +297,6 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
Error reserveStubs(unsigned NumStubs) {
|
||||
if (NumStubs <= FreeStubs.size())
|
||||
return Error::success();
|
||||
@ -312,8 +304,8 @@ private:
|
||||
unsigned NewStubsRequired = NumStubs - FreeStubs.size();
|
||||
unsigned NewBlockId = IndirectStubsInfos.size();
|
||||
typename TargetT::IndirectStubsInfo ISI;
|
||||
if (auto Err = TargetT::emitIndirectStubsBlock(ISI, NewStubsRequired,
|
||||
nullptr))
|
||||
if (auto Err =
|
||||
TargetT::emitIndirectStubsBlock(ISI, NewStubsRequired, nullptr))
|
||||
return Err;
|
||||
for (unsigned I = 0; I < ISI.getNumStubs(); ++I)
|
||||
FreeStubs.push_back(std::make_pair(NewBlockId, I));
|
||||
@ -345,8 +337,8 @@ Constant* createIRTypedAddress(FunctionType &FT, TargetAddress Addr);
|
||||
|
||||
/// @brief Create a function pointer with the given type, name, and initializer
|
||||
/// in the given Module.
|
||||
GlobalVariable* createImplPointer(PointerType &PT, Module &M,
|
||||
const Twine &Name, Constant *Initializer);
|
||||
GlobalVariable *createImplPointer(PointerType &PT, Module &M, const Twine &Name,
|
||||
Constant *Initializer);
|
||||
|
||||
/// @brief Turn a function declaration into a stub function that makes an
|
||||
/// indirect call using the given function pointer.
|
||||
|
@ -33,14 +33,14 @@ public:
|
||||
const char *getSrc() const { return Src; }
|
||||
TargetAddress getDst() const { return Dst; }
|
||||
uint64_t getSize() const { return Size; }
|
||||
|
||||
private:
|
||||
const char *Src;
|
||||
TargetAddress Dst;
|
||||
uint64_t Size;
|
||||
};
|
||||
|
||||
inline Error serialize(RPCChannel &C,
|
||||
const DirectBufferWriter &DBW) {
|
||||
inline Error serialize(RPCChannel &C, const DirectBufferWriter &DBW) {
|
||||
if (auto EC = serialize(C, DBW.getDst()))
|
||||
return EC;
|
||||
if (auto EC = serialize(C, DBW.getSize()))
|
||||
@ -48,8 +48,7 @@ inline Error serialize(RPCChannel &C,
|
||||
return C.appendBytes(DBW.getSrc(), DBW.getSize());
|
||||
}
|
||||
|
||||
inline Error deserialize(RPCChannel &C,
|
||||
DirectBufferWriter &DBW) {
|
||||
inline Error deserialize(RPCChannel &C, DirectBufferWriter &DBW) {
|
||||
TargetAddress Dst;
|
||||
if (auto EC = deserialize(C, Dst))
|
||||
return EC;
|
||||
@ -65,7 +64,6 @@ inline Error deserialize(RPCChannel &C,
|
||||
|
||||
class OrcRemoteTargetRPCAPI : public RPC<RPCChannel> {
|
||||
protected:
|
||||
|
||||
class ResourceIdMgr {
|
||||
public:
|
||||
typedef uint64_t ResourceId;
|
||||
@ -87,16 +85,13 @@ protected:
|
||||
};
|
||||
|
||||
public:
|
||||
|
||||
// FIXME: Remove constructors once MSVC supports synthesizing move-ops.
|
||||
OrcRemoteTargetRPCAPI() = default;
|
||||
OrcRemoteTargetRPCAPI(const OrcRemoteTargetRPCAPI &) = delete;
|
||||
OrcRemoteTargetRPCAPI &operator=(const OrcRemoteTargetRPCAPI &) = delete;
|
||||
|
||||
OrcRemoteTargetRPCAPI(OrcRemoteTargetRPCAPI &&) {}
|
||||
OrcRemoteTargetRPCAPI& operator=(OrcRemoteTargetRPCAPI&&) {
|
||||
return *this;
|
||||
}
|
||||
OrcRemoteTargetRPCAPI &operator=(OrcRemoteTargetRPCAPI &&) { return *this; }
|
||||
|
||||
enum JITFuncId : uint32_t {
|
||||
InvalidId = RPCFunctionIdTraits<JITFuncId>::InvalidId,
|
||||
@ -127,8 +122,8 @@ public:
|
||||
|
||||
typedef Function<CallIntVoidId, int32_t(TargetAddress Addr)> CallIntVoid;
|
||||
|
||||
typedef Function<CallMainId, int32_t(TargetAddress Addr,
|
||||
std::vector<std::string> Args)>
|
||||
typedef Function<CallMainId,
|
||||
int32_t(TargetAddress Addr, std::vector<std::string> Args)>
|
||||
CallMain;
|
||||
|
||||
typedef Function<CallVoidVoidId, void(TargetAddress FnAddr)> CallVoidVoid;
|
||||
@ -163,24 +158,23 @@ public:
|
||||
typedef Function<EmitResolverBlockId, void()> EmitResolverBlock;
|
||||
|
||||
/// EmitTrampolineBlock result is (BlockAddr, NumTrampolines).
|
||||
typedef Function<EmitTrampolineBlockId,
|
||||
std::tuple<TargetAddress, uint32_t>()> EmitTrampolineBlock;
|
||||
typedef Function<EmitTrampolineBlockId, std::tuple<TargetAddress, uint32_t>()>
|
||||
EmitTrampolineBlock;
|
||||
|
||||
typedef Function<GetSymbolAddressId, TargetAddress(std::string SymbolName)>
|
||||
GetSymbolAddress;
|
||||
|
||||
/// GetRemoteInfo result is (Triple, PointerSize, PageSize, TrampolineSize,
|
||||
/// IndirectStubsSize).
|
||||
typedef Function<GetRemoteInfoId,
|
||||
std::tuple<std::string, uint32_t, uint32_t, uint32_t,
|
||||
uint32_t>()> GetRemoteInfo;
|
||||
typedef Function<GetRemoteInfoId, std::tuple<std::string, uint32_t, uint32_t,
|
||||
uint32_t, uint32_t>()>
|
||||
GetRemoteInfo;
|
||||
|
||||
typedef Function<ReadMemId,
|
||||
std::vector<char>(TargetAddress Src, uint64_t Size)>
|
||||
ReadMem;
|
||||
|
||||
typedef Function<RegisterEHFramesId,
|
||||
void(TargetAddress Addr, uint32_t Size)>
|
||||
typedef Function<RegisterEHFramesId, void(TargetAddress Addr, uint32_t Size)>
|
||||
RegisterEHFrames;
|
||||
|
||||
typedef Function<ReserveMemId,
|
||||
@ -199,8 +193,7 @@ public:
|
||||
|
||||
typedef Function<TerminateSessionId, void()> TerminateSession;
|
||||
|
||||
typedef Function<WriteMemId, void(DirectBufferWriter DB)>
|
||||
WriteMem;
|
||||
typedef Function<WriteMemId, void(DirectBufferWriter DB)> WriteMem;
|
||||
|
||||
typedef Function<WritePtrId, void(TargetAddress Dst, TargetAddress Val)>
|
||||
WritePtr;
|
||||
|
@ -327,7 +327,6 @@ template <typename ChannelT, typename FunctionIdT = uint32_t,
|
||||
typename SequenceNumberT = uint16_t>
|
||||
class RPC : public RPCBase {
|
||||
public:
|
||||
|
||||
/// RPC default constructor.
|
||||
RPC() = default;
|
||||
|
||||
@ -445,7 +444,8 @@ public:
|
||||
/// The same as appendCallAsync, except that it calls C.send to flush the
|
||||
/// channel after serializing the call.
|
||||
template <typename Func, typename... ArgTs>
|
||||
Expected<AsyncCallResult<Func>> callAsync(ChannelT &C, const ArgTs &... Args) {
|
||||
Expected<AsyncCallResult<Func>> callAsync(ChannelT &C,
|
||||
const ArgTs &... Args) {
|
||||
auto ResAndSeqOrErr = callAsyncWithSeq<Func>(C, Args...);
|
||||
if (ResAndSeqOrErr)
|
||||
return std::move(ResAndSeqOrErr->first);
|
||||
|
@ -7,8 +7,8 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "llvm/ADT/Triple.h"
|
||||
#include "llvm/ExecutionEngine/Orc/OrcArchitectureSupport.h"
|
||||
#include "llvm/ADT/Triple.h"
|
||||
#include "llvm/Support/Process.h"
|
||||
|
||||
namespace llvm {
|
||||
@ -126,12 +126,9 @@ Error OrcX86_64::emitIndirectStubsBlock(IndirectStubsInfo &StubsInfo,
|
||||
|
||||
// Allocate memory for stubs and pointers in one call.
|
||||
std::error_code EC;
|
||||
auto StubsMem =
|
||||
sys::OwningMemoryBlock(
|
||||
sys::Memory::allocateMappedMemory(2 * NumPages * PageSize, nullptr,
|
||||
sys::Memory::MF_READ |
|
||||
sys::Memory::MF_WRITE,
|
||||
EC));
|
||||
auto StubsMem = sys::OwningMemoryBlock(sys::Memory::allocateMappedMemory(
|
||||
2 * NumPages * PageSize, nullptr,
|
||||
sys::Memory::MF_READ | sys::Memory::MF_WRITE, EC));
|
||||
|
||||
if (EC)
|
||||
return errorCodeToError(EC);
|
||||
@ -144,14 +141,13 @@ Error OrcX86_64::emitIndirectStubsBlock(IndirectStubsInfo &StubsInfo,
|
||||
|
||||
// Populate the stubs page stubs and mark it executable.
|
||||
uint64_t *Stub = reinterpret_cast<uint64_t *>(StubsBlock.base());
|
||||
uint64_t PtrOffsetField =
|
||||
static_cast<uint64_t>(NumPages * PageSize - 6) << 16;
|
||||
uint64_t PtrOffsetField = static_cast<uint64_t>(NumPages * PageSize - 6)
|
||||
<< 16;
|
||||
for (unsigned I = 0; I < NumStubs; ++I)
|
||||
Stub[I] = 0xF1C40000000025ff | PtrOffsetField;
|
||||
|
||||
if (auto EC = sys::Memory::protectMappedMemory(StubsBlock,
|
||||
sys::Memory::MF_READ |
|
||||
sys::Memory::MF_EXEC))
|
||||
if (auto EC = sys::Memory::protectMappedMemory(
|
||||
StubsBlock, sys::Memory::MF_READ | sys::Memory::MF_EXEC))
|
||||
return errorCodeToError(EC);
|
||||
|
||||
// Initialize all pointers to point at FailureAddress.
|
||||
@ -184,7 +180,8 @@ void OrcI386::writeResolverCode(uint8_t *ResolverMem, JITReentryFn ReentryFn,
|
||||
0x8b, 0x75, 0x04, // 0x18: movl 0x4(%ebp), %esi
|
||||
0x83, 0xee, 0x05, // 0x1b: subl $0x5, %esi
|
||||
0x89, 0x74, 0x24, 0x04, // 0x1e: movl %esi, 0x4(%esp)
|
||||
0xc7, 0x04, 0x24, 0x00, 0x00, 0x00, 0x00, // 0x22: movl <cbmgr>, (%esp)
|
||||
0xc7, 0x04, 0x24, 0x00, 0x00, 0x00,
|
||||
0x00, // 0x22: movl <cbmgr>, (%esp)
|
||||
0xb8, 0x00, 0x00, 0x00, 0x00, // 0x29: movl <reentry>, %eax
|
||||
0xff, 0xd0, // 0x2e: calll *%eax
|
||||
0x89, 0x45, 0x04, // 0x30: movl %eax, 0x4(%ebp)
|
||||
@ -224,8 +221,7 @@ void OrcI386::writeTrampolines(uint8_t *TrampolineMem, void *ResolverAddr,
|
||||
}
|
||||
|
||||
Error OrcI386::emitIndirectStubsBlock(IndirectStubsInfo &StubsInfo,
|
||||
unsigned MinStubs,
|
||||
void *InitialPtrVal) {
|
||||
unsigned MinStubs, void *InitialPtrVal) {
|
||||
// Stub format is:
|
||||
//
|
||||
// .section __orc_stubs
|
||||
@ -255,12 +251,9 @@ Error OrcI386::emitIndirectStubsBlock(IndirectStubsInfo &StubsInfo,
|
||||
|
||||
// Allocate memory for stubs and pointers in one call.
|
||||
std::error_code EC;
|
||||
auto StubsMem =
|
||||
sys::OwningMemoryBlock(
|
||||
sys::Memory::allocateMappedMemory(2 * NumPages * PageSize, nullptr,
|
||||
sys::Memory::MF_READ |
|
||||
sys::Memory::MF_WRITE,
|
||||
EC));
|
||||
auto StubsMem = sys::OwningMemoryBlock(sys::Memory::allocateMappedMemory(
|
||||
2 * NumPages * PageSize, nullptr,
|
||||
sys::Memory::MF_READ | sys::Memory::MF_WRITE, EC));
|
||||
|
||||
if (EC)
|
||||
return errorCodeToError(EC);
|
||||
@ -277,9 +270,8 @@ Error OrcI386::emitIndirectStubsBlock(IndirectStubsInfo &StubsInfo,
|
||||
for (unsigned I = 0; I < NumStubs; ++I, PtrAddr += 4)
|
||||
Stub[I] = 0xF1C40000000025ff | (PtrAddr << 16);
|
||||
|
||||
if (auto EC = sys::Memory::protectMappedMemory(StubsBlock,
|
||||
sys::Memory::MF_READ |
|
||||
sys::Memory::MF_EXEC))
|
||||
if (auto EC = sys::Memory::protectMappedMemory(
|
||||
StubsBlock, sys::Memory::MF_READ | sys::Memory::MF_EXEC))
|
||||
return errorCodeToError(EC);
|
||||
|
||||
// Initialize all pointers to point at FailureAddress.
|
||||
|
@ -21,9 +21,8 @@ LLVMOrcJITStackRef LLVMOrcCreateInstance(LLVMTargetMachineRef TM) {
|
||||
auto IndirectStubsMgrBuilder =
|
||||
OrcCBindingsStack::createIndirectStubsMgrBuilder(T);
|
||||
|
||||
OrcCBindingsStack *JITStack =
|
||||
new OrcCBindingsStack(*TM2, std::move(CompileCallbackMgr),
|
||||
IndirectStubsMgrBuilder);
|
||||
OrcCBindingsStack *JITStack = new OrcCBindingsStack(
|
||||
*TM2, std::move(CompileCallbackMgr), IndirectStubsMgrBuilder);
|
||||
|
||||
return wrap(JITStack);
|
||||
}
|
||||
@ -41,9 +40,7 @@ void LLVMOrcGetMangledSymbol(LLVMOrcJITStackRef JITStack, char **MangledName,
|
||||
strcpy(*MangledName, Mangled.c_str());
|
||||
}
|
||||
|
||||
void LLVMOrcDisposeMangledSymbol(char *MangledName) {
|
||||
delete[] MangledName;
|
||||
}
|
||||
void LLVMOrcDisposeMangledSymbol(char *MangledName) { delete[] MangledName; }
|
||||
|
||||
LLVMOrcTargetAddress
|
||||
LLVMOrcCreateLazyCompileCallback(LLVMOrcJITStackRef JITStack,
|
||||
|
@ -20,7 +20,8 @@ using namespace llvm;
|
||||
std::unique_ptr<OrcCBindingsStack::CompileCallbackMgr>
|
||||
OrcCBindingsStack::createCompileCallbackMgr(Triple T) {
|
||||
switch (T.getArch()) {
|
||||
default: return nullptr;
|
||||
default:
|
||||
return nullptr;
|
||||
|
||||
case Triple::x86: {
|
||||
typedef orc::LocalJITCompileCallbackManager<orc::OrcI386> CCMgrT;
|
||||
@ -37,12 +38,12 @@ OrcCBindingsStack::createCompileCallbackMgr(Triple T) {
|
||||
OrcCBindingsStack::IndirectStubsManagerBuilder
|
||||
OrcCBindingsStack::createIndirectStubsMgrBuilder(Triple T) {
|
||||
switch (T.getArch()) {
|
||||
default: return nullptr;
|
||||
default:
|
||||
return nullptr;
|
||||
|
||||
case Triple::x86:
|
||||
return []() {
|
||||
return llvm::make_unique<
|
||||
orc::LocalIndirectStubsManager<orc::OrcI386>>();
|
||||
return llvm::make_unique<orc::LocalIndirectStubsManager<orc::OrcI386>>();
|
||||
};
|
||||
|
||||
case Triple::x86_64:
|
||||
|
@ -10,6 +10,7 @@
|
||||
#ifndef LLVM_LIB_EXECUTIONENGINE_ORC_ORCCBINDINGSSTACK_H
|
||||
#define LLVM_LIB_EXECUTIONENGINE_ORC_ORCCBINDINGSSTACK_H
|
||||
|
||||
#include "llvm-c/OrcBindings.h"
|
||||
#include "llvm/ADT/Triple.h"
|
||||
#include "llvm/ExecutionEngine/Orc/CompileOnDemandLayer.h"
|
||||
#include "llvm/ExecutionEngine/Orc/CompileUtils.h"
|
||||
@ -18,7 +19,6 @@
|
||||
#include "llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h"
|
||||
#include "llvm/IR/LLVMContext.h"
|
||||
#include "llvm/Support/Error.h"
|
||||
#include "llvm-c/OrcBindings.h"
|
||||
|
||||
namespace llvm {
|
||||
|
||||
@ -29,11 +29,11 @@ DEFINE_SIMPLE_CONVERSION_FUNCTIONS(TargetMachine, LLVMTargetMachineRef)
|
||||
|
||||
class OrcCBindingsStack {
|
||||
public:
|
||||
|
||||
typedef orc::JITCompileCallbackManager CompileCallbackMgr;
|
||||
typedef orc::ObjectLinkingLayer<> ObjLayerT;
|
||||
typedef orc::IRCompileLayer<ObjLayerT> CompileLayerT;
|
||||
typedef orc::CompileOnDemandLayer<CompileLayerT, CompileCallbackMgr> CODLayerT;
|
||||
typedef orc::CompileOnDemandLayer<CompileLayerT, CompileCallbackMgr>
|
||||
CODLayerT;
|
||||
|
||||
typedef std::function<std::unique_ptr<CompileCallbackMgr>()>
|
||||
CallbackManagerBuilder;
|
||||
@ -41,7 +41,6 @@ public:
|
||||
typedef CODLayerT::IndirectStubsManagerBuilderT IndirectStubsManagerBuilder;
|
||||
|
||||
private:
|
||||
|
||||
class GenericHandle {
|
||||
public:
|
||||
virtual ~GenericHandle() {}
|
||||
@ -50,8 +49,7 @@ private:
|
||||
virtual void removeModule() = 0;
|
||||
};
|
||||
|
||||
template <typename LayerT>
|
||||
class GenericHandleImpl : public GenericHandle {
|
||||
template <typename LayerT> class GenericHandleImpl : public GenericHandle {
|
||||
public:
|
||||
GenericHandleImpl(LayerT &Layer, typename LayerT::ModuleSetHandleT Handle)
|
||||
: Layer(Layer), Handle(std::move(Handle)) {}
|
||||
@ -61,9 +59,7 @@ private:
|
||||
return Layer.findSymbolIn(Handle, Name, ExportedSymbolsOnly);
|
||||
}
|
||||
|
||||
void removeModule() override {
|
||||
return Layer.removeModuleSet(Handle);
|
||||
}
|
||||
void removeModule() override { return Layer.removeModuleSet(Handle); }
|
||||
|
||||
private:
|
||||
LayerT &Layer;
|
||||
@ -78,7 +74,6 @@ private:
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
// We need a 'ModuleSetHandleT' to conform to the layer concept.
|
||||
typedef unsigned ModuleSetHandleT;
|
||||
|
||||
@ -125,22 +120,20 @@ public:
|
||||
createLazyCompileCallback(LLVMOrcLazyCompileCallbackFn Callback,
|
||||
void *CallbackCtx) {
|
||||
auto CCInfo = CCMgr->getCompileCallback();
|
||||
CCInfo.setCompileAction(
|
||||
[=]() -> orc::TargetAddress {
|
||||
CCInfo.setCompileAction([=]() -> orc::TargetAddress {
|
||||
return Callback(wrap(this), CallbackCtx);
|
||||
});
|
||||
return CCInfo.getAddress();
|
||||
}
|
||||
|
||||
LLVMOrcErrorCode
|
||||
createIndirectStub(StringRef StubName, orc::TargetAddress Addr) {
|
||||
LLVMOrcErrorCode createIndirectStub(StringRef StubName,
|
||||
orc::TargetAddress Addr) {
|
||||
return mapError(
|
||||
IndirectStubsMgr->createStub(StubName, Addr,
|
||||
JITSymbolFlags::Exported));
|
||||
IndirectStubsMgr->createStub(StubName, Addr, JITSymbolFlags::Exported));
|
||||
}
|
||||
|
||||
LLVMOrcErrorCode
|
||||
setIndirectStubPointer(StringRef Name, orc::TargetAddress Addr) {
|
||||
LLVMOrcErrorCode setIndirectStubPointer(StringRef Name,
|
||||
orc::TargetAddress Addr) {
|
||||
return mapError(IndirectStubsMgr->updatePointer(Name, Addr));
|
||||
}
|
||||
|
||||
@ -155,29 +148,26 @@ public:
|
||||
// 3. External resolver (if present).
|
||||
|
||||
if (auto Sym = CODLayer.findSymbol(Name, true))
|
||||
return RuntimeDyld::SymbolInfo(Sym.getAddress(),
|
||||
Sym.getFlags());
|
||||
return RuntimeDyld::SymbolInfo(Sym.getAddress(), Sym.getFlags());
|
||||
if (auto Sym = CXXRuntimeOverrides.searchOverrides(Name))
|
||||
return Sym;
|
||||
|
||||
if (ExternalResolver)
|
||||
return RuntimeDyld::SymbolInfo(ExternalResolver(Name.c_str(),
|
||||
ExternalResolverCtx),
|
||||
return RuntimeDyld::SymbolInfo(
|
||||
ExternalResolver(Name.c_str(), ExternalResolverCtx),
|
||||
llvm::JITSymbolFlags::Exported);
|
||||
|
||||
return RuntimeDyld::SymbolInfo(nullptr);
|
||||
},
|
||||
[](const std::string &Name) {
|
||||
return RuntimeDyld::SymbolInfo(nullptr);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
return std::shared_ptr<RuntimeDyld::SymbolResolver>(std::move(Resolver));
|
||||
}
|
||||
|
||||
template <typename LayerT>
|
||||
ModuleHandleT addIRModule(LayerT &Layer,
|
||||
Module *M,
|
||||
ModuleHandleT addIRModule(LayerT &Layer, Module *M,
|
||||
std::unique_ptr<RuntimeDyld::MemoryManager> MemMgr,
|
||||
LLVMOrcSymbolResolverFn ExternalResolver,
|
||||
void *ExternalResolverCtx) {
|
||||
@ -248,12 +238,9 @@ public:
|
||||
return GenericHandles[H]->findSymbolIn(Name, ExportedSymbolsOnly);
|
||||
}
|
||||
|
||||
const std::string& getErrorMessage() const {
|
||||
return ErrMsg;
|
||||
}
|
||||
const std::string &getErrorMessage() const { return ErrMsg; }
|
||||
|
||||
private:
|
||||
|
||||
template <typename LayerT>
|
||||
unsigned createHandle(LayerT &Layer,
|
||||
typename LayerT::ModuleSetHandleT Handle) {
|
||||
@ -272,8 +259,7 @@ private:
|
||||
|
||||
LLVMOrcErrorCode mapError(Error Err) {
|
||||
LLVMOrcErrorCode Result = LLVMOrcErrSuccess;
|
||||
handleAllErrors(std::move(Err),
|
||||
[&](ErrorInfoBase &EIB) {
|
||||
handleAllErrors(std::move(Err), [&](ErrorInfoBase &EIB) {
|
||||
// Handler of last resort.
|
||||
Result = LLVMOrcErrGeneric;
|
||||
ErrMsg = "";
|
||||
|
@ -53,8 +53,8 @@ namespace orc {
|
||||
|
||||
Error orcError(OrcErrorCode ErrCode) {
|
||||
typedef std::underlying_type<OrcErrorCode>::type UT;
|
||||
return errorCodeToError(std::error_code(static_cast<UT>(ErrCode),
|
||||
*OrcErrCat));
|
||||
return errorCodeToError(
|
||||
std::error_code(static_cast<UT>(ErrCode), *OrcErrCat));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,7 @@ namespace {
|
||||
class DummyCallbackManager : public orc::JITCompileCallbackManager {
|
||||
public:
|
||||
DummyCallbackManager() : JITCompileCallbackManager(0) {}
|
||||
|
||||
public:
|
||||
void grow() override { llvm_unreachable("not implemented"); }
|
||||
};
|
||||
@ -42,16 +43,14 @@ public:
|
||||
llvm_unreachable("Not implemented");
|
||||
}
|
||||
|
||||
Error updatePointer(StringRef Name,
|
||||
TargetAddress NewAddr) override {
|
||||
Error updatePointer(StringRef Name, TargetAddress NewAddr) override {
|
||||
llvm_unreachable("Not implemented");
|
||||
}
|
||||
};
|
||||
|
||||
TEST(CompileOnDemandLayerTest, FindSymbol) {
|
||||
auto MockBaseLayer =
|
||||
createMockBaseLayer<int>(DoNothingAndReturn<int>(0),
|
||||
DoNothingAndReturn<void>(),
|
||||
auto MockBaseLayer = createMockBaseLayer<int>(
|
||||
DoNothingAndReturn<int>(0), DoNothingAndReturn<void>(),
|
||||
[](const std::string &Name, bool) {
|
||||
if (Name == "foo")
|
||||
return JITSymbol(1, JITSymbolFlags::Exported);
|
||||
@ -68,8 +67,7 @@ TEST(CompileOnDemandLayerTest, FindSymbol) {
|
||||
|
||||
auto Sym = COD.findSymbol("foo", true);
|
||||
|
||||
EXPECT_TRUE(!!Sym)
|
||||
<< "CompileOnDemand::findSymbol should call findSymbol in the base layer.";
|
||||
EXPECT_TRUE(!!Sym) << "CompileOnDemand::findSymbol should call findSymbol in "
|
||||
"the base layer.";
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -20,6 +20,7 @@ using namespace llvm::orc::remote;
|
||||
class Queue : public std::queue<char> {
|
||||
public:
|
||||
std::mutex &getLock() { return Lock; }
|
||||
|
||||
private:
|
||||
std::mutex Lock;
|
||||
};
|
||||
@ -60,10 +61,8 @@ private:
|
||||
Queue &OutQueue;
|
||||
};
|
||||
|
||||
class DummyRPC : public testing::Test,
|
||||
public RPC<QueueChannel> {
|
||||
class DummyRPC : public testing::Test, public RPC<QueueChannel> {
|
||||
public:
|
||||
|
||||
enum FuncId : uint32_t {
|
||||
VoidBoolId = RPCFunctionIdTraits<FuncId>::FirstValidId,
|
||||
IntIntId,
|
||||
@ -72,14 +71,12 @@ public:
|
||||
|
||||
typedef Function<VoidBoolId, void(bool)> VoidBool;
|
||||
typedef Function<IntIntId, int32_t(int32_t)> IntInt;
|
||||
typedef Function<AllTheTypesId, void(int8_t, uint8_t, int16_t, uint16_t,
|
||||
int32_t, uint32_t, int64_t, uint64_t,
|
||||
bool, std::string, std::vector<int>)>
|
||||
typedef Function<AllTheTypesId,
|
||||
void(int8_t, uint8_t, int16_t, uint16_t, int32_t, uint32_t,
|
||||
int64_t, uint64_t, bool, std::string, std::vector<int>)>
|
||||
AllTheTypes;
|
||||
|
||||
};
|
||||
|
||||
|
||||
TEST_F(DummyRPC, TestAsyncVoidBool) {
|
||||
Queue Q1, Q2;
|
||||
QueueChannel C1(Q1, Q2);
|
||||
@ -91,10 +88,8 @@ TEST_F(DummyRPC, TestAsyncVoidBool) {
|
||||
|
||||
{
|
||||
// Expect a call to Proc1.
|
||||
auto EC = expect<VoidBool>(C2,
|
||||
[&](bool &B) {
|
||||
EXPECT_EQ(B, true)
|
||||
<< "Bool serialization broken";
|
||||
auto EC = expect<VoidBool>(C2, [&](bool &B) {
|
||||
EXPECT_EQ(B, true) << "Bool serialization broken";
|
||||
return Error::success();
|
||||
});
|
||||
EXPECT_FALSE(EC) << "Simple expect over queue failed";
|
||||
@ -122,10 +117,8 @@ TEST_F(DummyRPC, TestAsyncIntInt) {
|
||||
|
||||
{
|
||||
// Expect a call to Proc1.
|
||||
auto EC = expect<IntInt>(C2,
|
||||
[&](int32_t I) -> Expected<int32_t> {
|
||||
EXPECT_EQ(I, 21)
|
||||
<< "Bool serialization broken";
|
||||
auto EC = expect<IntInt>(C2, [&](int32_t I) -> Expected<int32_t> {
|
||||
EXPECT_EQ(I, 21) << "Bool serialization broken";
|
||||
return 2 * I;
|
||||
});
|
||||
EXPECT_FALSE(EC) << "Simple expect over queue failed";
|
||||
@ -150,56 +143,28 @@ TEST_F(DummyRPC, TestSerialization) {
|
||||
|
||||
// Make a call to Proc1.
|
||||
std::vector<int> v({42, 7});
|
||||
auto ResOrErr = callAsyncWithSeq<AllTheTypes>(C1,
|
||||
-101,
|
||||
250,
|
||||
-10000,
|
||||
10000,
|
||||
-1000000000,
|
||||
1000000000,
|
||||
-10000000000,
|
||||
10000000000,
|
||||
true,
|
||||
"foo",
|
||||
v);
|
||||
EXPECT_TRUE(!!ResOrErr)
|
||||
<< "Big (serialization test) call over queue failed";
|
||||
auto ResOrErr = callAsyncWithSeq<AllTheTypes>(
|
||||
C1, -101, 250, -10000, 10000, -1000000000, 1000000000, -10000000000,
|
||||
10000000000, true, "foo", v);
|
||||
EXPECT_TRUE(!!ResOrErr) << "Big (serialization test) call over queue failed";
|
||||
|
||||
{
|
||||
// Expect a call to Proc1.
|
||||
auto EC = expect<AllTheTypes>(C2,
|
||||
[&](int8_t &s8,
|
||||
uint8_t &u8,
|
||||
int16_t &s16,
|
||||
uint16_t &u16,
|
||||
int32_t &s32,
|
||||
uint32_t &u32,
|
||||
int64_t &s64,
|
||||
uint64_t &u64,
|
||||
bool &b,
|
||||
std::string &s,
|
||||
std::vector<int> &v) {
|
||||
auto EC = expect<AllTheTypes>(
|
||||
C2, [&](int8_t &s8, uint8_t &u8, int16_t &s16, uint16_t &u16,
|
||||
int32_t &s32, uint32_t &u32, int64_t &s64, uint64_t &u64,
|
||||
bool &b, std::string &s, std::vector<int> &v) {
|
||||
|
||||
EXPECT_EQ(s8, -101)
|
||||
<< "int8_t serialization broken";
|
||||
EXPECT_EQ(u8, 250)
|
||||
<< "uint8_t serialization broken";
|
||||
EXPECT_EQ(s16, -10000)
|
||||
<< "int16_t serialization broken";
|
||||
EXPECT_EQ(u16, 10000)
|
||||
<< "uint16_t serialization broken";
|
||||
EXPECT_EQ(s32, -1000000000)
|
||||
<< "int32_t serialization broken";
|
||||
EXPECT_EQ(u32, 1000000000ULL)
|
||||
<< "uint32_t serialization broken";
|
||||
EXPECT_EQ(s64, -10000000000)
|
||||
<< "int64_t serialization broken";
|
||||
EXPECT_EQ(u64, 10000000000ULL)
|
||||
<< "uint64_t serialization broken";
|
||||
EXPECT_EQ(b, true)
|
||||
<< "bool serialization broken";
|
||||
EXPECT_EQ(s, "foo")
|
||||
<< "std::string serialization broken";
|
||||
EXPECT_EQ(s8, -101) << "int8_t serialization broken";
|
||||
EXPECT_EQ(u8, 250) << "uint8_t serialization broken";
|
||||
EXPECT_EQ(s16, -10000) << "int16_t serialization broken";
|
||||
EXPECT_EQ(u16, 10000) << "uint16_t serialization broken";
|
||||
EXPECT_EQ(s32, -1000000000) << "int32_t serialization broken";
|
||||
EXPECT_EQ(u32, 1000000000ULL) << "uint32_t serialization broken";
|
||||
EXPECT_EQ(s64, -10000000000) << "int64_t serialization broken";
|
||||
EXPECT_EQ(u64, 10000000000ULL) << "uint64_t serialization broken";
|
||||
EXPECT_EQ(b, true) << "bool serialization broken";
|
||||
EXPECT_EQ(s, "foo") << "std::string serialization broken";
|
||||
EXPECT_EQ(v, std::vector<int>({42, 7}))
|
||||
<< "std::vector serialization broken";
|
||||
return Error::success();
|
||||
|
Loading…
Reference in New Issue
Block a user