diff options
Diffstat (limited to 'llvm/lib/ExecutionEngine')
-rw-r--r-- | llvm/lib/ExecutionEngine/Orc/OrcArchitectureSupport.cpp | 230 | ||||
-rw-r--r-- | llvm/lib/ExecutionEngine/Orc/OrcCBindings.cpp | 11 | ||||
-rw-r--r-- | llvm/lib/ExecutionEngine/Orc/OrcCBindingsStack.cpp | 45 | ||||
-rw-r--r-- | llvm/lib/ExecutionEngine/Orc/OrcCBindingsStack.h | 112 | ||||
-rw-r--r-- | llvm/lib/ExecutionEngine/Orc/OrcError.cpp | 4 |
5 files changed, 189 insertions, 213 deletions
diff --git a/llvm/lib/ExecutionEngine/Orc/OrcArchitectureSupport.cpp b/llvm/lib/ExecutionEngine/Orc/OrcArchitectureSupport.cpp index 4095a3b98ee..b51e3cd002d 100644 --- a/llvm/lib/ExecutionEngine/Orc/OrcArchitectureSupport.cpp +++ b/llvm/lib/ExecutionEngine/Orc/OrcArchitectureSupport.cpp @@ -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 { @@ -18,62 +18,62 @@ void OrcX86_64::writeResolverCode(uint8_t *ResolverMem, JITReentryFn ReentryFn, void *CallbackMgr) { const uint8_t ResolverCode[] = { - // resolver_entry: - 0x55, // 0x00: pushq %rbp - 0x48, 0x89, 0xe5, // 0x01: movq %rsp, %rbp - 0x50, // 0x04: pushq %rax - 0x53, // 0x05: pushq %rbx - 0x51, // 0x06: pushq %rcx - 0x52, // 0x07: pushq %rdx - 0x56, // 0x08: pushq %rsi - 0x57, // 0x09: pushq %rdi - 0x41, 0x50, // 0x0a: pushq %r8 - 0x41, 0x51, // 0x0c: pushq %r9 - 0x41, 0x52, // 0x0e: pushq %r10 - 0x41, 0x53, // 0x10: pushq %r11 - 0x41, 0x54, // 0x12: pushq %r12 - 0x41, 0x55, // 0x14: pushq %r13 - 0x41, 0x56, // 0x16: pushq %r14 - 0x41, 0x57, // 0x18: pushq %r15 - 0x48, 0x81, 0xec, 0x08, 0x02, 0x00, 0x00, // 0x1a: subq 0x208, %rsp - 0x48, 0x0f, 0xae, 0x04, 0x24, // 0x21: fxsave64 (%rsp) - 0x48, 0xbf, // 0x26: movabsq <CBMgr>, %rdi - - // 0x28: Callback manager addr. - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - - 0x48, 0x8b, 0x75, 0x08, // 0x30: movq 8(%rbp), %rsi - 0x48, 0x83, 0xee, 0x06, // 0x34: subq $6, %rsi - 0x48, 0xb8, // 0x38: movabsq <REntry>, %rax - - // 0x3a: JIT re-entry fn addr: - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - - 0xff, 0xd0, // 0x42: callq *%rax - 0x48, 0x89, 0x45, 0x08, // 0x44: movq %rax, 8(%rbp) - 0x48, 0x0f, 0xae, 0x0c, 0x24, // 0x48: fxrstor64 (%rsp) - 0x48, 0x81, 0xc4, 0x08, 0x02, 0x00, 0x00, // 0x4d: addq 0x208, %rsp - 0x41, 0x5f, // 0x54: popq %r15 - 0x41, 0x5e, // 0x56: popq %r14 - 0x41, 0x5d, // 0x58: popq %r13 - 0x41, 0x5c, // 0x5a: popq %r12 - 0x41, 0x5b, // 0x5c: popq %r11 - 0x41, 0x5a, // 0x5e: popq %r10 - 0x41, 0x59, // 0x60: popq %r9 - 0x41, 0x58, // 0x62: popq %r8 - 0x5f, // 0x64: popq %rdi - 0x5e, // 0x65: popq %rsi - 0x5a, // 0x66: popq %rdx - 0x59, // 0x67: popq %rcx - 0x5b, // 0x68: popq %rbx - 0x58, // 0x69: popq %rax - 0x5d, // 0x6a: popq %rbp - 0xc3, // 0x6b: retq + // resolver_entry: + 0x55, // 0x00: pushq %rbp + 0x48, 0x89, 0xe5, // 0x01: movq %rsp, %rbp + 0x50, // 0x04: pushq %rax + 0x53, // 0x05: pushq %rbx + 0x51, // 0x06: pushq %rcx + 0x52, // 0x07: pushq %rdx + 0x56, // 0x08: pushq %rsi + 0x57, // 0x09: pushq %rdi + 0x41, 0x50, // 0x0a: pushq %r8 + 0x41, 0x51, // 0x0c: pushq %r9 + 0x41, 0x52, // 0x0e: pushq %r10 + 0x41, 0x53, // 0x10: pushq %r11 + 0x41, 0x54, // 0x12: pushq %r12 + 0x41, 0x55, // 0x14: pushq %r13 + 0x41, 0x56, // 0x16: pushq %r14 + 0x41, 0x57, // 0x18: pushq %r15 + 0x48, 0x81, 0xec, 0x08, 0x02, 0x00, 0x00, // 0x1a: subq 0x208, %rsp + 0x48, 0x0f, 0xae, 0x04, 0x24, // 0x21: fxsave64 (%rsp) + 0x48, 0xbf, // 0x26: movabsq <CBMgr>, %rdi + + // 0x28: Callback manager addr. + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + + 0x48, 0x8b, 0x75, 0x08, // 0x30: movq 8(%rbp), %rsi + 0x48, 0x83, 0xee, 0x06, // 0x34: subq $6, %rsi + 0x48, 0xb8, // 0x38: movabsq <REntry>, %rax + + // 0x3a: JIT re-entry fn addr: + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + + 0xff, 0xd0, // 0x42: callq *%rax + 0x48, 0x89, 0x45, 0x08, // 0x44: movq %rax, 8(%rbp) + 0x48, 0x0f, 0xae, 0x0c, 0x24, // 0x48: fxrstor64 (%rsp) + 0x48, 0x81, 0xc4, 0x08, 0x02, 0x00, 0x00, // 0x4d: addq 0x208, %rsp + 0x41, 0x5f, // 0x54: popq %r15 + 0x41, 0x5e, // 0x56: popq %r14 + 0x41, 0x5d, // 0x58: popq %r13 + 0x41, 0x5c, // 0x5a: popq %r12 + 0x41, 0x5b, // 0x5c: popq %r11 + 0x41, 0x5a, // 0x5e: popq %r10 + 0x41, 0x59, // 0x60: popq %r9 + 0x41, 0x58, // 0x62: popq %r8 + 0x5f, // 0x64: popq %rdi + 0x5e, // 0x65: popq %rsi + 0x5a, // 0x66: popq %rdx + 0x59, // 0x67: popq %rcx + 0x5b, // 0x68: popq %rbx + 0x58, // 0x69: popq %rax + 0x5d, // 0x6a: popq %rbp + 0xc3, // 0x6b: retq }; const unsigned ReentryFnAddrOffset = 0x3a; const unsigned CallbackMgrAddrOffset = 0x28; - + memcpy(ResolverMem, ResolverCode, sizeof(ResolverCode)); memcpy(ResolverMem + ReentryFnAddrOffset, &ReentryFn, sizeof(ReentryFn)); memcpy(ResolverMem + CallbackMgrAddrOffset, &CallbackMgr, @@ -81,13 +81,13 @@ void OrcX86_64::writeResolverCode(uint8_t *ResolverMem, JITReentryFn ReentryFn, } void OrcX86_64::writeTrampolines(uint8_t *TrampolineMem, void *ResolverAddr, - unsigned NumTrampolines) { + unsigned NumTrampolines) { unsigned OffsetToPtr = NumTrampolines * TrampolineSize; - memcpy(TrampolineMem + OffsetToPtr, &ResolverAddr, sizeof(void*)); + memcpy(TrampolineMem + OffsetToPtr, &ResolverAddr, sizeof(void *)); - uint64_t *Trampolines = reinterpret_cast<uint64_t*>(TrampolineMem); + uint64_t *Trampolines = reinterpret_cast<uint64_t *>(TrampolineMem); uint64_t CallIndirPCRel = 0xf1c40000000015ff; for (unsigned I = 0; I < NumTrampolines; ++I, OffsetToPtr -= TrampolineSize) @@ -126,36 +126,32 @@ 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); // Create separate MemoryBlocks representing the stubs and pointers. sys::MemoryBlock StubsBlock(StubsMem.base(), NumPages * PageSize); - sys::MemoryBlock PtrsBlock(static_cast<char*>(StubsMem.base()) + - NumPages * PageSize, + sys::MemoryBlock PtrsBlock(static_cast<char *>(StubsMem.base()) + + NumPages * PageSize, NumPages * PageSize); // 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 *Stub = reinterpret_cast<uint64_t *>(StubsBlock.base()); + 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. - void **Ptr = reinterpret_cast<void**>(PtrsBlock.base()); + void **Ptr = reinterpret_cast<void **>(PtrsBlock.base()); for (unsigned I = 0; I < NumStubs; ++I) Ptr[I] = InitialPtrVal; @@ -168,37 +164,38 @@ void OrcI386::writeResolverCode(uint8_t *ResolverMem, JITReentryFn ReentryFn, void *CallbackMgr) { const uint8_t ResolverCode[] = { - // resolver_entry: - 0x55, // 0x00: pushl %ebp - 0x89, 0xe5, // 0x01: movl %esp, %ebp - 0x54, // 0x03: pushl %esp - 0x83, 0xe4, 0xf0, // 0x04: andl $-0x10, %esp - 0x50, // 0x07: pushl %eax - 0x53, // 0x08: pushl %ebx - 0x51, // 0x09: pushl %ecx - 0x52, // 0x0a: pushl %edx - 0x56, // 0x0b: pushl %esi - 0x57, // 0x0c: pushl %edi - 0x81, 0xec, 0x18, 0x02, 0x00, 0x00, // 0x0d: subl $0x218, %esp - 0x0f, 0xae, 0x44, 0x24, 0x10, // 0x13: fxsave 0x10(%esp) - 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) - 0xb8, 0x00, 0x00, 0x00, 0x00, // 0x29: movl <reentry>, %eax - 0xff, 0xd0, // 0x2e: calll *%eax - 0x89, 0x45, 0x04, // 0x30: movl %eax, 0x4(%ebp) - 0x0f, 0xae, 0x4c, 0x24, 0x10, // 0x33: fxrstor 0x10(%esp) - 0x81, 0xc4, 0x18, 0x02, 0x00, 0x00, // 0x38: addl $0x218, %esp - 0x5f, // 0x3e: popl %edi - 0x5e, // 0x3f: popl %esi - 0x5a, // 0x40: popl %edx - 0x59, // 0x41: popl %ecx - 0x5b, // 0x42: popl %ebx - 0x58, // 0x43: popl %eax - 0x8b, 0x65, 0xfc, // 0x44: movl -0x4(%ebp), %esp - 0x5d, // 0x48: popl %ebp - 0xc3 // 0x49: retl + // resolver_entry: + 0x55, // 0x00: pushl %ebp + 0x89, 0xe5, // 0x01: movl %esp, %ebp + 0x54, // 0x03: pushl %esp + 0x83, 0xe4, 0xf0, // 0x04: andl $-0x10, %esp + 0x50, // 0x07: pushl %eax + 0x53, // 0x08: pushl %ebx + 0x51, // 0x09: pushl %ecx + 0x52, // 0x0a: pushl %edx + 0x56, // 0x0b: pushl %esi + 0x57, // 0x0c: pushl %edi + 0x81, 0xec, 0x18, 0x02, 0x00, 0x00, // 0x0d: subl $0x218, %esp + 0x0f, 0xae, 0x44, 0x24, 0x10, // 0x13: fxsave 0x10(%esp) + 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) + 0xb8, 0x00, 0x00, 0x00, 0x00, // 0x29: movl <reentry>, %eax + 0xff, 0xd0, // 0x2e: calll *%eax + 0x89, 0x45, 0x04, // 0x30: movl %eax, 0x4(%ebp) + 0x0f, 0xae, 0x4c, 0x24, 0x10, // 0x33: fxrstor 0x10(%esp) + 0x81, 0xc4, 0x18, 0x02, 0x00, 0x00, // 0x38: addl $0x218, %esp + 0x5f, // 0x3e: popl %edi + 0x5e, // 0x3f: popl %esi + 0x5a, // 0x40: popl %edx + 0x59, // 0x41: popl %ecx + 0x5b, // 0x42: popl %ebx + 0x58, // 0x43: popl %eax + 0x8b, 0x65, 0xfc, // 0x44: movl -0x4(%ebp), %esp + 0x5d, // 0x48: popl %ebp + 0xc3 // 0x49: retl }; const unsigned ReentryFnAddrOffset = 0x2a; @@ -216,16 +213,15 @@ void OrcI386::writeTrampolines(uint8_t *TrampolineMem, void *ResolverAddr, uint64_t CallRelImm = 0xF1C4C400000000e8; uint64_t Resolver = reinterpret_cast<uint64_t>(ResolverAddr); uint64_t ResolverRel = - Resolver - reinterpret_cast<uint64_t>(TrampolineMem) - 5; + Resolver - reinterpret_cast<uint64_t>(TrampolineMem) - 5; - uint64_t *Trampolines = reinterpret_cast<uint64_t*>(TrampolineMem); + uint64_t *Trampolines = reinterpret_cast<uint64_t *>(TrampolineMem); for (unsigned I = 0; I < NumTrampolines; ++I, ResolverRel -= TrampolineSize) Trampolines[I] = CallRelImm | (ResolverRel << 8); } Error OrcI386::emitIndirectStubsBlock(IndirectStubsInfo &StubsInfo, - unsigned MinStubs, - void *InitialPtrVal) { + unsigned MinStubs, void *InitialPtrVal) { // Stub format is: // // .section __orc_stubs @@ -255,35 +251,31 @@ 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); // Create separate MemoryBlocks representing the stubs and pointers. sys::MemoryBlock StubsBlock(StubsMem.base(), NumPages * PageSize); - sys::MemoryBlock PtrsBlock(static_cast<char*>(StubsMem.base()) + - NumPages * PageSize, + sys::MemoryBlock PtrsBlock(static_cast<char *>(StubsMem.base()) + + NumPages * PageSize, NumPages * PageSize); // Populate the stubs page stubs and mark it executable. - uint64_t *Stub = reinterpret_cast<uint64_t*>(StubsBlock.base()); + uint64_t *Stub = reinterpret_cast<uint64_t *>(StubsBlock.base()); uint64_t PtrAddr = reinterpret_cast<uint64_t>(PtrsBlock.base()); 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. - void **Ptr = reinterpret_cast<void**>(PtrsBlock.base()); + void **Ptr = reinterpret_cast<void **>(PtrsBlock.base()); for (unsigned I = 0; I < NumStubs; ++I) Ptr[I] = InitialPtrVal; diff --git a/llvm/lib/ExecutionEngine/Orc/OrcCBindings.cpp b/llvm/lib/ExecutionEngine/Orc/OrcCBindings.cpp index 565a9d03ec9..4153f7f0cc9 100644 --- a/llvm/lib/ExecutionEngine/Orc/OrcCBindings.cpp +++ b/llvm/lib/ExecutionEngine/Orc/OrcCBindings.cpp @@ -19,11 +19,10 @@ LLVMOrcJITStackRef LLVMOrcCreateInstance(LLVMTargetMachineRef TM) { auto CompileCallbackMgr = OrcCBindingsStack::createCompileCallbackMgr(T); auto IndirectStubsMgrBuilder = - OrcCBindingsStack::createIndirectStubsMgrBuilder(T); + 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, diff --git a/llvm/lib/ExecutionEngine/Orc/OrcCBindingsStack.cpp b/llvm/lib/ExecutionEngine/Orc/OrcCBindingsStack.cpp index 412e605fc0b..10f6692e9ff 100644 --- a/llvm/lib/ExecutionEngine/Orc/OrcCBindingsStack.cpp +++ b/llvm/lib/ExecutionEngine/Orc/OrcCBindingsStack.cpp @@ -20,35 +20,36 @@ 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; - return llvm::make_unique<CCMgrT>(0); - }; + case Triple::x86: { + typedef orc::LocalJITCompileCallbackManager<orc::OrcI386> CCMgrT; + return llvm::make_unique<CCMgrT>(0); + }; - case Triple::x86_64: { - typedef orc::LocalJITCompileCallbackManager<orc::OrcX86_64> CCMgrT; - return llvm::make_unique<CCMgrT>(0); - } + case Triple::x86_64: { + typedef orc::LocalJITCompileCallbackManager<orc::OrcX86_64> CCMgrT; + return llvm::make_unique<CCMgrT>(0); + } } } OrcCBindingsStack::IndirectStubsManagerBuilder OrcCBindingsStack::createIndirectStubsMgrBuilder(Triple T) { switch (T.getArch()) { - default: return nullptr; - - case Triple::x86: - return [](){ - return llvm::make_unique< - orc::LocalIndirectStubsManager<orc::OrcI386>>(); - }; - - case Triple::x86_64: - return [](){ - return llvm::make_unique< - orc::LocalIndirectStubsManager<orc::OrcX86_64>>(); - }; + default: + return nullptr; + + case Triple::x86: + return []() { + return llvm::make_unique<orc::LocalIndirectStubsManager<orc::OrcI386>>(); + }; + + case Triple::x86_64: + return []() { + return llvm::make_unique< + orc::LocalIndirectStubsManager<orc::OrcX86_64>>(); + }; } } diff --git a/llvm/lib/ExecutionEngine/Orc/OrcCBindingsStack.h b/llvm/lib/ExecutionEngine/Orc/OrcCBindingsStack.h index 6b84c7b523f..508ce62c88d 100644 --- a/llvm/lib/ExecutionEngine/Orc/OrcCBindingsStack.h +++ b/llvm/lib/ExecutionEngine/Orc/OrcCBindingsStack.h @@ -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,19 +29,18 @@ 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; + CallbackManagerBuilder; typedef CODLayerT::IndirectStubsManagerBuilderT IndirectStubsManagerBuilder; private: - class GenericHandle { public: virtual ~GenericHandle() {} @@ -50,20 +49,17 @@ 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)) {} + : Layer(Layer), Handle(std::move(Handle)) {} orc::JITSymbol findSymbolIn(const std::string &Name, bool ExportedSymbolsOnly) override { 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 { - return Callback(wrap(this), CallbackCtx); - }); + 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)); } @@ -148,36 +141,33 @@ public: createResolver(LLVMOrcSymbolResolverFn ExternalResolver, void *ExternalResolverCtx) { auto Resolver = orc::createLambdaResolver( - [this, ExternalResolver, ExternalResolverCtx](const std::string &Name) { - // Search order: - // 1. JIT'd symbols. - // 2. Runtime overrides. - // 3. External resolver (if present). - - if (auto Sym = CODLayer.findSymbol(Name, true)) - 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), - llvm::JITSymbolFlags::Exported); - - return RuntimeDyld::SymbolInfo(nullptr); - }, - [](const std::string &Name) { - return RuntimeDyld::SymbolInfo(nullptr); - } - ); + [this, ExternalResolver, ExternalResolverCtx](const std::string &Name) { + // Search order: + // 1. JIT'd symbols. + // 2. Runtime overrides. + // 3. External resolver (if present). + + if (auto Sym = CODLayer.findSymbol(Name, true)) + 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), + 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) { @@ -198,7 +188,7 @@ public: auto Resolver = createResolver(ExternalResolver, ExternalResolverCtx); // Add the module to the JIT. - std::vector<Module*> S; + std::vector<Module *> S; S.push_back(std::move(M)); auto LH = Layer.addModuleSet(std::move(S), std::move(MemMgr), @@ -215,7 +205,7 @@ public: return H; } - ModuleHandleT addIRModuleEager(Module* M, + ModuleHandleT addIRModuleEager(Module *M, LLVMOrcSymbolResolverFn ExternalResolver, void *ExternalResolverCtx) { return addIRModule(CompileLayer, std::move(M), @@ -223,11 +213,11 @@ public: std::move(ExternalResolver), ExternalResolverCtx); } - ModuleHandleT addIRModuleLazy(Module* M, + ModuleHandleT addIRModuleLazy(Module *M, LLVMOrcSymbolResolverFn ExternalResolver, void *ExternalResolverCtx) { return addIRModule(CODLayer, std::move(M), - llvm::make_unique<SectionMemoryManager>(), + llvm::make_unique<SectionMemoryManager>(), std::move(ExternalResolver), 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,14 +259,13 @@ private: LLVMOrcErrorCode mapError(Error Err) { LLVMOrcErrorCode Result = LLVMOrcErrSuccess; - handleAllErrors(std::move(Err), - [&](ErrorInfoBase &EIB) { - // Handler of last resort. - Result = LLVMOrcErrGeneric; - ErrMsg = ""; - raw_string_ostream ErrStream(ErrMsg); - EIB.log(ErrStream); - }); + handleAllErrors(std::move(Err), [&](ErrorInfoBase &EIB) { + // Handler of last resort. + Result = LLVMOrcErrGeneric; + ErrMsg = ""; + raw_string_ostream ErrStream(ErrMsg); + EIB.log(ErrStream); + }); return Result; } diff --git a/llvm/lib/ExecutionEngine/Orc/OrcError.cpp b/llvm/lib/ExecutionEngine/Orc/OrcError.cpp index 37b49903ba7..58889cc7bc1 100644 --- a/llvm/lib/ExecutionEngine/Orc/OrcError.cpp +++ b/llvm/lib/ExecutionEngine/Orc/OrcError.cpp @@ -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)); } } } |