From 018984e94eb2aca83a40cba6b5f1a8ef67c4d67c Mon Sep 17 00:00:00 2001 From: Yichao Yu Date: Thu, 2 Jun 2016 22:56:30 -0400 Subject: [PATCH] Move memory manager out of debuginfo.cpp --- src/codegen.cpp | 17 ++++-------- src/debuginfo.cpp | 61 +++++++++----------------------------------- src/jitlayers.cpp | 51 +++++++++++++++++++++++++++--------- src/julia_internal.h | 3 +++ 4 files changed, 59 insertions(+), 73 deletions(-) diff --git a/src/codegen.cpp b/src/codegen.cpp index 712820525e61f..bc1df3e02cfc9 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -94,7 +94,6 @@ #include "llvm/ExecutionEngine/ObjectMemoryBuffer.h" #elif defined(USE_MCJIT) #include -#include #include #include #else @@ -335,15 +334,11 @@ static GlobalVariable *jlRTLD_DEFAULT_var; static GlobalVariable *jlexe_var; static GlobalVariable *jldll_var; #if defined(_CPU_X86_64_) && !defined(USE_MCJIT) -extern JITMemoryManager *createJITMemoryManagerWin(); +JITMemoryManager *createJITMemoryManagerWin(); #endif #endif //_OS_WINDOWS_ -#if defined(_OS_DARWIN_) && defined(LLVM37) && defined(LLVM_SHLIB) -#define CUSTOM_MEMORY_MANAGER createRTDyldMemoryManagerOSX -extern RTDyldMemoryManager *createRTDyldMemoryManagerOSX(); -#elif defined(_OS_LINUX_) && defined(LLVM37) && defined(JL_UNW_HAS_FORMAT_IP) -#define CUSTOM_MEMORY_MANAGER createRTDyldMemoryManagerUnix -extern RTDyldMemoryManager *createRTDyldMemoryManagerUnix(); +#ifdef USE_MCJIT +RTDyldMemoryManager *createRTDyldMemoryManager(); #endif static Function *jltls_states_func; @@ -5731,10 +5726,8 @@ extern "C" void jl_init_codegen(void) eb .setEngineKind(EngineKind::JIT) #if defined(_OS_WINDOWS_) && defined(_CPU_X86_64_) && !defined(USE_MCJIT) .setJITMemoryManager(createJITMemoryManagerWin()) -#elif defined(CUSTOM_MEMORY_MANAGER) - .setMCJITMemoryManager(std::unique_ptr{CUSTOM_MEMORY_MANAGER()}) -#elif defined(USE_ORCMCJIT) // ORCJIT forgets to create one if one isn't created for it - .setMCJITMemoryManager(std::unique_ptr{new SectionMemoryManager()}) +#elif defined(USE_MCJIT) + .setMCJITMemoryManager(std::unique_ptr{createRTDyldMemoryManager()}) #endif .setTargetOptions(options) #if (defined(_OS_LINUX_) && defined(_CPU_X86_64_)) diff --git a/src/debuginfo.cpp b/src/debuginfo.cpp index abd9365894560..36f470e06e5e8 100644 --- a/src/debuginfo.cpp +++ b/src/debuginfo.cpp @@ -1341,28 +1341,11 @@ static void processFDEs(const char *EHFrameAddr, size_t EHFrameSize, callback f) * ourselves to ensure the right one gets picked. */ -#include "llvm/ExecutionEngine/SectionMemoryManager.h" -class RTDyldMemoryManagerOSX : public SectionMemoryManager -{ - RTDyldMemoryManagerOSX(const RTDyldMemoryManagerOSX&) = delete; - void operator=(const RTDyldMemoryManagerOSX&) = delete; - -public: - RTDyldMemoryManagerOSX() {}; - ~RTDyldMemoryManagerOSX() override {}; - void registerEHFrames(uint8_t *Addr, uint64_t LoadAddr, size_t Size) override; - void deregisterEHFrames(uint8_t *Addr, uint64_t LoadAddr, size_t Size) override; -}; - static void (*libc_register_frame)(void*) = NULL; static void (*libc_deregister_frame)(void*) = NULL; // This implementation handles frame registration for local targets. -// Memory managers for remote targets should re-implement this function -// and use the LoadAddr parameter. -void RTDyldMemoryManagerOSX::registerEHFrames(uint8_t *Addr, - uint64_t LoadAddr, - size_t Size) +void register_eh_frames(uint8_t *Addr, size_t Size) { // On OS X OS X __register_frame takes a single FDE as an argument. // See http://lists.cs.uiuc.edu/pipermail/llvmdev/2013-April/061768.html @@ -1376,9 +1359,7 @@ void RTDyldMemoryManagerOSX::registerEHFrames(uint8_t *Addr, }); } -void RTDyldMemoryManagerOSX::deregisterEHFrames(uint8_t *Addr, - uint64_t LoadAddr, - size_t Size) +void deregister_eh_frames(uint8_t *Addr, size_t Size) { processFDEs((char*)Addr, Size, [](const char *Entry) { if (!libc_deregister_frame) { @@ -1390,27 +1371,8 @@ void RTDyldMemoryManagerOSX::deregisterEHFrames(uint8_t *Addr, }); } -RTDyldMemoryManager* createRTDyldMemoryManagerOSX() -{ - return new RTDyldMemoryManagerOSX(); -} - -#endif - -#if defined(_OS_LINUX_) && defined(LLVM37) && defined(JL_UNW_HAS_FORMAT_IP) +#elif defined(_OS_LINUX_) && defined(LLVM37) && defined(JL_UNW_HAS_FORMAT_IP) #include -#include "llvm/ExecutionEngine/SectionMemoryManager.h" -class RTDyldMemoryManagerUnix : public SectionMemoryManager -{ - RTDyldMemoryManagerUnix(const RTDyldMemoryManagerUnix&) = delete; - void operator=(const RTDyldMemoryManagerUnix&) = delete; - -public: - RTDyldMemoryManagerUnix() {}; - ~RTDyldMemoryManagerUnix() override {}; - void registerEHFrames(uint8_t *Addr, uint64_t LoadAddr, size_t Size) override; - void deregisterEHFrames(uint8_t *Addr, uint64_t LoadAddr, size_t Size) override; -}; struct unw_table_entry { @@ -1592,9 +1554,7 @@ static DW_EH_PE parseCIE(const uint8_t *Addr, const uint8_t *End) return DW_EH_PE_absptr; } -void RTDyldMemoryManagerUnix::registerEHFrames(uint8_t *Addr, - uint64_t LoadAddr, - size_t Size) +void register_eh_frames(uint8_t *Addr, size_t Size) { #ifndef _CPU_ARM_ // System unwinder @@ -1725,9 +1685,7 @@ void RTDyldMemoryManagerUnix::registerEHFrames(uint8_t *Addr, _U_dyn_register(di); } -void RTDyldMemoryManagerUnix::deregisterEHFrames(uint8_t *Addr, - uint64_t LoadAddr, - size_t Size) +void deregister_eh_frames(uint8_t *Addr, size_t Size) { #ifndef _CPU_ARM_ __deregister_frame(Addr); @@ -1737,9 +1695,14 @@ void RTDyldMemoryManagerUnix::deregisterEHFrames(uint8_t *Addr, // data structures). } -RTDyldMemoryManager* createRTDyldMemoryManagerUnix() +#else + +void register_eh_frames(uint8_t *Addr, size_t Size) +{ +} + +void deregister_eh_frames(uint8_t *Addr, size_t Size) { - return new RTDyldMemoryManagerUnix(); } #endif diff --git a/src/jitlayers.cpp b/src/jitlayers.cpp index 72a889897e81f..4c7696258ce63 100644 --- a/src/jitlayers.cpp +++ b/src/jitlayers.cpp @@ -1,5 +1,7 @@ // This file is a part of Julia. License is MIT: http://julialang.org/license +#include + // Except for parts of this file which were copied from LLVM, under the UIUC license (marked below). // this defines the set of optimization passes defined for Julia at various optimization levels @@ -129,6 +131,42 @@ static void addOptimizationPasses(T *PM) //PM->add(createCFGSimplificationPass()); // Merge & remove BBs } +#ifdef USE_MCJIT +#ifdef LLVM37 +class RTDyldMemoryManagerJL : public SectionMemoryManager { + RTDyldMemoryManagerJL(const RTDyldMemoryManagerJL&) = delete; + void operator=(const RTDyldMemoryManagerJL&) = delete; + +public: + RTDyldMemoryManagerJL() {}; + ~RTDyldMemoryManagerJL() override {}; + void registerEHFrames(uint8_t *Addr, uint64_t LoadAddr, size_t Size) override; + void deregisterEHFrames(uint8_t *Addr, uint64_t LoadAddr, size_t Size) override; +}; + +void RTDyldMemoryManagerJL::registerEHFrames(uint8_t *Addr, + uint64_t LoadAddr, + size_t Size) +{ + register_eh_frames(Addr, Size); +} + +void RTDyldMemoryManagerJL::deregisterEHFrames(uint8_t *Addr, + uint64_t LoadAddr, + size_t Size) +{ + deregister_eh_frames(Addr, Size); +} +#else +typedef SectionMemoryManager RTDyldMemoryManagerJL; +#endif + +RTDyldMemoryManager* createRTDyldMemoryManager() +{ + return new RTDyldMemoryManagerJL(); +} +#endif + #ifdef USE_ORCJIT // ------------------------ TEMPORARILY COPIED FROM LLVM ----------------- @@ -190,17 +228,6 @@ void NotifyDebugger(jit_code_entry *JITCodeEntry) } // ------------------------ END OF TEMPORARY COPY FROM LLVM ----------------- -#if defined(_OS_DARWIN_) && defined(LLVM37) && defined(LLVM_SHLIB) -#define CUSTOM_MEMORY_MANAGER createRTDyldMemoryManagerOSX -extern RTDyldMemoryManager *createRTDyldMemoryManagerOSX(); -#elif defined(_OS_LINUX_) && defined(LLVM37) && defined(JL_UNW_HAS_FORMAT_IP) -#define CUSTOM_MEMORY_MANAGER createRTDyldMemoryManagerUnix -extern RTDyldMemoryManager *createRTDyldMemoryManagerUnix(); -#endif -#ifndef CUSTOM_MEMORY_MANAGER -#define CUSTOM_MEMORY_MANAGER() new SectionMemoryManager -#endif - #ifdef _OS_LINUX_ // Resolve non-lock free atomic functions in the libatomic library. // This is the library that provides support for c11/c++11 atomic operations. @@ -322,7 +349,7 @@ class JuliaOJIT { : TM(TM), DL(TM.createDataLayout()), ObjStream(ObjBufferSV), - MemMgr(CUSTOM_MEMORY_MANAGER()), + MemMgr(createRTDyldMemoryManager()), ObjectLayer(DebugObjectRegistrar(*this)), CompileLayer( ObjectLayer, diff --git a/src/julia_internal.h b/src/julia_internal.h index add229fc5ab0b..f4ca351867ad2 100644 --- a/src/julia_internal.h +++ b/src/julia_internal.h @@ -651,6 +651,9 @@ jl_value_t *jl_lookup_match(jl_value_t *a, jl_value_t *b, jl_svec_t **penv, jl_s unsigned jl_special_vector_alignment(size_t nfields, jl_value_t *field_type); +void register_eh_frames(uint8_t *Addr, size_t Size); +void deregister_eh_frames(uint8_t *Addr, size_t Size); + #ifdef __cplusplus } #endif