From 250bca7fc145b143d5e9aeeca66f0bb36cf4d5ef Mon Sep 17 00:00:00 2001 From: Andres Freund Date: Thu, 22 Mar 2018 11:07:55 -0700 Subject: Debugging and profiling support for LLVM JIT provider. This currently requires patches to the LLVM codebase to be effective (submitted upstream), the GUCs are available without those patches however. Author: Andres Freund Discussion: https://postgr.es/m/20170901064131.tazjxwus3k2w3ybh@alap3.anarazel.de --- src/backend/jit/llvm/llvmjit.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'src/backend/jit/llvm/llvmjit.c') diff --git a/src/backend/jit/llvm/llvmjit.c b/src/backend/jit/llvm/llvmjit.c index 6b07c143b2b..8cf8aaaa3a1 100644 --- a/src/backend/jit/llvm/llvmjit.c +++ b/src/backend/jit/llvm/llvmjit.c @@ -541,6 +541,21 @@ llvm_session_initialize(void) llvm_opt0_orc = LLVMOrcCreateInstance(llvm_opt0_targetmachine); llvm_opt3_orc = LLVMOrcCreateInstance(llvm_opt3_targetmachine); +#if defined(HAVE_DECL_LLVMORCREGISTERGDB) && HAVE_DECL_LLVMORCREGISTERGDB + if (jit_debugging_support) + { + LLVMOrcRegisterGDB(llvm_opt0_orc); + LLVMOrcRegisterGDB(llvm_opt3_orc); + } +#endif +#if defined(HAVE_DECL_LLVMORCREGISTERPERF) && HAVE_DECL_LLVMORCREGISTERPERF + if (jit_profiling_support) + { + LLVMOrcRegisterPerf(llvm_opt0_orc); + LLVMOrcRegisterPerf(llvm_opt3_orc); + } +#endif + before_shmem_exit(llvm_shutdown, 0); llvm_session_initialized = true; @@ -551,6 +566,27 @@ llvm_session_initialize(void) static void llvm_shutdown(int code, Datum arg) { + /* unregister profiling support, needs to be flushed to be useful */ + + if (llvm_opt3_orc) + { +#if defined(HAVE_DECL_LLVMORCREGISTERPERF) && HAVE_DECL_LLVMORCREGISTERPERF + if (jit_profiling_support) + LLVMOrcUnregisterPerf(llvm_opt3_orc); +#endif + LLVMOrcDisposeInstance(llvm_opt3_orc); + llvm_opt3_orc = NULL; + } + + if (llvm_opt0_orc) + { +#if defined(HAVE_DECL_LLVMORCREGISTERPERF) && HAVE_DECL_LLVMORCREGISTERPERF + if (jit_profiling_support) + LLVMOrcUnregisterPerf(llvm_opt0_orc); +#endif + LLVMOrcDisposeInstance(llvm_opt0_orc); + llvm_opt0_orc = NULL; + } } /* helper for llvm_create_types */ -- cgit v1.2.3