From e9a9843e1380c42a22fe5a89229afa98f1668ef3 Mon Sep 17 00:00:00 2001 From: Andres Freund Date: Sun, 22 Jul 2018 21:13:20 -0700 Subject: [PATCH] LLVMJIT: Adapt to API changes in gdb and perf support. During the work of upstreaming my previous patches for gdb and perf support the API changed. Adapt. Normally this wouldn't necessarily be something to backpatch, but the previous API wasn't upstream, and at least the gdb support is quite useful for debugging. Author: Andres Freund Backpatch: 11, where LLVM based JIT support was added. --- config/llvm.m4 | 3 ++- configure | 45 +++++++++++++++++----------------- src/backend/jit/llvm/llvmjit.c | 17 ++++++++----- src/include/pg_config.h.in | 16 ++++++------ src/include/pg_config.h.win32 | 16 ++++++------ 5 files changed, 52 insertions(+), 45 deletions(-) diff --git a/config/llvm.m4 b/config/llvm.m4 index e25ffec661..09ff681228 100644 --- a/config/llvm.m4 +++ b/config/llvm.m4 @@ -94,8 +94,9 @@ AC_DEFUN([PGAC_LLVM_SUPPORT], # Check which functionality is present SAVE_CPPFLAGS="$CPPFLAGS" CPPFLAGS="$CPPFLAGS $LLVM_CPPFLAGS" - AC_CHECK_DECLS([LLVMOrcGetSymbolAddressIn, LLVMOrcRegisterGDB, LLVMOrcRegisterPerf], [], [], [[#include ]]) + AC_CHECK_DECLS([LLVMOrcGetSymbolAddressIn], [], [], [[#include ]]) AC_CHECK_DECLS([LLVMGetHostCPUName], [], [], [[#include ]]) + AC_CHECK_DECLS([LLVMCreateGDBRegistrationListener, LLVMCreatePerfJITEventListener], [], [], [[#include ]]) CPPFLAGS="$SAVE_CPPFLAGS" # LLVM_CONFIG, CLANG are already output via AC_ARG_VAR diff --git a/configure b/configure index f891914ed9..034ace014a 100755 --- a/configure +++ b/configure @@ -5007,28 +5007,6 @@ fi cat >>confdefs.h <<_ACEOF #define HAVE_DECL_LLVMORCGETSYMBOLADDRESSIN $ac_have_decl -_ACEOF -ac_fn_c_check_decl "$LINENO" "LLVMOrcRegisterGDB" "ac_cv_have_decl_LLVMOrcRegisterGDB" "#include -" -if test "x$ac_cv_have_decl_LLVMOrcRegisterGDB" = xyes; then : - ac_have_decl=1 -else - ac_have_decl=0 -fi - -cat >>confdefs.h <<_ACEOF -#define HAVE_DECL_LLVMORCREGISTERGDB $ac_have_decl -_ACEOF -ac_fn_c_check_decl "$LINENO" "LLVMOrcRegisterPerf" "ac_cv_have_decl_LLVMOrcRegisterPerf" "#include -" -if test "x$ac_cv_have_decl_LLVMOrcRegisterPerf" = xyes; then : - ac_have_decl=1 -else - ac_have_decl=0 -fi - -cat >>confdefs.h <<_ACEOF -#define HAVE_DECL_LLVMORCREGISTERPERF $ac_have_decl _ACEOF ac_fn_c_check_decl "$LINENO" "LLVMGetHostCPUName" "ac_cv_have_decl_LLVMGetHostCPUName" "#include @@ -5041,6 +5019,29 @@ fi cat >>confdefs.h <<_ACEOF #define HAVE_DECL_LLVMGETHOSTCPUNAME $ac_have_decl +_ACEOF + + ac_fn_c_check_decl "$LINENO" "LLVMCreateGDBRegistrationListener" "ac_cv_have_decl_LLVMCreateGDBRegistrationListener" "#include +" +if test "x$ac_cv_have_decl_LLVMCreateGDBRegistrationListener" = xyes; then : + ac_have_decl=1 +else + ac_have_decl=0 +fi + +cat >>confdefs.h <<_ACEOF +#define HAVE_DECL_LLVMCREATEGDBREGISTRATIONLISTENER $ac_have_decl +_ACEOF +ac_fn_c_check_decl "$LINENO" "LLVMCreatePerfJITEventListener" "ac_cv_have_decl_LLVMCreatePerfJITEventListener" "#include +" +if test "x$ac_cv_have_decl_LLVMCreatePerfJITEventListener" = xyes; then : + ac_have_decl=1 +else + ac_have_decl=0 +fi + +cat >>confdefs.h <<_ACEOF +#define HAVE_DECL_LLVMCREATEPERFJITEVENTLISTENER $ac_have_decl _ACEOF CPPFLAGS="$SAVE_CPPFLAGS" diff --git a/src/backend/jit/llvm/llvmjit.c b/src/backend/jit/llvm/llvmjit.c index 955c966713..640c27fc40 100644 --- a/src/backend/jit/llvm/llvmjit.c +++ b/src/backend/jit/llvm/llvmjit.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -666,18 +667,22 @@ 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 defined(HAVE_DECL_LLVMCREATEGDBREGISTRATIONLISTENER) && HAVE_DECL_LLVMCREATEGDBREGISTRATIONLISTENER if (jit_debugging_support) { - LLVMOrcRegisterGDB(llvm_opt0_orc); - LLVMOrcRegisterGDB(llvm_opt3_orc); + LLVMJITEventListenerRef l = LLVMCreateGDBRegistrationListener(); + + LLVMOrcRegisterJITEventListener(llvm_opt0_orc, l); + LLVMOrcRegisterJITEventListener(llvm_opt3_orc, l); } #endif -#if defined(HAVE_DECL_LLVMORCREGISTERPERF) && HAVE_DECL_LLVMORCREGISTERPERF +#if defined(HAVE_DECL_LLVMCREATEPERFJITEVENTLISTENER) && HAVE_DECL_LLVMCREATEPERFJITEVENTLISTENER if (jit_profiling_support) { - LLVMOrcRegisterPerf(llvm_opt0_orc); - LLVMOrcRegisterPerf(llvm_opt3_orc); + LLVMJITEventListenerRef l = LLVMCreatePerfJITEventListener(); + + LLVMOrcRegisterJITEventListener(llvm_opt0_orc, l); + LLVMOrcRegisterJITEventListener(llvm_opt3_orc, l); } #endif diff --git a/src/include/pg_config.h.in b/src/include/pg_config.h.in index f9fb92f31c..3eec284dc1 100644 --- a/src/include/pg_config.h.in +++ b/src/include/pg_config.h.in @@ -134,6 +134,14 @@ don't. */ #undef HAVE_DECL_F_FULLFSYNC +/* Define to 1 if you have the declaration of + `LLVMCreateGDBRegistrationListener', and to 0 if you don't. */ +#undef HAVE_DECL_LLVMCREATEGDBREGISTRATIONLISTENER + +/* Define to 1 if you have the declaration of + `LLVMCreatePerfJITEventListener', and to 0 if you don't. */ +#undef HAVE_DECL_LLVMCREATEPERFJITEVENTLISTENER + /* Define to 1 if you have the declaration of `LLVMGetHostCPUName', and to 0 if you don't. */ #undef HAVE_DECL_LLVMGETHOSTCPUNAME @@ -142,14 +150,6 @@ to 0 if you don't. */ #undef HAVE_DECL_LLVMORCGETSYMBOLADDRESSIN -/* Define to 1 if you have the declaration of `LLVMOrcRegisterGDB', and to 0 - if you don't. */ -#undef HAVE_DECL_LLVMORCREGISTERGDB - -/* Define to 1 if you have the declaration of `LLVMOrcRegisterPerf', and to 0 - if you don't. */ -#undef HAVE_DECL_LLVMORCREGISTERPERF - /* Define to 1 if you have the declaration of `posix_fadvise', and to 0 if you don't. */ #undef HAVE_DECL_POSIX_FADVISE diff --git a/src/include/pg_config.h.win32 b/src/include/pg_config.h.win32 index 01cf8daf43..ab276f7a95 100644 --- a/src/include/pg_config.h.win32 +++ b/src/include/pg_config.h.win32 @@ -107,6 +107,14 @@ don't. */ #define HAVE_DECL_F_FULLFSYNC 0 +/* Define to 1 if you have the declaration of + `LLVMCreateGDBRegistrationListener', and to 0 if you don't. */ +#undef HAVE_DECL_LLVMCREATEGDBREGISTRATIONLISTENER + +/* Define to 1 if you have the declaration of + `LLVMCreatePerfJITEventListener', and to 0 if you don't. */ +#undef HAVE_DECL_LLVMCREATEPERFJITEVENTLISTENER + /* Define to 1 if you have the declaration of `LLVMGetHostCPUName', and to 0 if you don't. */ #define HAVE_DECL_LLVMGETHOSTCPUNAME 0 @@ -115,14 +123,6 @@ to 0 if you don't. */ #define HAVE_DECL_LLVMORCGETSYMBOLADDRESSIN 0 -/* Define to 1 if you have the declaration of `LLVMOrcRegisterGDB', and to 0 - if you don't. */ -#define HAVE_DECL_LLVMORCREGISTERGDB 0 - -/* Define to 1 if you have the declaration of `LLVMOrcRegisterPerf', and to 0 - if you don't. */ -#define HAVE_DECL_LLVMORCREGISTERPERF 0 - /* Define to 1 if you have the declaration of `snprintf', and to 0 if you don't. */ #define HAVE_DECL_SNPRINTF 1