From 7ccce43ae2cf465d7ebf37185dc1dd4f11ed8fb3 Mon Sep 17 00:00:00 2001
From: Thomas Munro <thomas.munro@gmail.com>
Date: Thu, 27 Nov 2025 22:57:38 +1300
Subject: [PATCH 1/6] jit: Drop redundant LLVM configure checks.

We currently require LLVM 14, so these checks for LLVM 9 functions are
always true.  We finished up having to test LLVM major versions directly
due to the nature of API changes, so this function-probing style wasn't
continued.
---
 config/llvm.m4                 | 17 -----------------
 configure                      | 32 --------------------------------
 configure.ac                   |  4 ----
 meson.build                    |  8 --------
 src/backend/jit/llvm/llvmjit.c |  5 -----
 src/include/pg_config.h.in     |  8 --------
 6 files changed, 74 deletions(-)

diff --git a/config/llvm.m4 b/config/llvm.m4
index 9d6fe8199e3..5d4f14cb900 100644
--- a/config/llvm.m4
+++ b/config/llvm.m4
@@ -101,20 +101,3 @@ dnl LLVM_CONFIG, CLANG are already output via AC_ARG_VAR
   AC_SUBST(LLVM_BINPATH)
 
 ])# PGAC_LLVM_SUPPORT
-
-
-# PGAC_CHECK_LLVM_FUNCTIONS
-# -------------------------
-#
-# Check presence of some optional LLVM functions.
-# (This shouldn't happen until we're ready to run AC_CHECK_DECLS tests;
-# because PGAC_LLVM_SUPPORT runs very early, it's not an appropriate place.)
-#
-AC_DEFUN([PGAC_CHECK_LLVM_FUNCTIONS],
-[
-  # Check which functionality is present
-  SAVE_CPPFLAGS="$CPPFLAGS"
-  CPPFLAGS="$CPPFLAGS $LLVM_CPPFLAGS"
-  AC_CHECK_DECLS([LLVMCreateGDBRegistrationListener, LLVMCreatePerfJITEventListener], [], [], [[#include <llvm-c/ExecutionEngine.h>]])
-  CPPFLAGS="$SAVE_CPPFLAGS"
-])# PGAC_CHECK_LLVM_FUNCTIONS
diff --git a/configure b/configure
index 3a0ed11fa8e..486456deee1 100755
--- a/configure
+++ b/configure
@@ -16475,38 +16475,6 @@ fi
   CPPFLAGS=$ac_save_CPPFLAGS
 fi
 
-if test "$with_llvm" = yes; then
-
-  # Check which functionality is present
-  SAVE_CPPFLAGS="$CPPFLAGS"
-  CPPFLAGS="$CPPFLAGS $LLVM_CPPFLAGS"
-  ac_fn_c_check_decl "$LINENO" "LLVMCreateGDBRegistrationListener" "ac_cv_have_decl_LLVMCreateGDBRegistrationListener" "#include <llvm-c/ExecutionEngine.h>
-"
-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 <llvm-c/ExecutionEngine.h>
-"
-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"
-
-fi
-
 # Lastly, restore full LIBS list and check for readline/libedit symbols
 LIBS="$LIBS_including_readline"
 
diff --git a/configure.ac b/configure.ac
index c2413720a18..624c3f28ddc 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1938,10 +1938,6 @@ if test "$with_icu" = yes; then
   CPPFLAGS=$ac_save_CPPFLAGS
 fi
 
-if test "$with_llvm" = yes; then
-  PGAC_CHECK_LLVM_FUNCTIONS()
-fi
-
 # Lastly, restore full LIBS list and check for readline/libedit symbols
 LIBS="$LIBS_including_readline"
 
diff --git a/meson.build b/meson.build
index 6e7ddd74683..7011007e644 100644
--- a/meson.build
+++ b/meson.build
@@ -2665,14 +2665,6 @@ decl_checks += [
   ['memset_s', 'string.h', '#define __STDC_WANT_LIB_EXT1__ 1'],
 ]
 
-# Check presence of some optional LLVM functions.
-if llvm.found()
-  decl_checks += [
-    ['LLVMCreateGDBRegistrationListener', 'llvm-c/ExecutionEngine.h'],
-    ['LLVMCreatePerfJITEventListener', 'llvm-c/ExecutionEngine.h'],
-  ]
-endif
-
 foreach c : decl_checks
   func = c.get(0)
   header = c.get(1)
diff --git a/src/backend/jit/llvm/llvmjit.c b/src/backend/jit/llvm/llvmjit.c
index e978b996bae..3d67bd6b9bc 100644
--- a/src/backend/jit/llvm/llvmjit.c
+++ b/src/backend/jit/llvm/llvmjit.c
@@ -1180,24 +1180,19 @@ llvm_create_object_layer(void *Ctx, LLVMOrcExecutionSessionRef ES, const char *T
 		LLVMOrcCreateRTDyldObjectLinkingLayerWithSectionMemoryManager(ES);
 #endif
 
-
-#if defined(HAVE_DECL_LLVMCREATEGDBREGISTRATIONLISTENER) && HAVE_DECL_LLVMCREATEGDBREGISTRATIONLISTENER
 	if (jit_debugging_support)
 	{
 		LLVMJITEventListenerRef l = LLVMCreateGDBRegistrationListener();
 
 		LLVMOrcRTDyldObjectLinkingLayerRegisterJITEventListener(objlayer, l);
 	}
-#endif
 
-#if defined(HAVE_DECL_LLVMCREATEPERFJITEVENTLISTENER) && HAVE_DECL_LLVMCREATEPERFJITEVENTLISTENER
 	if (jit_profiling_support)
 	{
 		LLVMJITEventListenerRef l = LLVMCreatePerfJITEventListener();
 
 		LLVMOrcRTDyldObjectLinkingLayerRegisterJITEventListener(objlayer, l);
 	}
-#endif
 
 	return objlayer;
 }
diff --git a/src/include/pg_config.h.in b/src/include/pg_config.h.in
index b0b0cfdaf79..56915d2ef91 100644
--- a/src/include/pg_config.h.in
+++ b/src/include/pg_config.h.in
@@ -83,14 +83,6 @@
    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 `memset_s', and to 0 if you
    don't. */
 #undef HAVE_DECL_MEMSET_S
-- 
2.51.2

