Guiding principle for dropping LLVM versions?
Hi,
Currently we claim to support all versions of LLVM from 3.9 up. It's
now getting quite inconvenient to test changes on older releases with
single digit major versions, because they aren't available through
usual package channels on current distributions, and frankly it feels
like pointless busy-work to build those older versions from source
(not to mention that it takes hoooouuurrs to compile that much C++).
At the other end of the window, we've also been back-patching support
for the latest LLVM versions into all supported releases, which might
make slightly more sense, but I don't know.
For the trailing end of the window, would it make sense to say that
when PostgreSQL 17 ships, it doesn't need to support any LLVM versions
that are no longer available in the default package repositories of
current major distros?
I'm trying to understand the practical constraints. Perhaps a package
maintainer could correct me if I have this wrong. Distros typically
support a range of releases from the past few years, and then bless
one as 'default' by making it the one you get if you install a meta
package eg 'llvm' without a number (for example, on Debian 12 this is
LLVM 14, though LLVM 13 is still available). Having a default
encourages sharing, eg one LLVM library can be used by many different
things. The maintainer of the PostgreSQL package then chooses which
one to link against, and it's usually the default one unless we can't
use that one yet for technical reasons (a situation that might arise
from time to time in bleeding edge distros). So if we just knew the
*oldest default* on every live distro at release time, I assume no
package maintainer would get upset if we ripped out support for
everything older, and that'd let us vacuum a lot of old versions out
of our tree.
A more conservative horizon would be: which is the *oldest* LLVM you
can still get through the usual channels on every relevant distro, for
the benefit of people compiling from source, who for some reason want
to use a version older then the default on their distro? I don't know
what the motivation would be.
What reason could there be to be more conservative than that?
I wonder if there is a good way to make this sort of thing more
systematic. If we could agree on a guiding principle vaguely like the
above, then perhaps we just need a wiki page that lists relevant
distributions, versions and EOL dates, that could be used to reduce
the combinations of stuff we have to consider and make the pruning
decisions into no-brainers.
Hi,
On Thu, 2023-09-21 at 10:54 +1200, Thomas Munro wrote:
I'm trying to understand the practical constraints. Perhaps a package
maintainer could correct me if I have this wrong. Distros typically
support a range of releases from the past few years, and then bless
one as 'default' by making it the one you get if you install a meta
package eg 'llvm' without a number (for example, on Debian 12 this is
LLVM 14, though LLVM 13 is still available). Having a default
encourages sharing, eg one LLVM library can be used by many different
things. The maintainer of the PostgreSQL package then chooses which
one to link against, and it's usually the default one unless we can't
use that one yet for technical reasons (a situation that might arise
from time to time in bleeding edge distros). So if we just knew the
*oldest default* on every live distro at release time, I assume no
package maintainer would get upset if we ripped out support for
everything older, and that'd let us vacuum a lot of old versions out
of our tree.
RPM packager speaking:
Even though older LLVM versions exist on both RHEL and Fedora, they
don't provide older Clang packages, which means we have to link to the
latest release anyway (like currently Fedora 38 packages are waiting for
LLVM 16 patch, as they cannot be linked against LLVM 15)
Regards,
Regards,
--
Devrim Gündüz
Open Source Solution Architect, PostgreSQL Major Contributor
Twitter: @DevrimGunduz , @DevrimGunduzTR
Thomas Munro <thomas.munro@gmail.com> writes:
I wonder if there is a good way to make this sort of thing more
systematic. If we could agree on a guiding principle vaguely like the
above, then perhaps we just need a wiki page that lists relevant
distributions, versions and EOL dates, that could be used to reduce
the combinations of stuff we have to consider and make the pruning
decisions into no-brainers.
FWIW, I think "compile older Postgres on newer infrastructure"
is a more common and more defensible scenario than "compile
newer Postgres on older infrastructure". We've spent a ton of
effort on the latter scenario (and I've helped lead the charge
in many cases), but I think the real-world demand for it isn't
truly that high once you get beyond a year or two back. On the
other hand, if you have an app that depends on PG 11 behavioral
details and you don't want to update it right now, you might
nonetheless need to put that server onto recent infrastructure
for practical reasons.
Thus, I think it's worthwhile to spend effort on back-patching
new-LLVM compatibility fixes into old PG branches, but I agree
that newer PG branches can drop compatibility with obsolete
LLVM versions.
LLVM is maybe not the poster child for these concerns -- for
either direction of compatibility problems, someone could build
without JIT support and not really be dead in the water.
In any case, I agree with your prior decision to not touch v11
for this. With that branch's next release being its last,
I think the odds of introducing a bug we can't fix later
outweigh any arguable portability gain.
regards, tom lane
On 21 Sep 2023, at 07:28, Tom Lane <tgl@sss.pgh.pa.us> wrote:
Thomas Munro <thomas.munro@gmail.com> writes:
I wonder if there is a good way to make this sort of thing more
systematic. If we could agree on a guiding principle vaguely like the
above, then perhaps we just need a wiki page that lists relevant
distributions, versions and EOL dates, that could be used to reduce
the combinations of stuff we have to consider and make the pruning
decisions into no-brainers.
As someone who on occasion poke at OpenSSL compat code I would very much like a
more structured approach around dealing with dependencies.
Thus, I think it's worthwhile to spend effort on back-patching
new-LLVM compatibility fixes into old PG branches, but I agree
that newer PG branches can drop compatibility with obsolete
LLVM versions.
+1
LLVM is maybe not the poster child for these concerns -- for
either direction of compatibility problems, someone could build
without JIT support and not really be dead in the water.
Right, OpenSSL on the other hand might be better example since removing TLS
support is likely a no-show. I can see both the need to use an old OpenSSL
version in a backbranch due to certifications etc, as well as a requirement in
other cases to use the latest version due to CVE's.
In any case, I agree with your prior decision to not touch v11
for this. With that branch's next release being its last,
I think the odds of introducing a bug we can't fix later
outweigh any arguable portability gain.
Agreed.
--
Daniel Gustafsson
On Thu, Sep 21, 2023 at 12:27 PM Devrim Gündüz <devrim@gunduz.org> wrote:
Even though older LLVM versions exist on both RHEL and Fedora, they
don't provide older Clang packages, which means we have to link to the
latest release anyway (like currently Fedora 38 packages are waiting for
LLVM 16 patch, as they cannot be linked against LLVM 15)
That's quite interesting, because it means that RHEL doesn't act as
the "lanterne route" for this, ie the most conservative relevant
distribution.
If we used Debian as a yardstick, PostgreSQL 17 wouldn't need anything
older than LLVM 14 AFAICS. Who else do we need to ask? Where could
we find this sort of information in machine-readable form (that is
feedback I got discussing the wiki page idea with people, ie that it
would be bound to become stale and abandoned)?
Fresh from doing battle with this stuff, I wanted to see what it would
look like if we dropped 3.9...13 in master:
11 files changed, 12 insertions(+), 367 deletions(-)
I noticed in passing that the LLVMOrcRegisterJITEventListener
configure probes are not present in meson.
Attachments:
0001-jit-Require-at-least-LLVM-14-if-enabled.patchapplication/octet-stream; name=0001-jit-Require-at-least-LLVM-14-if-enabled.patchDownload
From 68e3d53d0e40a7bd505e9acced7621e89f027f77 Mon Sep 17 00:00:00 2001
From: Thomas Munro <thomas.munro@gmail.com>
Date: Thu, 19 Oct 2023 04:45:46 +1300
Subject: [PATCH] jit: Require at least LLVM 14, if enabled.
Remove support for a lot of older LLVM versions dating back to 3.9. The
default on common software distritbutions will be at least LLVM 14 when
PostgreSQL 17 ships.
Discussion: https://postgr.es/m/CA%2BhUKGLhNs5geZaVNj2EJ79Dx9W8fyWUU3HxcpZy55sMGcY%3DiA%40mail.gmail.com
---
config/llvm.m4 | 6 +-
configure | 39 +-----
doc/src/sgml/installation.sgml | 4 +-
meson.build | 2 +-
src/backend/jit/llvm/llvmjit.c | 158 +-----------------------
src/backend/jit/llvm/llvmjit_error.cpp | 35 ------
src/backend/jit/llvm/llvmjit_expr.c | 6 +-
src/backend/jit/llvm/llvmjit_inline.cpp | 51 +-------
src/backend/jit/llvm/llvmjit_wrap.cpp | 63 +---------
src/include/pg_config.h.in | 12 --
src/tools/msvc/Solution.pm | 3 -
11 files changed, 12 insertions(+), 367 deletions(-)
diff --git a/config/llvm.m4 b/config/llvm.m4
index 3a75cd8b4d..a99f29ffdc 100644
--- a/config/llvm.m4
+++ b/config/llvm.m4
@@ -25,8 +25,8 @@ AC_DEFUN([PGAC_LLVM_SUPPORT],
AC_MSG_ERROR([$LLVM_CONFIG does not work])
fi
# and whether the version is supported
- if echo $pgac_llvm_version | $AWK -F '.' '{ if ([$]1 >= 4 || ([$]1 == 3 && [$]2 >= 9)) exit 1; else exit 0;}';then
- AC_MSG_ERROR([$LLVM_CONFIG version is $pgac_llvm_version but at least 3.9 is required])
+ if echo $pgac_llvm_version | $AWK -F '.' '{ if ([$]1 >= 14) exit 1; else exit 0;}';then
+ AC_MSG_ERROR([$LLVM_CONFIG version is $pgac_llvm_version but at least 14 is required])
fi
# need clang to create some bitcode files
@@ -114,8 +114,6 @@ AC_DEFUN([PGAC_CHECK_LLVM_FUNCTIONS],
# Check which functionality is present
SAVE_CPPFLAGS="$CPPFLAGS"
CPPFLAGS="$CPPFLAGS $LLVM_CPPFLAGS"
- AC_CHECK_DECLS([LLVMOrcGetSymbolAddressIn], [], [], [[#include <llvm-c/OrcBindings.h>]])
- AC_CHECK_DECLS([LLVMGetHostCPUName, LLVMGetHostCPUFeatures], [], [], [[#include <llvm-c/TargetMachine.h>]])
AC_CHECK_DECLS([LLVMCreateGDBRegistrationListener, LLVMCreatePerfJITEventListener], [], [], [[#include <llvm-c/ExecutionEngine.h>]])
CPPFLAGS="$SAVE_CPPFLAGS"
])# PGAC_CHECK_LLVM_FUNCTIONS
diff --git a/configure b/configure
index d47e0f8b26..f4a04485e1 100755
--- a/configure
+++ b/configure
@@ -5120,8 +5120,8 @@ fi
as_fn_error $? "$LLVM_CONFIG does not work" "$LINENO" 5
fi
# and whether the version is supported
- if echo $pgac_llvm_version | $AWK -F '.' '{ if ($1 >= 4 || ($1 == 3 && $2 >= 9)) exit 1; else exit 0;}';then
- as_fn_error $? "$LLVM_CONFIG version is $pgac_llvm_version but at least 3.9 is required" "$LINENO" 5
+ if echo $pgac_llvm_version | $AWK -F '.' '{ if ($1 >= 14) exit 1; else exit 0;}';then
+ as_fn_error $? "$LLVM_CONFIG version is $pgac_llvm_version but at least 14 is required" "$LINENO" 5
fi
# need clang to create some bitcode files
@@ -16571,41 +16571,6 @@ if test "$with_llvm" = yes; then
# Check which functionality is present
SAVE_CPPFLAGS="$CPPFLAGS"
CPPFLAGS="$CPPFLAGS $LLVM_CPPFLAGS"
- ac_fn_c_check_decl "$LINENO" "LLVMOrcGetSymbolAddressIn" "ac_cv_have_decl_LLVMOrcGetSymbolAddressIn" "#include <llvm-c/OrcBindings.h>
-"
-if test "x$ac_cv_have_decl_LLVMOrcGetSymbolAddressIn" = xyes; then :
- ac_have_decl=1
-else
- ac_have_decl=0
-fi
-
-cat >>confdefs.h <<_ACEOF
-#define HAVE_DECL_LLVMORCGETSYMBOLADDRESSIN $ac_have_decl
-_ACEOF
-
- ac_fn_c_check_decl "$LINENO" "LLVMGetHostCPUName" "ac_cv_have_decl_LLVMGetHostCPUName" "#include <llvm-c/TargetMachine.h>
-"
-if test "x$ac_cv_have_decl_LLVMGetHostCPUName" = xyes; then :
- ac_have_decl=1
-else
- ac_have_decl=0
-fi
-
-cat >>confdefs.h <<_ACEOF
-#define HAVE_DECL_LLVMGETHOSTCPUNAME $ac_have_decl
-_ACEOF
-ac_fn_c_check_decl "$LINENO" "LLVMGetHostCPUFeatures" "ac_cv_have_decl_LLVMGetHostCPUFeatures" "#include <llvm-c/TargetMachine.h>
-"
-if test "x$ac_cv_have_decl_LLVMGetHostCPUFeatures" = xyes; then :
- ac_have_decl=1
-else
- ac_have_decl=0
-fi
-
-cat >>confdefs.h <<_ACEOF
-#define HAVE_DECL_LLVMGETHOSTCPUFEATURES $ac_have_decl
-_ACEOF
-
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 :
diff --git a/doc/src/sgml/installation.sgml b/doc/src/sgml/installation.sgml
index f4b1f81189..20453ab586 100644
--- a/doc/src/sgml/installation.sgml
+++ b/doc/src/sgml/installation.sgml
@@ -965,7 +965,7 @@ build-postgresql:
linkend="jit"/>)</phrase>. This
requires the <productname>LLVM</productname> library to be installed.
The minimum required version of <productname>LLVM</productname> is
- currently 3.9.
+ currently 14.
</para>
<para>
<command>llvm-config</command><indexterm><primary>llvm-config</primary></indexterm>
@@ -2432,7 +2432,7 @@ ninja install
condition="standalone-ignore"> (see <xref linkend="jit"/>)</phrase>.
This requires the <productname>LLVM</productname> library to be
installed. The minimum required version of
- <productname>LLVM</productname> is currently 3.9. Disabled by
+ <productname>LLVM</productname> is currently 14. Disabled by
default.
</para>
diff --git a/meson.build b/meson.build
index 862c955453..4c12c60bb6 100644
--- a/meson.build
+++ b/meson.build
@@ -748,7 +748,7 @@ endif
llvmopt = get_option('llvm')
llvm = not_found_dep
if add_languages('cpp', required: llvmopt, native: false)
- llvm = dependency('llvm', version: '>=3.9', method: 'config-tool', required: llvmopt)
+ llvm = dependency('llvm', version: '>=14', method: 'config-tool', required: llvmopt)
if llvm.found()
diff --git a/src/backend/jit/llvm/llvmjit.c b/src/backend/jit/llvm/llvmjit.c
index 58f638859a..d31e4759a6 100644
--- a/src/backend/jit/llvm/llvmjit.c
+++ b/src/backend/jit/llvm/llvmjit.c
@@ -21,23 +21,17 @@
#if LLVM_VERSION_MAJOR > 16
#include <llvm-c/Transforms/PassBuilder.h>
#endif
-#if LLVM_VERSION_MAJOR > 11
#include <llvm-c/Orc.h>
#include <llvm-c/OrcEE.h>
#include <llvm-c/LLJIT.h>
-#else
-#include <llvm-c/OrcBindings.h>
-#endif
#include <llvm-c/Support.h>
#include <llvm-c/Target.h>
#if LLVM_VERSION_MAJOR < 17
#include <llvm-c/Transforms/IPO.h>
#include <llvm-c/Transforms/PassManagerBuilder.h>
#include <llvm-c/Transforms/Scalar.h>
-#if LLVM_VERSION_MAJOR > 6
#include <llvm-c/Transforms/Utils.h>
#endif
-#endif
#include "jit/llvmjit.h"
#include "jit/llvmjit_emit.h"
@@ -52,13 +46,8 @@
/* Handle of a module emitted via ORC JIT */
typedef struct LLVMJitHandle
{
-#if LLVM_VERSION_MAJOR > 11
LLVMOrcLLJITRef lljit;
LLVMOrcResourceTrackerRef resource_tracker;
-#else
- LLVMOrcJITStackRef stack;
- LLVMOrcModuleHandle orc_handle;
-#endif
} LLVMJitHandle;
@@ -105,14 +94,9 @@ static LLVMContextRef llvm_context;
static LLVMTargetRef llvm_targetref;
-#if LLVM_VERSION_MAJOR > 11
static LLVMOrcThreadSafeContextRef llvm_ts_context;
static LLVMOrcLLJITRef llvm_opt0_orc;
static LLVMOrcLLJITRef llvm_opt3_orc;
-#else /* LLVM_VERSION_MAJOR > 11 */
-static LLVMOrcJITStackRef llvm_opt0_orc;
-static LLVMOrcJITStackRef llvm_opt3_orc;
-#endif /* LLVM_VERSION_MAJOR > 11 */
static void llvm_release_context(JitContext *context);
@@ -126,10 +110,8 @@ static void llvm_set_target(void);
static void llvm_recreate_llvm_context(void);
static uint64_t llvm_resolve_symbol(const char *name, void *ctx);
-#if LLVM_VERSION_MAJOR > 11
static LLVMOrcLLJITRef llvm_create_jit_instance(LLVMTargetMachineRef tm);
static char *llvm_error_message(LLVMErrorRef error);
-#endif /* LLVM_VERSION_MAJOR > 11 */
PG_MODULE_MAGIC;
@@ -270,7 +252,6 @@ llvm_release_context(JitContext *context)
{
LLVMJitHandle *jit_handle = (LLVMJitHandle *) lfirst(lc);
-#if LLVM_VERSION_MAJOR > 11
{
LLVMOrcExecutionSessionRef ee;
LLVMOrcSymbolStringPoolRef sp;
@@ -288,11 +269,6 @@ llvm_release_context(JitContext *context)
sp = LLVMOrcExecutionSessionGetSymbolStringPool(ee);
LLVMOrcSymbolStringPoolClearDeadEntries(sp);
}
-#else /* LLVM_VERSION_MAJOR > 11 */
- {
- LLVMOrcRemoveModule(jit_handle->stack, jit_handle->orc_handle);
- }
-#endif /* LLVM_VERSION_MAJOR > 11 */
pfree(jit_handle);
}
@@ -354,10 +330,7 @@ llvm_expand_funcname(struct LLVMJitContext *context, const char *basename)
void *
llvm_get_function(LLVMJitContext *context, const char *funcname)
{
-#if LLVM_VERSION_MAJOR > 11 || \
- defined(HAVE_DECL_LLVMORCGETSYMBOLADDRESSIN) && HAVE_DECL_LLVMORCGETSYMBOLADDRESSIN
ListCell *lc;
-#endif
llvm_assert_in_fatal_section();
@@ -375,7 +348,6 @@ llvm_get_function(LLVMJitContext *context, const char *funcname)
* to mangle here.
*/
-#if LLVM_VERSION_MAJOR > 11
foreach(lc, context->handles)
{
LLVMJitHandle *handle = (LLVMJitHandle *) lfirst(lc);
@@ -405,41 +377,6 @@ llvm_get_function(LLVMJitContext *context, const char *funcname)
if (addr)
return (void *) (uintptr_t) addr;
}
-#elif defined(HAVE_DECL_LLVMORCGETSYMBOLADDRESSIN) && HAVE_DECL_LLVMORCGETSYMBOLADDRESSIN
- foreach(lc, context->handles)
- {
- LLVMOrcTargetAddress addr;
- LLVMJitHandle *handle = (LLVMJitHandle *) lfirst(lc);
-
- addr = 0;
- if (LLVMOrcGetSymbolAddressIn(handle->stack, &addr, handle->orc_handle, funcname))
- elog(ERROR, "failed to look up symbol \"%s\"", funcname);
- if (addr)
- return (void *) (uintptr_t) addr;
- }
-#elif LLVM_VERSION_MAJOR < 5
- {
- LLVMOrcTargetAddress addr;
-
- if ((addr = LLVMOrcGetSymbolAddress(llvm_opt0_orc, funcname)))
- return (void *) (uintptr_t) addr;
- if ((addr = LLVMOrcGetSymbolAddress(llvm_opt3_orc, funcname)))
- return (void *) (uintptr_t) addr;
- }
-#else
- {
- LLVMOrcTargetAddress addr;
-
- if (LLVMOrcGetSymbolAddress(llvm_opt0_orc, &addr, funcname))
- elog(ERROR, "failed to look up symbol \"%s\"", funcname);
- if (addr)
- return (void *) (uintptr_t) addr;
- if (LLVMOrcGetSymbolAddress(llvm_opt3_orc, &addr, funcname))
- elog(ERROR, "failed to look up symbol \"%s\"", funcname);
- if (addr)
- return (void *) (uintptr_t) addr;
- }
-#endif
elog(ERROR, "failed to JIT: %s", funcname);
@@ -526,7 +463,7 @@ llvm_copy_attributes_at_index(LLVMValueRef v_from, LLVMValueRef v_to, uint32 ind
int num_attributes;
LLVMAttributeRef *attrs;
- num_attributes = LLVMGetAttributeCountAtIndexPG(v_from, index);
+ num_attributes = LLVMGetAttributeCountAtIndex(v_from, index);
/*
* Not just for efficiency: LLVM <= 3.9 crashes when
@@ -736,11 +673,7 @@ llvm_compile_module(LLVMJitContext *context)
MemoryContext oldcontext;
instr_time starttime;
instr_time endtime;
-#if LLVM_VERSION_MAJOR > 11
LLVMOrcLLJITRef compile_orc;
-#else
- LLVMOrcJITStackRef compile_orc;
-#endif
if (context->base.flags & PGJIT_OPT3)
compile_orc = llvm_opt3_orc;
@@ -797,7 +730,6 @@ llvm_compile_module(LLVMJitContext *context)
* faster instruction selection mechanism is used.
*/
INSTR_TIME_SET_CURRENT(starttime);
-#if LLVM_VERSION_MAJOR > 11
{
LLVMOrcThreadSafeModuleRef ts_module;
LLVMErrorRef error;
@@ -825,36 +757,6 @@ llvm_compile_module(LLVMJitContext *context)
/* LLVMOrcLLJITAddLLVMIRModuleWithRT takes ownership of the module */
}
-#elif LLVM_VERSION_MAJOR > 6
- {
- handle->stack = compile_orc;
- if (LLVMOrcAddEagerlyCompiledIR(compile_orc, &handle->orc_handle, context->module,
- llvm_resolve_symbol, NULL))
- elog(ERROR, "failed to JIT module");
-
- /* LLVMOrcAddEagerlyCompiledIR takes ownership of the module */
- }
-#elif LLVM_VERSION_MAJOR > 4
- {
- LLVMSharedModuleRef smod;
-
- smod = LLVMOrcMakeSharedModule(context->module);
- handle->stack = compile_orc;
- if (LLVMOrcAddEagerlyCompiledIR(compile_orc, &handle->orc_handle, smod,
- llvm_resolve_symbol, NULL))
- elog(ERROR, "failed to JIT module");
-
- LLVMOrcDisposeSharedModuleRef(smod);
- }
-#else /* LLVM 4.0 and 3.9 */
- {
- handle->stack = compile_orc;
- handle->orc_handle = LLVMOrcAddEagerlyCompiledIR(compile_orc, context->module,
- llvm_resolve_symbol, NULL);
-
- LLVMDisposeModule(context->module);
- }
-#endif
INSTR_TIME_SET_CURRENT(endtime);
INSTR_TIME_ACCUM_DIFF(context->base.instr.emission_counter,
@@ -966,7 +868,6 @@ llvm_session_initialize(void)
/* force symbols in main binary to be loaded */
LLVMLoadLibraryPermanently(NULL);
-#if LLVM_VERSION_MAJOR > 11
{
llvm_ts_context = LLVMOrcCreateNewThreadSafeContext();
@@ -976,31 +877,6 @@ llvm_session_initialize(void)
llvm_opt3_orc = llvm_create_jit_instance(opt3_tm);
opt3_tm = 0;
}
-#else /* LLVM_VERSION_MAJOR > 11 */
- {
- llvm_opt0_orc = LLVMOrcCreateInstance(opt0_tm);
- llvm_opt3_orc = LLVMOrcCreateInstance(opt3_tm);
-
-#if defined(HAVE_DECL_LLVMCREATEGDBREGISTRATIONLISTENER) && HAVE_DECL_LLVMCREATEGDBREGISTRATIONLISTENER
- if (jit_debugging_support)
- {
- LLVMJITEventListenerRef l = LLVMCreateGDBRegistrationListener();
-
- LLVMOrcRegisterJITEventListener(llvm_opt0_orc, l);
- LLVMOrcRegisterJITEventListener(llvm_opt3_orc, l);
- }
-#endif
-#if defined(HAVE_DECL_LLVMCREATEPERFJITEVENTLISTENER) && HAVE_DECL_LLVMCREATEPERFJITEVENTLISTENER
- if (jit_profiling_support)
- {
- LLVMJITEventListenerRef l = LLVMCreatePerfJITEventListener();
-
- LLVMOrcRegisterJITEventListener(llvm_opt0_orc, l);
- LLVMOrcRegisterJITEventListener(llvm_opt3_orc, l);
- }
-#endif
- }
-#endif /* LLVM_VERSION_MAJOR > 11 */
on_proc_exit(llvm_shutdown, 0);
@@ -1030,7 +906,6 @@ llvm_shutdown(int code, Datum arg)
elog(PANIC, "LLVMJitContext in use count not 0 at exit (is %zu)",
llvm_jit_context_in_use_count);
-#if LLVM_VERSION_MAJOR > 11
{
if (llvm_opt3_orc)
{
@@ -1048,31 +923,6 @@ llvm_shutdown(int code, Datum arg)
llvm_ts_context = NULL;
}
}
-#else /* LLVM_VERSION_MAJOR > 11 */
- {
- /* 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;
- }
- }
-#endif /* LLVM_VERSION_MAJOR > 11 */
}
/* helper for llvm_create_types, returning a function's return type */
@@ -1242,8 +1092,6 @@ llvm_resolve_symbol(const char *symname, void *ctx)
return (uint64_t) addr;
}
-#if LLVM_VERSION_MAJOR > 11
-
static LLVMErrorRef
llvm_resolve_symbols(LLVMOrcDefinitionGeneratorRef GeneratorObj, void *Ctx,
LLVMOrcLookupStateRef *LookupState, LLVMOrcLookupKind Kind,
@@ -1262,9 +1110,7 @@ llvm_resolve_symbols(LLVMOrcDefinitionGeneratorRef GeneratorObj, void *Ctx,
{
const char *name = LLVMOrcSymbolStringPoolEntryStr(LookupSet[i].Name);
-#if LLVM_VERSION_MAJOR > 12
LLVMOrcRetainSymbolStringPoolEntry(LookupSet[i].Name);
-#endif
symbols[i].Name = LookupSet[i].Name;
symbols[i].Sym.Address = llvm_resolve_symbol(name, NULL);
symbols[i].Sym.Flags.GenericFlags = LLVMJITSymbolGenericFlagsExported;
@@ -1392,5 +1238,3 @@ llvm_error_message(LLVMErrorRef error)
return msg;
}
-
-#endif /* LLVM_VERSION_MAJOR > 11 */
diff --git a/src/backend/jit/llvm/llvmjit_error.cpp b/src/backend/jit/llvm/llvmjit_error.cpp
index ea40f5a124..bcf51f12a9 100644
--- a/src/backend/jit/llvm/llvmjit_error.cpp
+++ b/src/backend/jit/llvm/llvmjit_error.cpp
@@ -29,16 +29,8 @@ static int fatal_new_handler_depth = 0;
static std::new_handler old_new_handler = NULL;
static void fatal_system_new_handler(void);
-#if LLVM_VERSION_MAJOR > 4
static void fatal_llvm_new_handler(void *user_data, const char *reason, bool gen_crash_diag);
-#if LLVM_VERSION_MAJOR < 14
-static void fatal_llvm_new_handler(void *user_data, const std::string& reason, bool gen_crash_diag);
-#endif
-#endif
static void fatal_llvm_error_handler(void *user_data, const char *reason, bool gen_crash_diag);
-#if LLVM_VERSION_MAJOR < 14
-static void fatal_llvm_error_handler(void *user_data, const std::string& reason, bool gen_crash_diag);
-#endif
/*
@@ -65,9 +57,7 @@ llvm_enter_fatal_on_oom(void)
if (fatal_new_handler_depth == 0)
{
old_new_handler = std::set_new_handler(fatal_system_new_handler);
-#if LLVM_VERSION_MAJOR > 4
llvm::install_bad_alloc_error_handler(fatal_llvm_new_handler);
-#endif
llvm::install_fatal_error_handler(fatal_llvm_error_handler);
}
fatal_new_handler_depth++;
@@ -83,9 +73,7 @@ llvm_leave_fatal_on_oom(void)
if (fatal_new_handler_depth == 0)
{
std::set_new_handler(old_new_handler);
-#if LLVM_VERSION_MAJOR > 4
llvm::remove_bad_alloc_error_handler();
-#endif
llvm::remove_fatal_error_handler();
}
}
@@ -110,9 +98,7 @@ llvm_reset_after_error(void)
if (fatal_new_handler_depth != 0)
{
std::set_new_handler(old_new_handler);
-#if LLVM_VERSION_MAJOR > 4
llvm::remove_bad_alloc_error_handler();
-#endif
llvm::remove_fatal_error_handler();
}
fatal_new_handler_depth = 0;
@@ -133,7 +119,6 @@ fatal_system_new_handler(void)
errdetail("while in LLVM")));
}
-#if LLVM_VERSION_MAJOR > 4
static void
fatal_llvm_new_handler(void *user_data,
const char *reason,
@@ -144,16 +129,6 @@ fatal_llvm_new_handler(void *user_data,
errmsg("out of memory"),
errdetail("While in LLVM: %s", reason)));
}
-#if LLVM_VERSION_MAJOR < 14
-static void
-fatal_llvm_new_handler(void *user_data,
- const std::string& reason,
- bool gen_crash_diag)
-{
- fatal_llvm_new_handler(user_data, reason.c_str(), gen_crash_diag);
-}
-#endif
-#endif
static void
fatal_llvm_error_handler(void *user_data,
@@ -164,13 +139,3 @@ fatal_llvm_error_handler(void *user_data,
(errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("fatal llvm error: %s", reason)));
}
-
-#if LLVM_VERSION_MAJOR < 14
-static void
-fatal_llvm_error_handler(void *user_data,
- const std::string& reason,
- bool gen_crash_diag)
-{
- fatal_llvm_error_handler(user_data, reason.c_str(), gen_crash_diag);
-}
-#endif
diff --git a/src/backend/jit/llvm/llvmjit_expr.c b/src/backend/jit/llvm/llvmjit_expr.c
index a3a0876bff..a950564afa 100644
--- a/src/backend/jit/llvm/llvmjit_expr.c
+++ b/src/backend/jit/llvm/llvmjit_expr.c
@@ -2644,12 +2644,8 @@ create_LifetimeEnd(LLVMModuleRef mod)
LLVMTypeRef param_types[2];
LLVMContextRef lc;
- /* LLVM 5+ has a variadic pointer argument */
-#if LLVM_VERSION_MAJOR < 5
- const char *nm = "llvm.lifetime.end";
-#else
+ /* variadic pointer argument */
const char *nm = "llvm.lifetime.end.p0i8";
-#endif
fn = LLVMGetNamedFunction(mod, nm);
if (fn)
diff --git a/src/backend/jit/llvm/llvmjit_inline.cpp b/src/backend/jit/llvm/llvmjit_inline.cpp
index d92d7f3c88..693bc6510b 100644
--- a/src/backend/jit/llvm/llvmjit_inline.cpp
+++ b/src/backend/jit/llvm/llvmjit_inline.cpp
@@ -49,12 +49,7 @@ extern "C"
#include <llvm/ADT/StringSet.h>
#include <llvm/ADT/StringMap.h>
#include <llvm/Analysis/ModuleSummaryAnalysis.h>
-#if LLVM_VERSION_MAJOR > 3
#include <llvm/Bitcode/BitcodeReader.h>
-#else
-#include <llvm/Bitcode/ReaderWriter.h>
-#include <llvm/Support/Error.h>
-#endif
#include <llvm/IR/Attributes.h>
#include <llvm/IR/DebugInfo.h>
#include <llvm/IR/IntrinsicInst.h>
@@ -267,14 +262,12 @@ llvm_build_inline_plan(LLVMContextRef lc, llvm::Module *mod)
fs = llvm::cast<llvm::FunctionSummary>(gvs);
-#if LLVM_VERSION_MAJOR > 3
if (gvs->notEligibleToImport())
{
ilog(DEBUG1, "ineligibile to import %s due to summary",
symbolName.data());
continue;
}
-#endif
if ((int) fs->instCount() > inlineState.costLimit)
{
@@ -458,16 +451,9 @@ llvm_execute_inline_plan(llvm::Module *mod, ImportMapTy *globalsToInline)
}
-#if LLVM_VERSION_MAJOR > 4
-#define IRMOVE_PARAMS , /*IsPerformingImport=*/false
-#elif LLVM_VERSION_MAJOR > 3
-#define IRMOVE_PARAMS , /*LinkModuleInlineAsm=*/false, /*IsPerformingImport=*/false
-#else
-#define IRMOVE_PARAMS
-#endif
if (Mover.move(std::move(importMod), GlobalsToImport.getArrayRef(),
- [](llvm::GlobalValue &, llvm::IRMover::ValueAdder) {}
- IRMOVE_PARAMS))
+ [](llvm::GlobalValue &, llvm::IRMover::ValueAdder) {},
+ /*IsPerformingImport=*/false))
elog(FATAL, "function import failed with linker error");
}
}
@@ -608,10 +594,6 @@ function_inlinable(llvm::Function &F,
if (F.materialize())
elog(FATAL, "failed to materialize metadata");
-#if LLVM_VERSION_MAJOR < 14
-#define hasFnAttr hasFnAttribute
-#endif
-
if (F.getAttributes().hasFnAttr(llvm::Attribute::NoInline))
{
ilog(DEBUG1, "ineligibile to import %s due to noinline",
@@ -793,7 +775,6 @@ llvm_load_summary(llvm::StringRef path)
{
llvm::MemoryBufferRef ref(*MBOrErr.get().get());
-#if LLVM_VERSION_MAJOR > 3
llvm::Expected<std::unique_ptr<llvm::ModuleSummaryIndex> > IndexOrErr =
llvm::getModuleSummaryIndex(ref);
if (IndexOrErr)
@@ -801,15 +782,6 @@ llvm_load_summary(llvm::StringRef path)
elog(FATAL, "failed to load summary \"%s\": %s",
path.data(),
toString(IndexOrErr.takeError()).c_str());
-#else
- llvm::ErrorOr<std::unique_ptr<llvm::ModuleSummaryIndex> > IndexOrErr =
- llvm::getModuleSummaryIndex(ref, [](const llvm::DiagnosticInfo &) {});
- if (IndexOrErr)
- return std::move(IndexOrErr.get());
- elog(FATAL, "failed to load summary \"%s\": %s",
- path.data(),
- IndexOrErr.getError().message().c_str());
-#endif
}
return nullptr;
}
@@ -853,22 +825,12 @@ summaries_for_guid(const InlineSearchPath& path, llvm::GlobalValue::GUID guid)
for (auto index : path)
{
-#if LLVM_VERSION_MAJOR > 4
llvm::ValueInfo funcVI = index->getValueInfo(guid);
/* if index doesn't know function, we don't have a body, continue */
if (funcVI)
for (auto &gv : funcVI.getSummaryList())
matches.push_back(gv.get());
-#else
- const llvm::const_gvsummary_iterator &I =
- index->findGlobalValueSummaryList(guid);
- if (I != index->end())
- {
- for (auto &gv : I->second)
- matches.push_back(gv.get());
- }
-#endif
}
return matches;
@@ -889,9 +851,6 @@ create_redirection_function(std::unique_ptr<llvm::Module> &importMod,
llvm::Function *AF;
llvm::BasicBlock *BB;
llvm::CallInst *fwdcall;
-#if LLVM_VERSION_MAJOR < 14
- llvm::Attribute inlineAttribute;
-#endif
AF = llvm::Function::Create(F->getFunctionType(),
LinkageTypes::AvailableExternallyLinkage,
@@ -900,13 +859,7 @@ create_redirection_function(std::unique_ptr<llvm::Module> &importMod,
Builder.SetInsertPoint(BB);
fwdcall = Builder.CreateCall(F, &*AF->arg_begin());
-#if LLVM_VERSION_MAJOR < 14
- inlineAttribute = llvm::Attribute::get(Context,
- llvm::Attribute::AlwaysInline);
- fwdcall->addAttribute(~0U, inlineAttribute);
-#else
fwdcall->addFnAttr(llvm::Attribute::AlwaysInline);
-#endif
Builder.CreateRet(fwdcall);
return AF;
diff --git a/src/backend/jit/llvm/llvmjit_wrap.cpp b/src/backend/jit/llvm/llvmjit_wrap.cpp
index 90a41b9191..52ce09c981 100644
--- a/src/backend/jit/llvm/llvmjit_wrap.cpp
+++ b/src/backend/jit/llvm/llvmjit_wrap.cpp
@@ -19,18 +19,9 @@ extern "C"
#include <llvm-c/Core.h>
/* Avoid macro clash with LLVM's C++ headers */
-#undef Min
+//#undef Min
-#include <llvm/IR/Attributes.h>
#include <llvm/IR/Function.h>
-#if LLVM_VERSION_MAJOR < 17
-#include <llvm/MC/SubtargetFeature.h>
-#endif
-#if LLVM_VERSION_MAJOR > 16
-#include <llvm/TargetParser/Host.h>
-#else
-#include <llvm/Support/Host.h>
-#endif
#include "jit/llvmjit.h"
@@ -38,50 +29,6 @@ extern "C"
/*
* C-API extensions.
*/
-#if defined(HAVE_DECL_LLVMGETHOSTCPUNAME) && !HAVE_DECL_LLVMGETHOSTCPUNAME
-char *LLVMGetHostCPUName(void) {
- return strdup(llvm::sys::getHostCPUName().data());
-}
-#endif
-
-
-#if defined(HAVE_DECL_LLVMGETHOSTCPUFEATURES) && !HAVE_DECL_LLVMGETHOSTCPUFEATURES
-char *LLVMGetHostCPUFeatures(void) {
- llvm::SubtargetFeatures Features;
- llvm::StringMap<bool> HostFeatures;
-
- if (llvm::sys::getHostCPUFeatures(HostFeatures))
- for (auto &F : HostFeatures)
- Features.AddFeature(F.first(), F.second);
-
- return strdup(Features.getString().c_str());
-}
-#endif
-
-/*
- * Like LLVM's LLVMGetAttributeCountAtIndex(), works around a bug in LLVM 3.9.
- *
- * In LLVM <= 3.9, LLVMGetAttributeCountAtIndex() segfaults if there are no
- * attributes at an index (fixed in LLVM commit ce9bb1097dc2).
- */
-unsigned
-LLVMGetAttributeCountAtIndexPG(LLVMValueRef F, uint32 Idx)
-{
- /*
- * This is more expensive, so only do when using a problematic LLVM
- * version.
- */
-#if LLVM_VERSION_MAJOR < 4
- if (!llvm::unwrap<llvm::Function>(F)->getAttributes().hasAttributes(Idx))
- return 0;
-#endif
-
- /*
- * There is no nice public API to determine the count nicely, so just
- * always fall back to LLVM's C API.
- */
- return LLVMGetAttributeCountAtIndex(F, Idx);
-}
LLVMTypeRef
LLVMGetFunctionReturnType(LLVMValueRef r)
@@ -94,11 +41,3 @@ LLVMGetFunctionType(LLVMValueRef r)
{
return llvm::wrap(llvm::unwrap<llvm::Function>(r)->getFunctionType());
}
-
-#if LLVM_VERSION_MAJOR < 8
-LLVMTypeRef
-LLVMGlobalGetValueType(LLVMValueRef g)
-{
- return llvm::wrap(llvm::unwrap<llvm::GlobalValue>(g)->getValueType());
-}
-#endif
diff --git a/src/include/pg_config.h.in b/src/include/pg_config.h.in
index d8a2985567..481470ee59 100644
--- a/src/include/pg_config.h.in
+++ b/src/include/pg_config.h.in
@@ -103,18 +103,6 @@
`LLVMCreatePerfJITEventListener', and to 0 if you don't. */
#undef HAVE_DECL_LLVMCREATEPERFJITEVENTLISTENER
-/* Define to 1 if you have the declaration of `LLVMGetHostCPUFeatures', and to
- 0 if you don't. */
-#undef HAVE_DECL_LLVMGETHOSTCPUFEATURES
-
-/* Define to 1 if you have the declaration of `LLVMGetHostCPUName', and to 0
- if you don't. */
-#undef HAVE_DECL_LLVMGETHOSTCPUNAME
-
-/* Define to 1 if you have the declaration of `LLVMOrcGetSymbolAddressIn', and
- to 0 if you don't. */
-#undef HAVE_DECL_LLVMORCGETSYMBOLADDRESSIN
-
/* 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/tools/msvc/Solution.pm b/src/tools/msvc/Solution.pm
index a50f730260..5066bd9e28 100644
--- a/src/tools/msvc/Solution.pm
+++ b/src/tools/msvc/Solution.pm
@@ -235,9 +235,6 @@ sub GenerateFiles
HAVE_DECL_F_FULLFSYNC => 0,
HAVE_DECL_LLVMCREATEGDBREGISTRATIONLISTENER => 0,
HAVE_DECL_LLVMCREATEPERFJITEVENTLISTENER => 0,
- HAVE_DECL_LLVMGETHOSTCPUNAME => 0,
- HAVE_DECL_LLVMGETHOSTCPUFEATURES => 0,
- HAVE_DECL_LLVMORCGETSYMBOLADDRESSIN => 0,
HAVE_DECL_POSIX_FADVISE => 0,
HAVE_DECL_PREADV => 0,
HAVE_DECL_PWRITEV => 0,
--
2.39.3 (Apple Git-145)
We could go further. With LLVM 14 as the minimum we can just use
opaque pointers everywhere, and delete more conditional code in
master. Tested on 14-18.
I explored using the new pass manager everywhere too. It almost
worked, but I couldn't see how to override the inlining threshold
before LLVM 16[1]https://github.com/llvm/llvm-project/commit/4fa328074efd7eefdbb314b8f6e9f855e443ca20, even in C++, so we couldn't fix that with a
llvmjit_wrap.cpp hack.
I like this. How can I find out if someone would shout at me for
dropping LLVM 13?
[1]: https://github.com/llvm/llvm-project/commit/4fa328074efd7eefdbb314b8f6e9f855e443ca20
Attachments:
v2-0001-jit-Require-at-least-LLVM-14-if-enabled.patchtext/x-patch; charset=US-ASCII; name=v2-0001-jit-Require-at-least-LLVM-14-if-enabled.patchDownload
From dd6005de803fb621cf1e21d9d7d31589e903e35b Mon Sep 17 00:00:00 2001
From: Thomas Munro <thomas.munro@gmail.com>
Date: Thu, 19 Oct 2023 04:45:46 +1300
Subject: [PATCH v2 1/2] jit: Require at least LLVM 14, if enabled.
Remove support for a lot of older LLVM versions dating back to 3.9. The
default on common software distritbutions will be at least LLVM 14 when
PostgreSQL 17 ships.
Discussion: https://postgr.es/m/CA%2BhUKGLhNs5geZaVNj2EJ79Dx9W8fyWUU3HxcpZy55sMGcY%3DiA%40mail.gmail.com
---
config/llvm.m4 | 6 +-
configure | 39 +-----
doc/src/sgml/installation.sgml | 4 +-
meson.build | 2 +-
src/backend/jit/llvm/llvmjit.c | 158 +-----------------------
src/backend/jit/llvm/llvmjit_error.cpp | 35 ------
src/backend/jit/llvm/llvmjit_expr.c | 6 +-
src/backend/jit/llvm/llvmjit_inline.cpp | 51 +-------
src/backend/jit/llvm/llvmjit_wrap.cpp | 65 ----------
src/include/jit/llvmjit.h | 17 ---
src/include/pg_config.h.in | 12 --
src/tools/msvc/Solution.pm | 3 -
12 files changed, 11 insertions(+), 387 deletions(-)
diff --git a/config/llvm.m4 b/config/llvm.m4
index 3a75cd8b4d..a99f29ffdc 100644
--- a/config/llvm.m4
+++ b/config/llvm.m4
@@ -25,8 +25,8 @@ AC_DEFUN([PGAC_LLVM_SUPPORT],
AC_MSG_ERROR([$LLVM_CONFIG does not work])
fi
# and whether the version is supported
- if echo $pgac_llvm_version | $AWK -F '.' '{ if ([$]1 >= 4 || ([$]1 == 3 && [$]2 >= 9)) exit 1; else exit 0;}';then
- AC_MSG_ERROR([$LLVM_CONFIG version is $pgac_llvm_version but at least 3.9 is required])
+ if echo $pgac_llvm_version | $AWK -F '.' '{ if ([$]1 >= 14) exit 1; else exit 0;}';then
+ AC_MSG_ERROR([$LLVM_CONFIG version is $pgac_llvm_version but at least 14 is required])
fi
# need clang to create some bitcode files
@@ -114,8 +114,6 @@ AC_DEFUN([PGAC_CHECK_LLVM_FUNCTIONS],
# Check which functionality is present
SAVE_CPPFLAGS="$CPPFLAGS"
CPPFLAGS="$CPPFLAGS $LLVM_CPPFLAGS"
- AC_CHECK_DECLS([LLVMOrcGetSymbolAddressIn], [], [], [[#include <llvm-c/OrcBindings.h>]])
- AC_CHECK_DECLS([LLVMGetHostCPUName, LLVMGetHostCPUFeatures], [], [], [[#include <llvm-c/TargetMachine.h>]])
AC_CHECK_DECLS([LLVMCreateGDBRegistrationListener, LLVMCreatePerfJITEventListener], [], [], [[#include <llvm-c/ExecutionEngine.h>]])
CPPFLAGS="$SAVE_CPPFLAGS"
])# PGAC_CHECK_LLVM_FUNCTIONS
diff --git a/configure b/configure
index d47e0f8b26..f4a04485e1 100755
--- a/configure
+++ b/configure
@@ -5120,8 +5120,8 @@ fi
as_fn_error $? "$LLVM_CONFIG does not work" "$LINENO" 5
fi
# and whether the version is supported
- if echo $pgac_llvm_version | $AWK -F '.' '{ if ($1 >= 4 || ($1 == 3 && $2 >= 9)) exit 1; else exit 0;}';then
- as_fn_error $? "$LLVM_CONFIG version is $pgac_llvm_version but at least 3.9 is required" "$LINENO" 5
+ if echo $pgac_llvm_version | $AWK -F '.' '{ if ($1 >= 14) exit 1; else exit 0;}';then
+ as_fn_error $? "$LLVM_CONFIG version is $pgac_llvm_version but at least 14 is required" "$LINENO" 5
fi
# need clang to create some bitcode files
@@ -16571,41 +16571,6 @@ if test "$with_llvm" = yes; then
# Check which functionality is present
SAVE_CPPFLAGS="$CPPFLAGS"
CPPFLAGS="$CPPFLAGS $LLVM_CPPFLAGS"
- ac_fn_c_check_decl "$LINENO" "LLVMOrcGetSymbolAddressIn" "ac_cv_have_decl_LLVMOrcGetSymbolAddressIn" "#include <llvm-c/OrcBindings.h>
-"
-if test "x$ac_cv_have_decl_LLVMOrcGetSymbolAddressIn" = xyes; then :
- ac_have_decl=1
-else
- ac_have_decl=0
-fi
-
-cat >>confdefs.h <<_ACEOF
-#define HAVE_DECL_LLVMORCGETSYMBOLADDRESSIN $ac_have_decl
-_ACEOF
-
- ac_fn_c_check_decl "$LINENO" "LLVMGetHostCPUName" "ac_cv_have_decl_LLVMGetHostCPUName" "#include <llvm-c/TargetMachine.h>
-"
-if test "x$ac_cv_have_decl_LLVMGetHostCPUName" = xyes; then :
- ac_have_decl=1
-else
- ac_have_decl=0
-fi
-
-cat >>confdefs.h <<_ACEOF
-#define HAVE_DECL_LLVMGETHOSTCPUNAME $ac_have_decl
-_ACEOF
-ac_fn_c_check_decl "$LINENO" "LLVMGetHostCPUFeatures" "ac_cv_have_decl_LLVMGetHostCPUFeatures" "#include <llvm-c/TargetMachine.h>
-"
-if test "x$ac_cv_have_decl_LLVMGetHostCPUFeatures" = xyes; then :
- ac_have_decl=1
-else
- ac_have_decl=0
-fi
-
-cat >>confdefs.h <<_ACEOF
-#define HAVE_DECL_LLVMGETHOSTCPUFEATURES $ac_have_decl
-_ACEOF
-
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 :
diff --git a/doc/src/sgml/installation.sgml b/doc/src/sgml/installation.sgml
index f4b1f81189..20453ab586 100644
--- a/doc/src/sgml/installation.sgml
+++ b/doc/src/sgml/installation.sgml
@@ -965,7 +965,7 @@ build-postgresql:
linkend="jit"/>)</phrase>. This
requires the <productname>LLVM</productname> library to be installed.
The minimum required version of <productname>LLVM</productname> is
- currently 3.9.
+ currently 14.
</para>
<para>
<command>llvm-config</command><indexterm><primary>llvm-config</primary></indexterm>
@@ -2432,7 +2432,7 @@ ninja install
condition="standalone-ignore"> (see <xref linkend="jit"/>)</phrase>.
This requires the <productname>LLVM</productname> library to be
installed. The minimum required version of
- <productname>LLVM</productname> is currently 3.9. Disabled by
+ <productname>LLVM</productname> is currently 14. Disabled by
default.
</para>
diff --git a/meson.build b/meson.build
index 862c955453..4c12c60bb6 100644
--- a/meson.build
+++ b/meson.build
@@ -748,7 +748,7 @@ endif
llvmopt = get_option('llvm')
llvm = not_found_dep
if add_languages('cpp', required: llvmopt, native: false)
- llvm = dependency('llvm', version: '>=3.9', method: 'config-tool', required: llvmopt)
+ llvm = dependency('llvm', version: '>=14', method: 'config-tool', required: llvmopt)
if llvm.found()
diff --git a/src/backend/jit/llvm/llvmjit.c b/src/backend/jit/llvm/llvmjit.c
index 58f638859a..d31e4759a6 100644
--- a/src/backend/jit/llvm/llvmjit.c
+++ b/src/backend/jit/llvm/llvmjit.c
@@ -21,23 +21,17 @@
#if LLVM_VERSION_MAJOR > 16
#include <llvm-c/Transforms/PassBuilder.h>
#endif
-#if LLVM_VERSION_MAJOR > 11
#include <llvm-c/Orc.h>
#include <llvm-c/OrcEE.h>
#include <llvm-c/LLJIT.h>
-#else
-#include <llvm-c/OrcBindings.h>
-#endif
#include <llvm-c/Support.h>
#include <llvm-c/Target.h>
#if LLVM_VERSION_MAJOR < 17
#include <llvm-c/Transforms/IPO.h>
#include <llvm-c/Transforms/PassManagerBuilder.h>
#include <llvm-c/Transforms/Scalar.h>
-#if LLVM_VERSION_MAJOR > 6
#include <llvm-c/Transforms/Utils.h>
#endif
-#endif
#include "jit/llvmjit.h"
#include "jit/llvmjit_emit.h"
@@ -52,13 +46,8 @@
/* Handle of a module emitted via ORC JIT */
typedef struct LLVMJitHandle
{
-#if LLVM_VERSION_MAJOR > 11
LLVMOrcLLJITRef lljit;
LLVMOrcResourceTrackerRef resource_tracker;
-#else
- LLVMOrcJITStackRef stack;
- LLVMOrcModuleHandle orc_handle;
-#endif
} LLVMJitHandle;
@@ -105,14 +94,9 @@ static LLVMContextRef llvm_context;
static LLVMTargetRef llvm_targetref;
-#if LLVM_VERSION_MAJOR > 11
static LLVMOrcThreadSafeContextRef llvm_ts_context;
static LLVMOrcLLJITRef llvm_opt0_orc;
static LLVMOrcLLJITRef llvm_opt3_orc;
-#else /* LLVM_VERSION_MAJOR > 11 */
-static LLVMOrcJITStackRef llvm_opt0_orc;
-static LLVMOrcJITStackRef llvm_opt3_orc;
-#endif /* LLVM_VERSION_MAJOR > 11 */
static void llvm_release_context(JitContext *context);
@@ -126,10 +110,8 @@ static void llvm_set_target(void);
static void llvm_recreate_llvm_context(void);
static uint64_t llvm_resolve_symbol(const char *name, void *ctx);
-#if LLVM_VERSION_MAJOR > 11
static LLVMOrcLLJITRef llvm_create_jit_instance(LLVMTargetMachineRef tm);
static char *llvm_error_message(LLVMErrorRef error);
-#endif /* LLVM_VERSION_MAJOR > 11 */
PG_MODULE_MAGIC;
@@ -270,7 +252,6 @@ llvm_release_context(JitContext *context)
{
LLVMJitHandle *jit_handle = (LLVMJitHandle *) lfirst(lc);
-#if LLVM_VERSION_MAJOR > 11
{
LLVMOrcExecutionSessionRef ee;
LLVMOrcSymbolStringPoolRef sp;
@@ -288,11 +269,6 @@ llvm_release_context(JitContext *context)
sp = LLVMOrcExecutionSessionGetSymbolStringPool(ee);
LLVMOrcSymbolStringPoolClearDeadEntries(sp);
}
-#else /* LLVM_VERSION_MAJOR > 11 */
- {
- LLVMOrcRemoveModule(jit_handle->stack, jit_handle->orc_handle);
- }
-#endif /* LLVM_VERSION_MAJOR > 11 */
pfree(jit_handle);
}
@@ -354,10 +330,7 @@ llvm_expand_funcname(struct LLVMJitContext *context, const char *basename)
void *
llvm_get_function(LLVMJitContext *context, const char *funcname)
{
-#if LLVM_VERSION_MAJOR > 11 || \
- defined(HAVE_DECL_LLVMORCGETSYMBOLADDRESSIN) && HAVE_DECL_LLVMORCGETSYMBOLADDRESSIN
ListCell *lc;
-#endif
llvm_assert_in_fatal_section();
@@ -375,7 +348,6 @@ llvm_get_function(LLVMJitContext *context, const char *funcname)
* to mangle here.
*/
-#if LLVM_VERSION_MAJOR > 11
foreach(lc, context->handles)
{
LLVMJitHandle *handle = (LLVMJitHandle *) lfirst(lc);
@@ -405,41 +377,6 @@ llvm_get_function(LLVMJitContext *context, const char *funcname)
if (addr)
return (void *) (uintptr_t) addr;
}
-#elif defined(HAVE_DECL_LLVMORCGETSYMBOLADDRESSIN) && HAVE_DECL_LLVMORCGETSYMBOLADDRESSIN
- foreach(lc, context->handles)
- {
- LLVMOrcTargetAddress addr;
- LLVMJitHandle *handle = (LLVMJitHandle *) lfirst(lc);
-
- addr = 0;
- if (LLVMOrcGetSymbolAddressIn(handle->stack, &addr, handle->orc_handle, funcname))
- elog(ERROR, "failed to look up symbol \"%s\"", funcname);
- if (addr)
- return (void *) (uintptr_t) addr;
- }
-#elif LLVM_VERSION_MAJOR < 5
- {
- LLVMOrcTargetAddress addr;
-
- if ((addr = LLVMOrcGetSymbolAddress(llvm_opt0_orc, funcname)))
- return (void *) (uintptr_t) addr;
- if ((addr = LLVMOrcGetSymbolAddress(llvm_opt3_orc, funcname)))
- return (void *) (uintptr_t) addr;
- }
-#else
- {
- LLVMOrcTargetAddress addr;
-
- if (LLVMOrcGetSymbolAddress(llvm_opt0_orc, &addr, funcname))
- elog(ERROR, "failed to look up symbol \"%s\"", funcname);
- if (addr)
- return (void *) (uintptr_t) addr;
- if (LLVMOrcGetSymbolAddress(llvm_opt3_orc, &addr, funcname))
- elog(ERROR, "failed to look up symbol \"%s\"", funcname);
- if (addr)
- return (void *) (uintptr_t) addr;
- }
-#endif
elog(ERROR, "failed to JIT: %s", funcname);
@@ -526,7 +463,7 @@ llvm_copy_attributes_at_index(LLVMValueRef v_from, LLVMValueRef v_to, uint32 ind
int num_attributes;
LLVMAttributeRef *attrs;
- num_attributes = LLVMGetAttributeCountAtIndexPG(v_from, index);
+ num_attributes = LLVMGetAttributeCountAtIndex(v_from, index);
/*
* Not just for efficiency: LLVM <= 3.9 crashes when
@@ -736,11 +673,7 @@ llvm_compile_module(LLVMJitContext *context)
MemoryContext oldcontext;
instr_time starttime;
instr_time endtime;
-#if LLVM_VERSION_MAJOR > 11
LLVMOrcLLJITRef compile_orc;
-#else
- LLVMOrcJITStackRef compile_orc;
-#endif
if (context->base.flags & PGJIT_OPT3)
compile_orc = llvm_opt3_orc;
@@ -797,7 +730,6 @@ llvm_compile_module(LLVMJitContext *context)
* faster instruction selection mechanism is used.
*/
INSTR_TIME_SET_CURRENT(starttime);
-#if LLVM_VERSION_MAJOR > 11
{
LLVMOrcThreadSafeModuleRef ts_module;
LLVMErrorRef error;
@@ -825,36 +757,6 @@ llvm_compile_module(LLVMJitContext *context)
/* LLVMOrcLLJITAddLLVMIRModuleWithRT takes ownership of the module */
}
-#elif LLVM_VERSION_MAJOR > 6
- {
- handle->stack = compile_orc;
- if (LLVMOrcAddEagerlyCompiledIR(compile_orc, &handle->orc_handle, context->module,
- llvm_resolve_symbol, NULL))
- elog(ERROR, "failed to JIT module");
-
- /* LLVMOrcAddEagerlyCompiledIR takes ownership of the module */
- }
-#elif LLVM_VERSION_MAJOR > 4
- {
- LLVMSharedModuleRef smod;
-
- smod = LLVMOrcMakeSharedModule(context->module);
- handle->stack = compile_orc;
- if (LLVMOrcAddEagerlyCompiledIR(compile_orc, &handle->orc_handle, smod,
- llvm_resolve_symbol, NULL))
- elog(ERROR, "failed to JIT module");
-
- LLVMOrcDisposeSharedModuleRef(smod);
- }
-#else /* LLVM 4.0 and 3.9 */
- {
- handle->stack = compile_orc;
- handle->orc_handle = LLVMOrcAddEagerlyCompiledIR(compile_orc, context->module,
- llvm_resolve_symbol, NULL);
-
- LLVMDisposeModule(context->module);
- }
-#endif
INSTR_TIME_SET_CURRENT(endtime);
INSTR_TIME_ACCUM_DIFF(context->base.instr.emission_counter,
@@ -966,7 +868,6 @@ llvm_session_initialize(void)
/* force symbols in main binary to be loaded */
LLVMLoadLibraryPermanently(NULL);
-#if LLVM_VERSION_MAJOR > 11
{
llvm_ts_context = LLVMOrcCreateNewThreadSafeContext();
@@ -976,31 +877,6 @@ llvm_session_initialize(void)
llvm_opt3_orc = llvm_create_jit_instance(opt3_tm);
opt3_tm = 0;
}
-#else /* LLVM_VERSION_MAJOR > 11 */
- {
- llvm_opt0_orc = LLVMOrcCreateInstance(opt0_tm);
- llvm_opt3_orc = LLVMOrcCreateInstance(opt3_tm);
-
-#if defined(HAVE_DECL_LLVMCREATEGDBREGISTRATIONLISTENER) && HAVE_DECL_LLVMCREATEGDBREGISTRATIONLISTENER
- if (jit_debugging_support)
- {
- LLVMJITEventListenerRef l = LLVMCreateGDBRegistrationListener();
-
- LLVMOrcRegisterJITEventListener(llvm_opt0_orc, l);
- LLVMOrcRegisterJITEventListener(llvm_opt3_orc, l);
- }
-#endif
-#if defined(HAVE_DECL_LLVMCREATEPERFJITEVENTLISTENER) && HAVE_DECL_LLVMCREATEPERFJITEVENTLISTENER
- if (jit_profiling_support)
- {
- LLVMJITEventListenerRef l = LLVMCreatePerfJITEventListener();
-
- LLVMOrcRegisterJITEventListener(llvm_opt0_orc, l);
- LLVMOrcRegisterJITEventListener(llvm_opt3_orc, l);
- }
-#endif
- }
-#endif /* LLVM_VERSION_MAJOR > 11 */
on_proc_exit(llvm_shutdown, 0);
@@ -1030,7 +906,6 @@ llvm_shutdown(int code, Datum arg)
elog(PANIC, "LLVMJitContext in use count not 0 at exit (is %zu)",
llvm_jit_context_in_use_count);
-#if LLVM_VERSION_MAJOR > 11
{
if (llvm_opt3_orc)
{
@@ -1048,31 +923,6 @@ llvm_shutdown(int code, Datum arg)
llvm_ts_context = NULL;
}
}
-#else /* LLVM_VERSION_MAJOR > 11 */
- {
- /* 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;
- }
- }
-#endif /* LLVM_VERSION_MAJOR > 11 */
}
/* helper for llvm_create_types, returning a function's return type */
@@ -1242,8 +1092,6 @@ llvm_resolve_symbol(const char *symname, void *ctx)
return (uint64_t) addr;
}
-#if LLVM_VERSION_MAJOR > 11
-
static LLVMErrorRef
llvm_resolve_symbols(LLVMOrcDefinitionGeneratorRef GeneratorObj, void *Ctx,
LLVMOrcLookupStateRef *LookupState, LLVMOrcLookupKind Kind,
@@ -1262,9 +1110,7 @@ llvm_resolve_symbols(LLVMOrcDefinitionGeneratorRef GeneratorObj, void *Ctx,
{
const char *name = LLVMOrcSymbolStringPoolEntryStr(LookupSet[i].Name);
-#if LLVM_VERSION_MAJOR > 12
LLVMOrcRetainSymbolStringPoolEntry(LookupSet[i].Name);
-#endif
symbols[i].Name = LookupSet[i].Name;
symbols[i].Sym.Address = llvm_resolve_symbol(name, NULL);
symbols[i].Sym.Flags.GenericFlags = LLVMJITSymbolGenericFlagsExported;
@@ -1392,5 +1238,3 @@ llvm_error_message(LLVMErrorRef error)
return msg;
}
-
-#endif /* LLVM_VERSION_MAJOR > 11 */
diff --git a/src/backend/jit/llvm/llvmjit_error.cpp b/src/backend/jit/llvm/llvmjit_error.cpp
index ea40f5a124..bcf51f12a9 100644
--- a/src/backend/jit/llvm/llvmjit_error.cpp
+++ b/src/backend/jit/llvm/llvmjit_error.cpp
@@ -29,16 +29,8 @@ static int fatal_new_handler_depth = 0;
static std::new_handler old_new_handler = NULL;
static void fatal_system_new_handler(void);
-#if LLVM_VERSION_MAJOR > 4
static void fatal_llvm_new_handler(void *user_data, const char *reason, bool gen_crash_diag);
-#if LLVM_VERSION_MAJOR < 14
-static void fatal_llvm_new_handler(void *user_data, const std::string& reason, bool gen_crash_diag);
-#endif
-#endif
static void fatal_llvm_error_handler(void *user_data, const char *reason, bool gen_crash_diag);
-#if LLVM_VERSION_MAJOR < 14
-static void fatal_llvm_error_handler(void *user_data, const std::string& reason, bool gen_crash_diag);
-#endif
/*
@@ -65,9 +57,7 @@ llvm_enter_fatal_on_oom(void)
if (fatal_new_handler_depth == 0)
{
old_new_handler = std::set_new_handler(fatal_system_new_handler);
-#if LLVM_VERSION_MAJOR > 4
llvm::install_bad_alloc_error_handler(fatal_llvm_new_handler);
-#endif
llvm::install_fatal_error_handler(fatal_llvm_error_handler);
}
fatal_new_handler_depth++;
@@ -83,9 +73,7 @@ llvm_leave_fatal_on_oom(void)
if (fatal_new_handler_depth == 0)
{
std::set_new_handler(old_new_handler);
-#if LLVM_VERSION_MAJOR > 4
llvm::remove_bad_alloc_error_handler();
-#endif
llvm::remove_fatal_error_handler();
}
}
@@ -110,9 +98,7 @@ llvm_reset_after_error(void)
if (fatal_new_handler_depth != 0)
{
std::set_new_handler(old_new_handler);
-#if LLVM_VERSION_MAJOR > 4
llvm::remove_bad_alloc_error_handler();
-#endif
llvm::remove_fatal_error_handler();
}
fatal_new_handler_depth = 0;
@@ -133,7 +119,6 @@ fatal_system_new_handler(void)
errdetail("while in LLVM")));
}
-#if LLVM_VERSION_MAJOR > 4
static void
fatal_llvm_new_handler(void *user_data,
const char *reason,
@@ -144,16 +129,6 @@ fatal_llvm_new_handler(void *user_data,
errmsg("out of memory"),
errdetail("While in LLVM: %s", reason)));
}
-#if LLVM_VERSION_MAJOR < 14
-static void
-fatal_llvm_new_handler(void *user_data,
- const std::string& reason,
- bool gen_crash_diag)
-{
- fatal_llvm_new_handler(user_data, reason.c_str(), gen_crash_diag);
-}
-#endif
-#endif
static void
fatal_llvm_error_handler(void *user_data,
@@ -164,13 +139,3 @@ fatal_llvm_error_handler(void *user_data,
(errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("fatal llvm error: %s", reason)));
}
-
-#if LLVM_VERSION_MAJOR < 14
-static void
-fatal_llvm_error_handler(void *user_data,
- const std::string& reason,
- bool gen_crash_diag)
-{
- fatal_llvm_error_handler(user_data, reason.c_str(), gen_crash_diag);
-}
-#endif
diff --git a/src/backend/jit/llvm/llvmjit_expr.c b/src/backend/jit/llvm/llvmjit_expr.c
index a3a0876bff..a950564afa 100644
--- a/src/backend/jit/llvm/llvmjit_expr.c
+++ b/src/backend/jit/llvm/llvmjit_expr.c
@@ -2644,12 +2644,8 @@ create_LifetimeEnd(LLVMModuleRef mod)
LLVMTypeRef param_types[2];
LLVMContextRef lc;
- /* LLVM 5+ has a variadic pointer argument */
-#if LLVM_VERSION_MAJOR < 5
- const char *nm = "llvm.lifetime.end";
-#else
+ /* variadic pointer argument */
const char *nm = "llvm.lifetime.end.p0i8";
-#endif
fn = LLVMGetNamedFunction(mod, nm);
if (fn)
diff --git a/src/backend/jit/llvm/llvmjit_inline.cpp b/src/backend/jit/llvm/llvmjit_inline.cpp
index d92d7f3c88..693bc6510b 100644
--- a/src/backend/jit/llvm/llvmjit_inline.cpp
+++ b/src/backend/jit/llvm/llvmjit_inline.cpp
@@ -49,12 +49,7 @@ extern "C"
#include <llvm/ADT/StringSet.h>
#include <llvm/ADT/StringMap.h>
#include <llvm/Analysis/ModuleSummaryAnalysis.h>
-#if LLVM_VERSION_MAJOR > 3
#include <llvm/Bitcode/BitcodeReader.h>
-#else
-#include <llvm/Bitcode/ReaderWriter.h>
-#include <llvm/Support/Error.h>
-#endif
#include <llvm/IR/Attributes.h>
#include <llvm/IR/DebugInfo.h>
#include <llvm/IR/IntrinsicInst.h>
@@ -267,14 +262,12 @@ llvm_build_inline_plan(LLVMContextRef lc, llvm::Module *mod)
fs = llvm::cast<llvm::FunctionSummary>(gvs);
-#if LLVM_VERSION_MAJOR > 3
if (gvs->notEligibleToImport())
{
ilog(DEBUG1, "ineligibile to import %s due to summary",
symbolName.data());
continue;
}
-#endif
if ((int) fs->instCount() > inlineState.costLimit)
{
@@ -458,16 +451,9 @@ llvm_execute_inline_plan(llvm::Module *mod, ImportMapTy *globalsToInline)
}
-#if LLVM_VERSION_MAJOR > 4
-#define IRMOVE_PARAMS , /*IsPerformingImport=*/false
-#elif LLVM_VERSION_MAJOR > 3
-#define IRMOVE_PARAMS , /*LinkModuleInlineAsm=*/false, /*IsPerformingImport=*/false
-#else
-#define IRMOVE_PARAMS
-#endif
if (Mover.move(std::move(importMod), GlobalsToImport.getArrayRef(),
- [](llvm::GlobalValue &, llvm::IRMover::ValueAdder) {}
- IRMOVE_PARAMS))
+ [](llvm::GlobalValue &, llvm::IRMover::ValueAdder) {},
+ /*IsPerformingImport=*/false))
elog(FATAL, "function import failed with linker error");
}
}
@@ -608,10 +594,6 @@ function_inlinable(llvm::Function &F,
if (F.materialize())
elog(FATAL, "failed to materialize metadata");
-#if LLVM_VERSION_MAJOR < 14
-#define hasFnAttr hasFnAttribute
-#endif
-
if (F.getAttributes().hasFnAttr(llvm::Attribute::NoInline))
{
ilog(DEBUG1, "ineligibile to import %s due to noinline",
@@ -793,7 +775,6 @@ llvm_load_summary(llvm::StringRef path)
{
llvm::MemoryBufferRef ref(*MBOrErr.get().get());
-#if LLVM_VERSION_MAJOR > 3
llvm::Expected<std::unique_ptr<llvm::ModuleSummaryIndex> > IndexOrErr =
llvm::getModuleSummaryIndex(ref);
if (IndexOrErr)
@@ -801,15 +782,6 @@ llvm_load_summary(llvm::StringRef path)
elog(FATAL, "failed to load summary \"%s\": %s",
path.data(),
toString(IndexOrErr.takeError()).c_str());
-#else
- llvm::ErrorOr<std::unique_ptr<llvm::ModuleSummaryIndex> > IndexOrErr =
- llvm::getModuleSummaryIndex(ref, [](const llvm::DiagnosticInfo &) {});
- if (IndexOrErr)
- return std::move(IndexOrErr.get());
- elog(FATAL, "failed to load summary \"%s\": %s",
- path.data(),
- IndexOrErr.getError().message().c_str());
-#endif
}
return nullptr;
}
@@ -853,22 +825,12 @@ summaries_for_guid(const InlineSearchPath& path, llvm::GlobalValue::GUID guid)
for (auto index : path)
{
-#if LLVM_VERSION_MAJOR > 4
llvm::ValueInfo funcVI = index->getValueInfo(guid);
/* if index doesn't know function, we don't have a body, continue */
if (funcVI)
for (auto &gv : funcVI.getSummaryList())
matches.push_back(gv.get());
-#else
- const llvm::const_gvsummary_iterator &I =
- index->findGlobalValueSummaryList(guid);
- if (I != index->end())
- {
- for (auto &gv : I->second)
- matches.push_back(gv.get());
- }
-#endif
}
return matches;
@@ -889,9 +851,6 @@ create_redirection_function(std::unique_ptr<llvm::Module> &importMod,
llvm::Function *AF;
llvm::BasicBlock *BB;
llvm::CallInst *fwdcall;
-#if LLVM_VERSION_MAJOR < 14
- llvm::Attribute inlineAttribute;
-#endif
AF = llvm::Function::Create(F->getFunctionType(),
LinkageTypes::AvailableExternallyLinkage,
@@ -900,13 +859,7 @@ create_redirection_function(std::unique_ptr<llvm::Module> &importMod,
Builder.SetInsertPoint(BB);
fwdcall = Builder.CreateCall(F, &*AF->arg_begin());
-#if LLVM_VERSION_MAJOR < 14
- inlineAttribute = llvm::Attribute::get(Context,
- llvm::Attribute::AlwaysInline);
- fwdcall->addAttribute(~0U, inlineAttribute);
-#else
fwdcall->addFnAttr(llvm::Attribute::AlwaysInline);
-#endif
Builder.CreateRet(fwdcall);
return AF;
diff --git a/src/backend/jit/llvm/llvmjit_wrap.cpp b/src/backend/jit/llvm/llvmjit_wrap.cpp
index 90a41b9191..2d697fd2cc 100644
--- a/src/backend/jit/llvm/llvmjit_wrap.cpp
+++ b/src/backend/jit/llvm/llvmjit_wrap.cpp
@@ -17,20 +17,7 @@ extern "C"
}
#include <llvm-c/Core.h>
-
-/* Avoid macro clash with LLVM's C++ headers */
-#undef Min
-
-#include <llvm/IR/Attributes.h>
#include <llvm/IR/Function.h>
-#if LLVM_VERSION_MAJOR < 17
-#include <llvm/MC/SubtargetFeature.h>
-#endif
-#if LLVM_VERSION_MAJOR > 16
-#include <llvm/TargetParser/Host.h>
-#else
-#include <llvm/Support/Host.h>
-#endif
#include "jit/llvmjit.h"
@@ -38,50 +25,6 @@ extern "C"
/*
* C-API extensions.
*/
-#if defined(HAVE_DECL_LLVMGETHOSTCPUNAME) && !HAVE_DECL_LLVMGETHOSTCPUNAME
-char *LLVMGetHostCPUName(void) {
- return strdup(llvm::sys::getHostCPUName().data());
-}
-#endif
-
-
-#if defined(HAVE_DECL_LLVMGETHOSTCPUFEATURES) && !HAVE_DECL_LLVMGETHOSTCPUFEATURES
-char *LLVMGetHostCPUFeatures(void) {
- llvm::SubtargetFeatures Features;
- llvm::StringMap<bool> HostFeatures;
-
- if (llvm::sys::getHostCPUFeatures(HostFeatures))
- for (auto &F : HostFeatures)
- Features.AddFeature(F.first(), F.second);
-
- return strdup(Features.getString().c_str());
-}
-#endif
-
-/*
- * Like LLVM's LLVMGetAttributeCountAtIndex(), works around a bug in LLVM 3.9.
- *
- * In LLVM <= 3.9, LLVMGetAttributeCountAtIndex() segfaults if there are no
- * attributes at an index (fixed in LLVM commit ce9bb1097dc2).
- */
-unsigned
-LLVMGetAttributeCountAtIndexPG(LLVMValueRef F, uint32 Idx)
-{
- /*
- * This is more expensive, so only do when using a problematic LLVM
- * version.
- */
-#if LLVM_VERSION_MAJOR < 4
- if (!llvm::unwrap<llvm::Function>(F)->getAttributes().hasAttributes(Idx))
- return 0;
-#endif
-
- /*
- * There is no nice public API to determine the count nicely, so just
- * always fall back to LLVM's C API.
- */
- return LLVMGetAttributeCountAtIndex(F, Idx);
-}
LLVMTypeRef
LLVMGetFunctionReturnType(LLVMValueRef r)
@@ -94,11 +37,3 @@ LLVMGetFunctionType(LLVMValueRef r)
{
return llvm::wrap(llvm::unwrap<llvm::Function>(r)->getFunctionType());
}
-
-#if LLVM_VERSION_MAJOR < 8
-LLVMTypeRef
-LLVMGlobalGetValueType(LLVMValueRef g)
-{
- return llvm::wrap(llvm::unwrap<llvm::GlobalValue>(g)->getValueType());
-}
-#endif
diff --git a/src/include/jit/llvmjit.h b/src/include/jit/llvmjit.h
index 3ab86de3ac..e90b390bf4 100644
--- a/src/include/jit/llvmjit.h
+++ b/src/include/jit/llvmjit.h
@@ -130,26 +130,9 @@ extern LLVMValueRef slot_compile_deform(struct LLVMJitContext *context, TupleDes
* Error handling related functions.
****************************************************************************
*/
-#if defined(HAVE_DECL_LLVMGETHOSTCPUNAME) && !HAVE_DECL_LLVMGETHOSTCPUNAME
-/** Get the host CPU as a string. The result needs to be disposed with
- LLVMDisposeMessage. */
-extern char *LLVMGetHostCPUName(void);
-#endif
-
-#if defined(HAVE_DECL_LLVMGETHOSTCPUFEATURES) && !HAVE_DECL_LLVMGETHOSTCPUFEATURES
-/** Get the host CPU features as a string. The result needs to be disposed
- with LLVMDisposeMessage. */
-extern char *LLVMGetHostCPUFeatures(void);
-#endif
-
-extern unsigned LLVMGetAttributeCountAtIndexPG(LLVMValueRef F, uint32 Idx);
extern LLVMTypeRef LLVMGetFunctionReturnType(LLVMValueRef r);
extern LLVMTypeRef LLVMGetFunctionType(LLVMValueRef r);
-#if LLVM_MAJOR_VERSION < 8
-extern LLVMTypeRef LLVMGlobalGetValueType(LLVMValueRef g);
-#endif
-
#ifdef __cplusplus
} /* extern "C" */
#endif
diff --git a/src/include/pg_config.h.in b/src/include/pg_config.h.in
index d8a2985567..481470ee59 100644
--- a/src/include/pg_config.h.in
+++ b/src/include/pg_config.h.in
@@ -103,18 +103,6 @@
`LLVMCreatePerfJITEventListener', and to 0 if you don't. */
#undef HAVE_DECL_LLVMCREATEPERFJITEVENTLISTENER
-/* Define to 1 if you have the declaration of `LLVMGetHostCPUFeatures', and to
- 0 if you don't. */
-#undef HAVE_DECL_LLVMGETHOSTCPUFEATURES
-
-/* Define to 1 if you have the declaration of `LLVMGetHostCPUName', and to 0
- if you don't. */
-#undef HAVE_DECL_LLVMGETHOSTCPUNAME
-
-/* Define to 1 if you have the declaration of `LLVMOrcGetSymbolAddressIn', and
- to 0 if you don't. */
-#undef HAVE_DECL_LLVMORCGETSYMBOLADDRESSIN
-
/* 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/tools/msvc/Solution.pm b/src/tools/msvc/Solution.pm
index a50f730260..5066bd9e28 100644
--- a/src/tools/msvc/Solution.pm
+++ b/src/tools/msvc/Solution.pm
@@ -235,9 +235,6 @@ sub GenerateFiles
HAVE_DECL_F_FULLFSYNC => 0,
HAVE_DECL_LLVMCREATEGDBREGISTRATIONLISTENER => 0,
HAVE_DECL_LLVMCREATEPERFJITEVENTLISTENER => 0,
- HAVE_DECL_LLVMGETHOSTCPUNAME => 0,
- HAVE_DECL_LLVMGETHOSTCPUFEATURES => 0,
- HAVE_DECL_LLVMORCGETSYMBOLADDRESSIN => 0,
HAVE_DECL_POSIX_FADVISE => 0,
HAVE_DECL_PREADV => 0,
HAVE_DECL_PWRITEV => 0,
--
2.42.0
v2-0002-jit-Use-opaque-pointers-in-all-supported-LLVM-ver.patchtext/x-patch; charset=US-ASCII; name=v2-0002-jit-Use-opaque-pointers-in-all-supported-LLVM-ver.patchDownload
From 4296205aca732668fb64f8a5e11bd95524b5f15e Mon Sep 17 00:00:00 2001
From: Thomas Munro <thomas.munro@gmail.com>
Date: Fri, 20 Oct 2023 15:13:26 +1300
Subject: [PATCH v2 2/2] jit: Use opaque pointers in all supported LLVM
versions.
Historically we adapted to different LLVM API changes when forced to by
new LLVM releases, but we tried to avoid changing how we interacted with
already-released LLVM versions, because we needed to back-patch into our
release branches and we wanted to keep them as stable as possible. For
PostgreSQL 17, having dropped support for LLVM versions < 14, let's be
more aggressive and adopt LLVM opaque pointers everywhere for tidier and
more consistent code.
Discussions: https://postgr.es/m/CA%2BhUKGLhNs5geZaVNj2EJ79Dx9W8fyWUU3HxcpZy55sMGcY%3DiA%40mail.gmail.com
---
configure | 89 --------------------------------
configure.ac | 3 --
src/backend/jit/llvm/llvmjit.c | 13 -----
src/backend/jit/llvm/meson.build | 3 --
src/include/jit/llvmjit_emit.h | 16 ------
5 files changed, 124 deletions(-)
diff --git a/configure b/configure
index f4a04485e1..b026e2e935 100755
--- a/configure
+++ b/configure
@@ -7560,95 +7560,6 @@ if test x"$pgac_cv_prog_CLANGXX_cxxflags__fexcess_precision_standard" = x"yes";
fi
- { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${CLANG} supports -Xclang -no-opaque-pointers, for BITCODE_CFLAGS" >&5
-$as_echo_n "checking whether ${CLANG} supports -Xclang -no-opaque-pointers, for BITCODE_CFLAGS... " >&6; }
-if ${pgac_cv_prog_CLANG_cflags__Xclang__no_opaque_pointers+:} false; then :
- $as_echo_n "(cached) " >&6
-else
- pgac_save_CFLAGS=$CFLAGS
-pgac_save_CC=$CC
-CC=${CLANG}
-CFLAGS="${BITCODE_CFLAGS} -Xclang -no-opaque-pointers"
-ac_save_c_werror_flag=$ac_c_werror_flag
-ac_c_werror_flag=yes
-cat confdefs.h - <<_ACEOF >conftest.$ac_ext
-/* end confdefs.h. */
-
-int
-main ()
-{
-
- ;
- return 0;
-}
-_ACEOF
-if ac_fn_c_try_compile "$LINENO"; then :
- pgac_cv_prog_CLANG_cflags__Xclang__no_opaque_pointers=yes
-else
- pgac_cv_prog_CLANG_cflags__Xclang__no_opaque_pointers=no
-fi
-rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
-ac_c_werror_flag=$ac_save_c_werror_flag
-CFLAGS="$pgac_save_CFLAGS"
-CC="$pgac_save_CC"
-fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv_prog_CLANG_cflags__Xclang__no_opaque_pointers" >&5
-$as_echo "$pgac_cv_prog_CLANG_cflags__Xclang__no_opaque_pointers" >&6; }
-if test x"$pgac_cv_prog_CLANG_cflags__Xclang__no_opaque_pointers" = x"yes"; then
- BITCODE_CFLAGS="${BITCODE_CFLAGS} -Xclang -no-opaque-pointers"
-fi
-
- { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${CLANGXX} supports -Xclang -no-opaque-pointers, for BITCODE_CXXFLAGS" >&5
-$as_echo_n "checking whether ${CLANGXX} supports -Xclang -no-opaque-pointers, for BITCODE_CXXFLAGS... " >&6; }
-if ${pgac_cv_prog_CLANGXX_cxxflags__Xclang__no_opaque_pointers+:} false; then :
- $as_echo_n "(cached) " >&6
-else
- pgac_save_CXXFLAGS=$CXXFLAGS
-pgac_save_CXX=$CXX
-CXX=${CLANGXX}
-CXXFLAGS="${BITCODE_CXXFLAGS} -Xclang -no-opaque-pointers"
-ac_save_cxx_werror_flag=$ac_cxx_werror_flag
-ac_cxx_werror_flag=yes
-ac_ext=cpp
-ac_cpp='$CXXCPP $CPPFLAGS'
-ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5'
-ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
-ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
-
-cat confdefs.h - <<_ACEOF >conftest.$ac_ext
-/* end confdefs.h. */
-
-int
-main ()
-{
-
- ;
- return 0;
-}
-_ACEOF
-if ac_fn_cxx_try_compile "$LINENO"; then :
- pgac_cv_prog_CLANGXX_cxxflags__Xclang__no_opaque_pointers=yes
-else
- pgac_cv_prog_CLANGXX_cxxflags__Xclang__no_opaque_pointers=no
-fi
-rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
-ac_ext=c
-ac_cpp='$CPP $CPPFLAGS'
-ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
-ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
-ac_compiler_gnu=$ac_cv_c_compiler_gnu
-
-ac_cxx_werror_flag=$ac_save_cxx_werror_flag
-CXXFLAGS="$pgac_save_CXXFLAGS"
-CXX="$pgac_save_CXX"
-fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv_prog_CLANGXX_cxxflags__Xclang__no_opaque_pointers" >&5
-$as_echo "$pgac_cv_prog_CLANGXX_cxxflags__Xclang__no_opaque_pointers" >&6; }
-if test x"$pgac_cv_prog_CLANGXX_cxxflags__Xclang__no_opaque_pointers" = x"yes"; then
- BITCODE_CXXFLAGS="${BITCODE_CXXFLAGS} -Xclang -no-opaque-pointers"
-fi
-
-
NOT_THE_CFLAGS=""
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${CLANG} supports -Wunused-command-line-argument, for NOT_THE_CFLAGS" >&5
$as_echo_n "checking whether ${CLANG} supports -Wunused-command-line-argument, for NOT_THE_CFLAGS... " >&6; }
diff --git a/configure.ac b/configure.ac
index 440b08d113..2947d0d37a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -649,9 +649,6 @@ if test "$with_llvm" = yes ; then
PGAC_PROG_VARCC_VARFLAGS_OPT(CLANG, BITCODE_CFLAGS, [-fexcess-precision=standard])
PGAC_PROG_VARCXX_VARFLAGS_OPT(CLANGXX, BITCODE_CXXFLAGS, [-fexcess-precision=standard])
- PGAC_PROG_VARCC_VARFLAGS_OPT(CLANG, BITCODE_CFLAGS, [-Xclang -no-opaque-pointers])
- PGAC_PROG_VARCXX_VARFLAGS_OPT(CLANGXX, BITCODE_CXXFLAGS, [-Xclang -no-opaque-pointers])
-
NOT_THE_CFLAGS=""
PGAC_PROG_VARCC_VARFLAGS_OPT(CLANG, NOT_THE_CFLAGS, [-Wunused-command-line-argument])
if test -n "$NOT_THE_CFLAGS"; then
diff --git a/src/backend/jit/llvm/llvmjit.c b/src/backend/jit/llvm/llvmjit.c
index d31e4759a6..a3a44e13e9 100644
--- a/src/backend/jit/llvm/llvmjit.c
+++ b/src/backend/jit/llvm/llvmjit.c
@@ -809,19 +809,6 @@ llvm_session_initialize(void)
llvm_llvm_context_reuse_count = 0;
}
- /*
- * When targeting LLVM 15, turn off opaque pointers for the context we
- * build our code in. We don't need to do so for other contexts (e.g.
- * llvm_ts_context). Once the IR is generated, it carries the necessary
- * information.
- *
- * For 16 and above, opaque pointers must be used, and we have special
- * code for that.
- */
-#if LLVM_VERSION_MAJOR == 15
- LLVMContextSetOpaquePointers(LLVMGetGlobalContext(), false);
-#endif
-
/*
* Synchronize types early, as that also includes inferring the target
* triple.
diff --git a/src/backend/jit/llvm/meson.build b/src/backend/jit/llvm/meson.build
index 8ffaf41460..4743333c3f 100644
--- a/src/backend/jit/llvm/meson.build
+++ b/src/backend/jit/llvm/meson.build
@@ -60,9 +60,6 @@ endif
# XXX: Need to determine proper version of the function cflags for clang
bitcode_cflags = ['-fno-strict-aliasing', '-fwrapv']
-if llvm.version().version_compare('=15.0')
- bitcode_cflags += ['-Xclang', '-no-opaque-pointers']
-endif
bitcode_cflags += cppflags
# XXX: Worth improving on the logic to find directories here
diff --git a/src/include/jit/llvmjit_emit.h b/src/include/jit/llvmjit_emit.h
index b1f0ea56c0..a37b723d28 100644
--- a/src/include/jit/llvmjit_emit.h
+++ b/src/include/jit/llvmjit_emit.h
@@ -107,41 +107,25 @@ l_pbool_const(bool i)
static inline LLVMValueRef
l_struct_gep(LLVMBuilderRef b, LLVMTypeRef t, LLVMValueRef v, int32 idx, const char *name)
{
-#if LLVM_VERSION_MAJOR < 16
- return LLVMBuildStructGEP(b, v, idx, "");
-#else
return LLVMBuildStructGEP2(b, t, v, idx, "");
-#endif
}
static inline LLVMValueRef
l_gep(LLVMBuilderRef b, LLVMTypeRef t, LLVMValueRef v, LLVMValueRef *indices, int32 nindices, const char *name)
{
-#if LLVM_VERSION_MAJOR < 16
- return LLVMBuildGEP(b, v, indices, nindices, name);
-#else
return LLVMBuildGEP2(b, t, v, indices, nindices, name);
-#endif
}
static inline LLVMValueRef
l_load(LLVMBuilderRef b, LLVMTypeRef t, LLVMValueRef v, const char *name)
{
-#if LLVM_VERSION_MAJOR < 16
- return LLVMBuildLoad(b, v, name);
-#else
return LLVMBuildLoad2(b, t, v, name);
-#endif
}
static inline LLVMValueRef
l_call(LLVMBuilderRef b, LLVMTypeRef t, LLVMValueRef fn, LLVMValueRef *args, int32 nargs, const char *name)
{
-#if LLVM_VERSION_MAJOR < 16
- return LLVMBuildCall(b, fn, args, nargs, name);
-#else
return LLVMBuildCall2(b, t, fn, args, nargs, name);
-#endif
}
/*
--
2.42.0
Rebased. I also noticed this woefully out of date line:
- PGAC_PATH_PROGS(LLVM_CONFIG, llvm-config llvm-config-7
llvm-config-6.0 llvm-config-5.0 llvm-config-4.0 llvm-config-3.9)
+ PGAC_PATH_PROGS(LLVM_CONFIG, llvm-config llvm-config-17
llvm-config-16 llvm-config-15 llvm-config-14)
Attachments:
v3-0001-jit-Require-at-least-LLVM-14-if-enabled.patchtext/x-patch; charset=US-ASCII; name=v3-0001-jit-Require-at-least-LLVM-14-if-enabled.patchDownload
From 522a4f3744e691f42f43bb1ca91df60b12465bff Mon Sep 17 00:00:00 2001
From: Thomas Munro <thomas.munro@gmail.com>
Date: Thu, 19 Oct 2023 04:45:46 +1300
Subject: [PATCH v3 1/2] jit: Require at least LLVM 14, if enabled.
Remove support for a lot of older LLVM versions dating back to 3.9. The
default on common software distritbutions will be at least LLVM 14 when
PostgreSQL 17 ships.
Discussion: https://postgr.es/m/CA%2BhUKGLhNs5geZaVNj2EJ79Dx9W8fyWUU3HxcpZy55sMGcY%3DiA%40mail.gmail.com
---
config/llvm.m4 | 10 +-
configure | 43 +------
doc/src/sgml/installation.sgml | 4 +-
meson.build | 2 +-
src/backend/jit/llvm/llvmjit.c | 158 +-----------------------
src/backend/jit/llvm/llvmjit_error.cpp | 35 ------
src/backend/jit/llvm/llvmjit_expr.c | 6 +-
src/backend/jit/llvm/llvmjit_inline.cpp | 51 +-------
src/backend/jit/llvm/llvmjit_wrap.cpp | 65 ----------
src/include/jit/llvmjit.h | 17 ---
src/include/pg_config.h.in | 12 --
src/tools/msvc/Solution.pm | 3 -
12 files changed, 15 insertions(+), 391 deletions(-)
diff --git a/config/llvm.m4 b/config/llvm.m4
index 21d8cd4f90..ede5e25e91 100644
--- a/config/llvm.m4
+++ b/config/llvm.m4
@@ -13,7 +13,7 @@ AC_DEFUN([PGAC_LLVM_SUPPORT],
AC_REQUIRE([AC_PROG_AWK])
AC_ARG_VAR(LLVM_CONFIG, [path to llvm-config command])
- PGAC_PATH_PROGS(LLVM_CONFIG, llvm-config llvm-config-7 llvm-config-6.0 llvm-config-5.0 llvm-config-4.0 llvm-config-3.9)
+ PGAC_PATH_PROGS(LLVM_CONFIG, llvm-config llvm-config-17 llvm-config-16 llvm-config-15 llvm-config-14)
# no point continuing if llvm wasn't found
if test -z "$LLVM_CONFIG"; then
@@ -25,14 +25,14 @@ AC_DEFUN([PGAC_LLVM_SUPPORT],
AC_MSG_ERROR([$LLVM_CONFIG does not work])
fi
# and whether the version is supported
- if echo $pgac_llvm_version | $AWK -F '.' '{ if ([$]1 >= 4 || ([$]1 == 3 && [$]2 >= 9)) exit 1; else exit 0;}';then
- AC_MSG_ERROR([$LLVM_CONFIG version is $pgac_llvm_version but at least 3.9 is required])
+ if echo $pgac_llvm_version | $AWK -F '.' '{ if ([$]1 >= 14) exit 1; else exit 0;}';then
+ AC_MSG_ERROR([$LLVM_CONFIG version is $pgac_llvm_version but at least 14 is required])
fi
AC_MSG_NOTICE([using llvm $pgac_llvm_version])
# need clang to create some bitcode files
AC_ARG_VAR(CLANG, [path to clang compiler to generate bitcode])
- PGAC_PATH_PROGS(CLANG, clang clang-7 clang-6.0 clang-5.0 clang-4.0 clang-3.9)
+ PGAC_PATH_PROGS(CLANG, clang clang-17 clang-16 clang-15 clang-14)
if test -z "$CLANG"; then
AC_MSG_ERROR([clang not found, but required when compiling --with-llvm, specify with CLANG=])
fi
@@ -115,8 +115,6 @@ AC_DEFUN([PGAC_CHECK_LLVM_FUNCTIONS],
# Check which functionality is present
SAVE_CPPFLAGS="$CPPFLAGS"
CPPFLAGS="$CPPFLAGS $LLVM_CPPFLAGS"
- AC_CHECK_DECLS([LLVMOrcGetSymbolAddressIn], [], [], [[#include <llvm-c/OrcBindings.h>]])
- AC_CHECK_DECLS([LLVMGetHostCPUName, LLVMGetHostCPUFeatures], [], [], [[#include <llvm-c/TargetMachine.h>]])
AC_CHECK_DECLS([LLVMCreateGDBRegistrationListener, LLVMCreatePerfJITEventListener], [], [], [[#include <llvm-c/ExecutionEngine.h>]])
CPPFLAGS="$SAVE_CPPFLAGS"
])# PGAC_CHECK_LLVM_FUNCTIONS
diff --git a/configure b/configure
index c2cb1b1b24..2d92e3dea3 100755
--- a/configure
+++ b/configure
@@ -5056,7 +5056,7 @@ if test "$with_llvm" = yes; then :
if test -z "$LLVM_CONFIG"; then
- for ac_prog in llvm-config llvm-config-7 llvm-config-6.0 llvm-config-5.0 llvm-config-4.0 llvm-config-3.9
+ for ac_prog in llvm-config llvm-config-17 llvm-config-16 llvm-config-15 llvm-config-14
do
# Extract the first word of "$ac_prog", so it can be a program name with args.
set dummy $ac_prog; ac_word=$2
@@ -5120,8 +5120,8 @@ fi
as_fn_error $? "$LLVM_CONFIG does not work" "$LINENO" 5
fi
# and whether the version is supported
- if echo $pgac_llvm_version | $AWK -F '.' '{ if ($1 >= 4 || ($1 == 3 && $2 >= 9)) exit 1; else exit 0;}';then
- as_fn_error $? "$LLVM_CONFIG version is $pgac_llvm_version but at least 3.9 is required" "$LINENO" 5
+ if echo $pgac_llvm_version | $AWK -F '.' '{ if ($1 >= 14) exit 1; else exit 0;}';then
+ as_fn_error $? "$LLVM_CONFIG version is $pgac_llvm_version but at least 14 is required" "$LINENO" 5
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: using llvm $pgac_llvm_version" >&5
$as_echo "$as_me: using llvm $pgac_llvm_version" >&6;}
@@ -5129,7 +5129,7 @@ $as_echo "$as_me: using llvm $pgac_llvm_version" >&6;}
# need clang to create some bitcode files
if test -z "$CLANG"; then
- for ac_prog in clang clang-7 clang-6.0 clang-5.0 clang-4.0 clang-3.9
+ for ac_prog in clang clang-17 clang-16 clang-15 clang-14
do
# Extract the first word of "$ac_prog", so it can be a program name with args.
set dummy $ac_prog; ac_word=$2
@@ -16573,41 +16573,6 @@ if test "$with_llvm" = yes; then
# Check which functionality is present
SAVE_CPPFLAGS="$CPPFLAGS"
CPPFLAGS="$CPPFLAGS $LLVM_CPPFLAGS"
- ac_fn_c_check_decl "$LINENO" "LLVMOrcGetSymbolAddressIn" "ac_cv_have_decl_LLVMOrcGetSymbolAddressIn" "#include <llvm-c/OrcBindings.h>
-"
-if test "x$ac_cv_have_decl_LLVMOrcGetSymbolAddressIn" = xyes; then :
- ac_have_decl=1
-else
- ac_have_decl=0
-fi
-
-cat >>confdefs.h <<_ACEOF
-#define HAVE_DECL_LLVMORCGETSYMBOLADDRESSIN $ac_have_decl
-_ACEOF
-
- ac_fn_c_check_decl "$LINENO" "LLVMGetHostCPUName" "ac_cv_have_decl_LLVMGetHostCPUName" "#include <llvm-c/TargetMachine.h>
-"
-if test "x$ac_cv_have_decl_LLVMGetHostCPUName" = xyes; then :
- ac_have_decl=1
-else
- ac_have_decl=0
-fi
-
-cat >>confdefs.h <<_ACEOF
-#define HAVE_DECL_LLVMGETHOSTCPUNAME $ac_have_decl
-_ACEOF
-ac_fn_c_check_decl "$LINENO" "LLVMGetHostCPUFeatures" "ac_cv_have_decl_LLVMGetHostCPUFeatures" "#include <llvm-c/TargetMachine.h>
-"
-if test "x$ac_cv_have_decl_LLVMGetHostCPUFeatures" = xyes; then :
- ac_have_decl=1
-else
- ac_have_decl=0
-fi
-
-cat >>confdefs.h <<_ACEOF
-#define HAVE_DECL_LLVMGETHOSTCPUFEATURES $ac_have_decl
-_ACEOF
-
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 :
diff --git a/doc/src/sgml/installation.sgml b/doc/src/sgml/installation.sgml
index f4b1f81189..20453ab586 100644
--- a/doc/src/sgml/installation.sgml
+++ b/doc/src/sgml/installation.sgml
@@ -965,7 +965,7 @@ build-postgresql:
linkend="jit"/>)</phrase>. This
requires the <productname>LLVM</productname> library to be installed.
The minimum required version of <productname>LLVM</productname> is
- currently 3.9.
+ currently 14.
</para>
<para>
<command>llvm-config</command><indexterm><primary>llvm-config</primary></indexterm>
@@ -2432,7 +2432,7 @@ ninja install
condition="standalone-ignore"> (see <xref linkend="jit"/>)</phrase>.
This requires the <productname>LLVM</productname> library to be
installed. The minimum required version of
- <productname>LLVM</productname> is currently 3.9. Disabled by
+ <productname>LLVM</productname> is currently 14. Disabled by
default.
</para>
diff --git a/meson.build b/meson.build
index 2d516c8f37..2452ae92b8 100644
--- a/meson.build
+++ b/meson.build
@@ -748,7 +748,7 @@ endif
llvmopt = get_option('llvm')
llvm = not_found_dep
if add_languages('cpp', required: llvmopt, native: false)
- llvm = dependency('llvm', version: '>=3.9', method: 'config-tool', required: llvmopt)
+ llvm = dependency('llvm', version: '>=14', method: 'config-tool', required: llvmopt)
if llvm.found()
diff --git a/src/backend/jit/llvm/llvmjit.c b/src/backend/jit/llvm/llvmjit.c
index 58f638859a..d31e4759a6 100644
--- a/src/backend/jit/llvm/llvmjit.c
+++ b/src/backend/jit/llvm/llvmjit.c
@@ -21,23 +21,17 @@
#if LLVM_VERSION_MAJOR > 16
#include <llvm-c/Transforms/PassBuilder.h>
#endif
-#if LLVM_VERSION_MAJOR > 11
#include <llvm-c/Orc.h>
#include <llvm-c/OrcEE.h>
#include <llvm-c/LLJIT.h>
-#else
-#include <llvm-c/OrcBindings.h>
-#endif
#include <llvm-c/Support.h>
#include <llvm-c/Target.h>
#if LLVM_VERSION_MAJOR < 17
#include <llvm-c/Transforms/IPO.h>
#include <llvm-c/Transforms/PassManagerBuilder.h>
#include <llvm-c/Transforms/Scalar.h>
-#if LLVM_VERSION_MAJOR > 6
#include <llvm-c/Transforms/Utils.h>
#endif
-#endif
#include "jit/llvmjit.h"
#include "jit/llvmjit_emit.h"
@@ -52,13 +46,8 @@
/* Handle of a module emitted via ORC JIT */
typedef struct LLVMJitHandle
{
-#if LLVM_VERSION_MAJOR > 11
LLVMOrcLLJITRef lljit;
LLVMOrcResourceTrackerRef resource_tracker;
-#else
- LLVMOrcJITStackRef stack;
- LLVMOrcModuleHandle orc_handle;
-#endif
} LLVMJitHandle;
@@ -105,14 +94,9 @@ static LLVMContextRef llvm_context;
static LLVMTargetRef llvm_targetref;
-#if LLVM_VERSION_MAJOR > 11
static LLVMOrcThreadSafeContextRef llvm_ts_context;
static LLVMOrcLLJITRef llvm_opt0_orc;
static LLVMOrcLLJITRef llvm_opt3_orc;
-#else /* LLVM_VERSION_MAJOR > 11 */
-static LLVMOrcJITStackRef llvm_opt0_orc;
-static LLVMOrcJITStackRef llvm_opt3_orc;
-#endif /* LLVM_VERSION_MAJOR > 11 */
static void llvm_release_context(JitContext *context);
@@ -126,10 +110,8 @@ static void llvm_set_target(void);
static void llvm_recreate_llvm_context(void);
static uint64_t llvm_resolve_symbol(const char *name, void *ctx);
-#if LLVM_VERSION_MAJOR > 11
static LLVMOrcLLJITRef llvm_create_jit_instance(LLVMTargetMachineRef tm);
static char *llvm_error_message(LLVMErrorRef error);
-#endif /* LLVM_VERSION_MAJOR > 11 */
PG_MODULE_MAGIC;
@@ -270,7 +252,6 @@ llvm_release_context(JitContext *context)
{
LLVMJitHandle *jit_handle = (LLVMJitHandle *) lfirst(lc);
-#if LLVM_VERSION_MAJOR > 11
{
LLVMOrcExecutionSessionRef ee;
LLVMOrcSymbolStringPoolRef sp;
@@ -288,11 +269,6 @@ llvm_release_context(JitContext *context)
sp = LLVMOrcExecutionSessionGetSymbolStringPool(ee);
LLVMOrcSymbolStringPoolClearDeadEntries(sp);
}
-#else /* LLVM_VERSION_MAJOR > 11 */
- {
- LLVMOrcRemoveModule(jit_handle->stack, jit_handle->orc_handle);
- }
-#endif /* LLVM_VERSION_MAJOR > 11 */
pfree(jit_handle);
}
@@ -354,10 +330,7 @@ llvm_expand_funcname(struct LLVMJitContext *context, const char *basename)
void *
llvm_get_function(LLVMJitContext *context, const char *funcname)
{
-#if LLVM_VERSION_MAJOR > 11 || \
- defined(HAVE_DECL_LLVMORCGETSYMBOLADDRESSIN) && HAVE_DECL_LLVMORCGETSYMBOLADDRESSIN
ListCell *lc;
-#endif
llvm_assert_in_fatal_section();
@@ -375,7 +348,6 @@ llvm_get_function(LLVMJitContext *context, const char *funcname)
* to mangle here.
*/
-#if LLVM_VERSION_MAJOR > 11
foreach(lc, context->handles)
{
LLVMJitHandle *handle = (LLVMJitHandle *) lfirst(lc);
@@ -405,41 +377,6 @@ llvm_get_function(LLVMJitContext *context, const char *funcname)
if (addr)
return (void *) (uintptr_t) addr;
}
-#elif defined(HAVE_DECL_LLVMORCGETSYMBOLADDRESSIN) && HAVE_DECL_LLVMORCGETSYMBOLADDRESSIN
- foreach(lc, context->handles)
- {
- LLVMOrcTargetAddress addr;
- LLVMJitHandle *handle = (LLVMJitHandle *) lfirst(lc);
-
- addr = 0;
- if (LLVMOrcGetSymbolAddressIn(handle->stack, &addr, handle->orc_handle, funcname))
- elog(ERROR, "failed to look up symbol \"%s\"", funcname);
- if (addr)
- return (void *) (uintptr_t) addr;
- }
-#elif LLVM_VERSION_MAJOR < 5
- {
- LLVMOrcTargetAddress addr;
-
- if ((addr = LLVMOrcGetSymbolAddress(llvm_opt0_orc, funcname)))
- return (void *) (uintptr_t) addr;
- if ((addr = LLVMOrcGetSymbolAddress(llvm_opt3_orc, funcname)))
- return (void *) (uintptr_t) addr;
- }
-#else
- {
- LLVMOrcTargetAddress addr;
-
- if (LLVMOrcGetSymbolAddress(llvm_opt0_orc, &addr, funcname))
- elog(ERROR, "failed to look up symbol \"%s\"", funcname);
- if (addr)
- return (void *) (uintptr_t) addr;
- if (LLVMOrcGetSymbolAddress(llvm_opt3_orc, &addr, funcname))
- elog(ERROR, "failed to look up symbol \"%s\"", funcname);
- if (addr)
- return (void *) (uintptr_t) addr;
- }
-#endif
elog(ERROR, "failed to JIT: %s", funcname);
@@ -526,7 +463,7 @@ llvm_copy_attributes_at_index(LLVMValueRef v_from, LLVMValueRef v_to, uint32 ind
int num_attributes;
LLVMAttributeRef *attrs;
- num_attributes = LLVMGetAttributeCountAtIndexPG(v_from, index);
+ num_attributes = LLVMGetAttributeCountAtIndex(v_from, index);
/*
* Not just for efficiency: LLVM <= 3.9 crashes when
@@ -736,11 +673,7 @@ llvm_compile_module(LLVMJitContext *context)
MemoryContext oldcontext;
instr_time starttime;
instr_time endtime;
-#if LLVM_VERSION_MAJOR > 11
LLVMOrcLLJITRef compile_orc;
-#else
- LLVMOrcJITStackRef compile_orc;
-#endif
if (context->base.flags & PGJIT_OPT3)
compile_orc = llvm_opt3_orc;
@@ -797,7 +730,6 @@ llvm_compile_module(LLVMJitContext *context)
* faster instruction selection mechanism is used.
*/
INSTR_TIME_SET_CURRENT(starttime);
-#if LLVM_VERSION_MAJOR > 11
{
LLVMOrcThreadSafeModuleRef ts_module;
LLVMErrorRef error;
@@ -825,36 +757,6 @@ llvm_compile_module(LLVMJitContext *context)
/* LLVMOrcLLJITAddLLVMIRModuleWithRT takes ownership of the module */
}
-#elif LLVM_VERSION_MAJOR > 6
- {
- handle->stack = compile_orc;
- if (LLVMOrcAddEagerlyCompiledIR(compile_orc, &handle->orc_handle, context->module,
- llvm_resolve_symbol, NULL))
- elog(ERROR, "failed to JIT module");
-
- /* LLVMOrcAddEagerlyCompiledIR takes ownership of the module */
- }
-#elif LLVM_VERSION_MAJOR > 4
- {
- LLVMSharedModuleRef smod;
-
- smod = LLVMOrcMakeSharedModule(context->module);
- handle->stack = compile_orc;
- if (LLVMOrcAddEagerlyCompiledIR(compile_orc, &handle->orc_handle, smod,
- llvm_resolve_symbol, NULL))
- elog(ERROR, "failed to JIT module");
-
- LLVMOrcDisposeSharedModuleRef(smod);
- }
-#else /* LLVM 4.0 and 3.9 */
- {
- handle->stack = compile_orc;
- handle->orc_handle = LLVMOrcAddEagerlyCompiledIR(compile_orc, context->module,
- llvm_resolve_symbol, NULL);
-
- LLVMDisposeModule(context->module);
- }
-#endif
INSTR_TIME_SET_CURRENT(endtime);
INSTR_TIME_ACCUM_DIFF(context->base.instr.emission_counter,
@@ -966,7 +868,6 @@ llvm_session_initialize(void)
/* force symbols in main binary to be loaded */
LLVMLoadLibraryPermanently(NULL);
-#if LLVM_VERSION_MAJOR > 11
{
llvm_ts_context = LLVMOrcCreateNewThreadSafeContext();
@@ -976,31 +877,6 @@ llvm_session_initialize(void)
llvm_opt3_orc = llvm_create_jit_instance(opt3_tm);
opt3_tm = 0;
}
-#else /* LLVM_VERSION_MAJOR > 11 */
- {
- llvm_opt0_orc = LLVMOrcCreateInstance(opt0_tm);
- llvm_opt3_orc = LLVMOrcCreateInstance(opt3_tm);
-
-#if defined(HAVE_DECL_LLVMCREATEGDBREGISTRATIONLISTENER) && HAVE_DECL_LLVMCREATEGDBREGISTRATIONLISTENER
- if (jit_debugging_support)
- {
- LLVMJITEventListenerRef l = LLVMCreateGDBRegistrationListener();
-
- LLVMOrcRegisterJITEventListener(llvm_opt0_orc, l);
- LLVMOrcRegisterJITEventListener(llvm_opt3_orc, l);
- }
-#endif
-#if defined(HAVE_DECL_LLVMCREATEPERFJITEVENTLISTENER) && HAVE_DECL_LLVMCREATEPERFJITEVENTLISTENER
- if (jit_profiling_support)
- {
- LLVMJITEventListenerRef l = LLVMCreatePerfJITEventListener();
-
- LLVMOrcRegisterJITEventListener(llvm_opt0_orc, l);
- LLVMOrcRegisterJITEventListener(llvm_opt3_orc, l);
- }
-#endif
- }
-#endif /* LLVM_VERSION_MAJOR > 11 */
on_proc_exit(llvm_shutdown, 0);
@@ -1030,7 +906,6 @@ llvm_shutdown(int code, Datum arg)
elog(PANIC, "LLVMJitContext in use count not 0 at exit (is %zu)",
llvm_jit_context_in_use_count);
-#if LLVM_VERSION_MAJOR > 11
{
if (llvm_opt3_orc)
{
@@ -1048,31 +923,6 @@ llvm_shutdown(int code, Datum arg)
llvm_ts_context = NULL;
}
}
-#else /* LLVM_VERSION_MAJOR > 11 */
- {
- /* 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;
- }
- }
-#endif /* LLVM_VERSION_MAJOR > 11 */
}
/* helper for llvm_create_types, returning a function's return type */
@@ -1242,8 +1092,6 @@ llvm_resolve_symbol(const char *symname, void *ctx)
return (uint64_t) addr;
}
-#if LLVM_VERSION_MAJOR > 11
-
static LLVMErrorRef
llvm_resolve_symbols(LLVMOrcDefinitionGeneratorRef GeneratorObj, void *Ctx,
LLVMOrcLookupStateRef *LookupState, LLVMOrcLookupKind Kind,
@@ -1262,9 +1110,7 @@ llvm_resolve_symbols(LLVMOrcDefinitionGeneratorRef GeneratorObj, void *Ctx,
{
const char *name = LLVMOrcSymbolStringPoolEntryStr(LookupSet[i].Name);
-#if LLVM_VERSION_MAJOR > 12
LLVMOrcRetainSymbolStringPoolEntry(LookupSet[i].Name);
-#endif
symbols[i].Name = LookupSet[i].Name;
symbols[i].Sym.Address = llvm_resolve_symbol(name, NULL);
symbols[i].Sym.Flags.GenericFlags = LLVMJITSymbolGenericFlagsExported;
@@ -1392,5 +1238,3 @@ llvm_error_message(LLVMErrorRef error)
return msg;
}
-
-#endif /* LLVM_VERSION_MAJOR > 11 */
diff --git a/src/backend/jit/llvm/llvmjit_error.cpp b/src/backend/jit/llvm/llvmjit_error.cpp
index ea40f5a124..bcf51f12a9 100644
--- a/src/backend/jit/llvm/llvmjit_error.cpp
+++ b/src/backend/jit/llvm/llvmjit_error.cpp
@@ -29,16 +29,8 @@ static int fatal_new_handler_depth = 0;
static std::new_handler old_new_handler = NULL;
static void fatal_system_new_handler(void);
-#if LLVM_VERSION_MAJOR > 4
static void fatal_llvm_new_handler(void *user_data, const char *reason, bool gen_crash_diag);
-#if LLVM_VERSION_MAJOR < 14
-static void fatal_llvm_new_handler(void *user_data, const std::string& reason, bool gen_crash_diag);
-#endif
-#endif
static void fatal_llvm_error_handler(void *user_data, const char *reason, bool gen_crash_diag);
-#if LLVM_VERSION_MAJOR < 14
-static void fatal_llvm_error_handler(void *user_data, const std::string& reason, bool gen_crash_diag);
-#endif
/*
@@ -65,9 +57,7 @@ llvm_enter_fatal_on_oom(void)
if (fatal_new_handler_depth == 0)
{
old_new_handler = std::set_new_handler(fatal_system_new_handler);
-#if LLVM_VERSION_MAJOR > 4
llvm::install_bad_alloc_error_handler(fatal_llvm_new_handler);
-#endif
llvm::install_fatal_error_handler(fatal_llvm_error_handler);
}
fatal_new_handler_depth++;
@@ -83,9 +73,7 @@ llvm_leave_fatal_on_oom(void)
if (fatal_new_handler_depth == 0)
{
std::set_new_handler(old_new_handler);
-#if LLVM_VERSION_MAJOR > 4
llvm::remove_bad_alloc_error_handler();
-#endif
llvm::remove_fatal_error_handler();
}
}
@@ -110,9 +98,7 @@ llvm_reset_after_error(void)
if (fatal_new_handler_depth != 0)
{
std::set_new_handler(old_new_handler);
-#if LLVM_VERSION_MAJOR > 4
llvm::remove_bad_alloc_error_handler();
-#endif
llvm::remove_fatal_error_handler();
}
fatal_new_handler_depth = 0;
@@ -133,7 +119,6 @@ fatal_system_new_handler(void)
errdetail("while in LLVM")));
}
-#if LLVM_VERSION_MAJOR > 4
static void
fatal_llvm_new_handler(void *user_data,
const char *reason,
@@ -144,16 +129,6 @@ fatal_llvm_new_handler(void *user_data,
errmsg("out of memory"),
errdetail("While in LLVM: %s", reason)));
}
-#if LLVM_VERSION_MAJOR < 14
-static void
-fatal_llvm_new_handler(void *user_data,
- const std::string& reason,
- bool gen_crash_diag)
-{
- fatal_llvm_new_handler(user_data, reason.c_str(), gen_crash_diag);
-}
-#endif
-#endif
static void
fatal_llvm_error_handler(void *user_data,
@@ -164,13 +139,3 @@ fatal_llvm_error_handler(void *user_data,
(errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("fatal llvm error: %s", reason)));
}
-
-#if LLVM_VERSION_MAJOR < 14
-static void
-fatal_llvm_error_handler(void *user_data,
- const std::string& reason,
- bool gen_crash_diag)
-{
- fatal_llvm_error_handler(user_data, reason.c_str(), gen_crash_diag);
-}
-#endif
diff --git a/src/backend/jit/llvm/llvmjit_expr.c b/src/backend/jit/llvm/llvmjit_expr.c
index a3a0876bff..a950564afa 100644
--- a/src/backend/jit/llvm/llvmjit_expr.c
+++ b/src/backend/jit/llvm/llvmjit_expr.c
@@ -2644,12 +2644,8 @@ create_LifetimeEnd(LLVMModuleRef mod)
LLVMTypeRef param_types[2];
LLVMContextRef lc;
- /* LLVM 5+ has a variadic pointer argument */
-#if LLVM_VERSION_MAJOR < 5
- const char *nm = "llvm.lifetime.end";
-#else
+ /* variadic pointer argument */
const char *nm = "llvm.lifetime.end.p0i8";
-#endif
fn = LLVMGetNamedFunction(mod, nm);
if (fn)
diff --git a/src/backend/jit/llvm/llvmjit_inline.cpp b/src/backend/jit/llvm/llvmjit_inline.cpp
index d92d7f3c88..693bc6510b 100644
--- a/src/backend/jit/llvm/llvmjit_inline.cpp
+++ b/src/backend/jit/llvm/llvmjit_inline.cpp
@@ -49,12 +49,7 @@ extern "C"
#include <llvm/ADT/StringSet.h>
#include <llvm/ADT/StringMap.h>
#include <llvm/Analysis/ModuleSummaryAnalysis.h>
-#if LLVM_VERSION_MAJOR > 3
#include <llvm/Bitcode/BitcodeReader.h>
-#else
-#include <llvm/Bitcode/ReaderWriter.h>
-#include <llvm/Support/Error.h>
-#endif
#include <llvm/IR/Attributes.h>
#include <llvm/IR/DebugInfo.h>
#include <llvm/IR/IntrinsicInst.h>
@@ -267,14 +262,12 @@ llvm_build_inline_plan(LLVMContextRef lc, llvm::Module *mod)
fs = llvm::cast<llvm::FunctionSummary>(gvs);
-#if LLVM_VERSION_MAJOR > 3
if (gvs->notEligibleToImport())
{
ilog(DEBUG1, "ineligibile to import %s due to summary",
symbolName.data());
continue;
}
-#endif
if ((int) fs->instCount() > inlineState.costLimit)
{
@@ -458,16 +451,9 @@ llvm_execute_inline_plan(llvm::Module *mod, ImportMapTy *globalsToInline)
}
-#if LLVM_VERSION_MAJOR > 4
-#define IRMOVE_PARAMS , /*IsPerformingImport=*/false
-#elif LLVM_VERSION_MAJOR > 3
-#define IRMOVE_PARAMS , /*LinkModuleInlineAsm=*/false, /*IsPerformingImport=*/false
-#else
-#define IRMOVE_PARAMS
-#endif
if (Mover.move(std::move(importMod), GlobalsToImport.getArrayRef(),
- [](llvm::GlobalValue &, llvm::IRMover::ValueAdder) {}
- IRMOVE_PARAMS))
+ [](llvm::GlobalValue &, llvm::IRMover::ValueAdder) {},
+ /*IsPerformingImport=*/false))
elog(FATAL, "function import failed with linker error");
}
}
@@ -608,10 +594,6 @@ function_inlinable(llvm::Function &F,
if (F.materialize())
elog(FATAL, "failed to materialize metadata");
-#if LLVM_VERSION_MAJOR < 14
-#define hasFnAttr hasFnAttribute
-#endif
-
if (F.getAttributes().hasFnAttr(llvm::Attribute::NoInline))
{
ilog(DEBUG1, "ineligibile to import %s due to noinline",
@@ -793,7 +775,6 @@ llvm_load_summary(llvm::StringRef path)
{
llvm::MemoryBufferRef ref(*MBOrErr.get().get());
-#if LLVM_VERSION_MAJOR > 3
llvm::Expected<std::unique_ptr<llvm::ModuleSummaryIndex> > IndexOrErr =
llvm::getModuleSummaryIndex(ref);
if (IndexOrErr)
@@ -801,15 +782,6 @@ llvm_load_summary(llvm::StringRef path)
elog(FATAL, "failed to load summary \"%s\": %s",
path.data(),
toString(IndexOrErr.takeError()).c_str());
-#else
- llvm::ErrorOr<std::unique_ptr<llvm::ModuleSummaryIndex> > IndexOrErr =
- llvm::getModuleSummaryIndex(ref, [](const llvm::DiagnosticInfo &) {});
- if (IndexOrErr)
- return std::move(IndexOrErr.get());
- elog(FATAL, "failed to load summary \"%s\": %s",
- path.data(),
- IndexOrErr.getError().message().c_str());
-#endif
}
return nullptr;
}
@@ -853,22 +825,12 @@ summaries_for_guid(const InlineSearchPath& path, llvm::GlobalValue::GUID guid)
for (auto index : path)
{
-#if LLVM_VERSION_MAJOR > 4
llvm::ValueInfo funcVI = index->getValueInfo(guid);
/* if index doesn't know function, we don't have a body, continue */
if (funcVI)
for (auto &gv : funcVI.getSummaryList())
matches.push_back(gv.get());
-#else
- const llvm::const_gvsummary_iterator &I =
- index->findGlobalValueSummaryList(guid);
- if (I != index->end())
- {
- for (auto &gv : I->second)
- matches.push_back(gv.get());
- }
-#endif
}
return matches;
@@ -889,9 +851,6 @@ create_redirection_function(std::unique_ptr<llvm::Module> &importMod,
llvm::Function *AF;
llvm::BasicBlock *BB;
llvm::CallInst *fwdcall;
-#if LLVM_VERSION_MAJOR < 14
- llvm::Attribute inlineAttribute;
-#endif
AF = llvm::Function::Create(F->getFunctionType(),
LinkageTypes::AvailableExternallyLinkage,
@@ -900,13 +859,7 @@ create_redirection_function(std::unique_ptr<llvm::Module> &importMod,
Builder.SetInsertPoint(BB);
fwdcall = Builder.CreateCall(F, &*AF->arg_begin());
-#if LLVM_VERSION_MAJOR < 14
- inlineAttribute = llvm::Attribute::get(Context,
- llvm::Attribute::AlwaysInline);
- fwdcall->addAttribute(~0U, inlineAttribute);
-#else
fwdcall->addFnAttr(llvm::Attribute::AlwaysInline);
-#endif
Builder.CreateRet(fwdcall);
return AF;
diff --git a/src/backend/jit/llvm/llvmjit_wrap.cpp b/src/backend/jit/llvm/llvmjit_wrap.cpp
index 90a41b9191..2d697fd2cc 100644
--- a/src/backend/jit/llvm/llvmjit_wrap.cpp
+++ b/src/backend/jit/llvm/llvmjit_wrap.cpp
@@ -17,20 +17,7 @@ extern "C"
}
#include <llvm-c/Core.h>
-
-/* Avoid macro clash with LLVM's C++ headers */
-#undef Min
-
-#include <llvm/IR/Attributes.h>
#include <llvm/IR/Function.h>
-#if LLVM_VERSION_MAJOR < 17
-#include <llvm/MC/SubtargetFeature.h>
-#endif
-#if LLVM_VERSION_MAJOR > 16
-#include <llvm/TargetParser/Host.h>
-#else
-#include <llvm/Support/Host.h>
-#endif
#include "jit/llvmjit.h"
@@ -38,50 +25,6 @@ extern "C"
/*
* C-API extensions.
*/
-#if defined(HAVE_DECL_LLVMGETHOSTCPUNAME) && !HAVE_DECL_LLVMGETHOSTCPUNAME
-char *LLVMGetHostCPUName(void) {
- return strdup(llvm::sys::getHostCPUName().data());
-}
-#endif
-
-
-#if defined(HAVE_DECL_LLVMGETHOSTCPUFEATURES) && !HAVE_DECL_LLVMGETHOSTCPUFEATURES
-char *LLVMGetHostCPUFeatures(void) {
- llvm::SubtargetFeatures Features;
- llvm::StringMap<bool> HostFeatures;
-
- if (llvm::sys::getHostCPUFeatures(HostFeatures))
- for (auto &F : HostFeatures)
- Features.AddFeature(F.first(), F.second);
-
- return strdup(Features.getString().c_str());
-}
-#endif
-
-/*
- * Like LLVM's LLVMGetAttributeCountAtIndex(), works around a bug in LLVM 3.9.
- *
- * In LLVM <= 3.9, LLVMGetAttributeCountAtIndex() segfaults if there are no
- * attributes at an index (fixed in LLVM commit ce9bb1097dc2).
- */
-unsigned
-LLVMGetAttributeCountAtIndexPG(LLVMValueRef F, uint32 Idx)
-{
- /*
- * This is more expensive, so only do when using a problematic LLVM
- * version.
- */
-#if LLVM_VERSION_MAJOR < 4
- if (!llvm::unwrap<llvm::Function>(F)->getAttributes().hasAttributes(Idx))
- return 0;
-#endif
-
- /*
- * There is no nice public API to determine the count nicely, so just
- * always fall back to LLVM's C API.
- */
- return LLVMGetAttributeCountAtIndex(F, Idx);
-}
LLVMTypeRef
LLVMGetFunctionReturnType(LLVMValueRef r)
@@ -94,11 +37,3 @@ LLVMGetFunctionType(LLVMValueRef r)
{
return llvm::wrap(llvm::unwrap<llvm::Function>(r)->getFunctionType());
}
-
-#if LLVM_VERSION_MAJOR < 8
-LLVMTypeRef
-LLVMGlobalGetValueType(LLVMValueRef g)
-{
- return llvm::wrap(llvm::unwrap<llvm::GlobalValue>(g)->getValueType());
-}
-#endif
diff --git a/src/include/jit/llvmjit.h b/src/include/jit/llvmjit.h
index 3ab86de3ac..e90b390bf4 100644
--- a/src/include/jit/llvmjit.h
+++ b/src/include/jit/llvmjit.h
@@ -130,26 +130,9 @@ extern LLVMValueRef slot_compile_deform(struct LLVMJitContext *context, TupleDes
* Error handling related functions.
****************************************************************************
*/
-#if defined(HAVE_DECL_LLVMGETHOSTCPUNAME) && !HAVE_DECL_LLVMGETHOSTCPUNAME
-/** Get the host CPU as a string. The result needs to be disposed with
- LLVMDisposeMessage. */
-extern char *LLVMGetHostCPUName(void);
-#endif
-
-#if defined(HAVE_DECL_LLVMGETHOSTCPUFEATURES) && !HAVE_DECL_LLVMGETHOSTCPUFEATURES
-/** Get the host CPU features as a string. The result needs to be disposed
- with LLVMDisposeMessage. */
-extern char *LLVMGetHostCPUFeatures(void);
-#endif
-
-extern unsigned LLVMGetAttributeCountAtIndexPG(LLVMValueRef F, uint32 Idx);
extern LLVMTypeRef LLVMGetFunctionReturnType(LLVMValueRef r);
extern LLVMTypeRef LLVMGetFunctionType(LLVMValueRef r);
-#if LLVM_MAJOR_VERSION < 8
-extern LLVMTypeRef LLVMGlobalGetValueType(LLVMValueRef g);
-#endif
-
#ifdef __cplusplus
} /* extern "C" */
#endif
diff --git a/src/include/pg_config.h.in b/src/include/pg_config.h.in
index d8a2985567..481470ee59 100644
--- a/src/include/pg_config.h.in
+++ b/src/include/pg_config.h.in
@@ -103,18 +103,6 @@
`LLVMCreatePerfJITEventListener', and to 0 if you don't. */
#undef HAVE_DECL_LLVMCREATEPERFJITEVENTLISTENER
-/* Define to 1 if you have the declaration of `LLVMGetHostCPUFeatures', and to
- 0 if you don't. */
-#undef HAVE_DECL_LLVMGETHOSTCPUFEATURES
-
-/* Define to 1 if you have the declaration of `LLVMGetHostCPUName', and to 0
- if you don't. */
-#undef HAVE_DECL_LLVMGETHOSTCPUNAME
-
-/* Define to 1 if you have the declaration of `LLVMOrcGetSymbolAddressIn', and
- to 0 if you don't. */
-#undef HAVE_DECL_LLVMORCGETSYMBOLADDRESSIN
-
/* 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/tools/msvc/Solution.pm b/src/tools/msvc/Solution.pm
index a50f730260..5066bd9e28 100644
--- a/src/tools/msvc/Solution.pm
+++ b/src/tools/msvc/Solution.pm
@@ -235,9 +235,6 @@ sub GenerateFiles
HAVE_DECL_F_FULLFSYNC => 0,
HAVE_DECL_LLVMCREATEGDBREGISTRATIONLISTENER => 0,
HAVE_DECL_LLVMCREATEPERFJITEVENTLISTENER => 0,
- HAVE_DECL_LLVMGETHOSTCPUNAME => 0,
- HAVE_DECL_LLVMGETHOSTCPUFEATURES => 0,
- HAVE_DECL_LLVMORCGETSYMBOLADDRESSIN => 0,
HAVE_DECL_POSIX_FADVISE => 0,
HAVE_DECL_PREADV => 0,
HAVE_DECL_PWRITEV => 0,
--
2.42.0
v3-0002-jit-Use-opaque-pointers-in-all-supported-LLVM-ver.patchtext/x-patch; charset=US-ASCII; name=v3-0002-jit-Use-opaque-pointers-in-all-supported-LLVM-ver.patchDownload
From e63ccb052fc8902825a6c2c29951db70068be4e8 Mon Sep 17 00:00:00 2001
From: Thomas Munro <thomas.munro@gmail.com>
Date: Fri, 20 Oct 2023 15:13:26 +1300
Subject: [PATCH v3 2/2] jit: Use opaque pointers in all supported LLVM
versions.
Historically we adapted to different LLVM API changes when forced to by
new LLVM releases, but we tried to avoid changing how we interacted with
already-released LLVM versions, because we needed to back-patch into our
release branches and we wanted to keep them as stable as possible. For
PostgreSQL 17, having dropped support for LLVM versions < 14, let's be
more aggressive and adopt LLVM opaque pointers everywhere for tidier and
more consistent code.
Discussions: https://postgr.es/m/CA%2BhUKGLhNs5geZaVNj2EJ79Dx9W8fyWUU3HxcpZy55sMGcY%3DiA%40mail.gmail.com
---
configure | 89 --------------------------------
configure.ac | 3 --
src/backend/jit/llvm/llvmjit.c | 13 -----
src/backend/jit/llvm/meson.build | 3 --
src/include/jit/llvmjit_emit.h | 16 ------
5 files changed, 124 deletions(-)
diff --git a/configure b/configure
index 2d92e3dea3..8c6c01db84 100755
--- a/configure
+++ b/configure
@@ -7562,95 +7562,6 @@ if test x"$pgac_cv_prog_CLANGXX_cxxflags__fexcess_precision_standard" = x"yes";
fi
- { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${CLANG} supports -Xclang -no-opaque-pointers, for BITCODE_CFLAGS" >&5
-$as_echo_n "checking whether ${CLANG} supports -Xclang -no-opaque-pointers, for BITCODE_CFLAGS... " >&6; }
-if ${pgac_cv_prog_CLANG_cflags__Xclang__no_opaque_pointers+:} false; then :
- $as_echo_n "(cached) " >&6
-else
- pgac_save_CFLAGS=$CFLAGS
-pgac_save_CC=$CC
-CC=${CLANG}
-CFLAGS="${BITCODE_CFLAGS} -Xclang -no-opaque-pointers"
-ac_save_c_werror_flag=$ac_c_werror_flag
-ac_c_werror_flag=yes
-cat confdefs.h - <<_ACEOF >conftest.$ac_ext
-/* end confdefs.h. */
-
-int
-main ()
-{
-
- ;
- return 0;
-}
-_ACEOF
-if ac_fn_c_try_compile "$LINENO"; then :
- pgac_cv_prog_CLANG_cflags__Xclang__no_opaque_pointers=yes
-else
- pgac_cv_prog_CLANG_cflags__Xclang__no_opaque_pointers=no
-fi
-rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
-ac_c_werror_flag=$ac_save_c_werror_flag
-CFLAGS="$pgac_save_CFLAGS"
-CC="$pgac_save_CC"
-fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv_prog_CLANG_cflags__Xclang__no_opaque_pointers" >&5
-$as_echo "$pgac_cv_prog_CLANG_cflags__Xclang__no_opaque_pointers" >&6; }
-if test x"$pgac_cv_prog_CLANG_cflags__Xclang__no_opaque_pointers" = x"yes"; then
- BITCODE_CFLAGS="${BITCODE_CFLAGS} -Xclang -no-opaque-pointers"
-fi
-
- { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${CLANGXX} supports -Xclang -no-opaque-pointers, for BITCODE_CXXFLAGS" >&5
-$as_echo_n "checking whether ${CLANGXX} supports -Xclang -no-opaque-pointers, for BITCODE_CXXFLAGS... " >&6; }
-if ${pgac_cv_prog_CLANGXX_cxxflags__Xclang__no_opaque_pointers+:} false; then :
- $as_echo_n "(cached) " >&6
-else
- pgac_save_CXXFLAGS=$CXXFLAGS
-pgac_save_CXX=$CXX
-CXX=${CLANGXX}
-CXXFLAGS="${BITCODE_CXXFLAGS} -Xclang -no-opaque-pointers"
-ac_save_cxx_werror_flag=$ac_cxx_werror_flag
-ac_cxx_werror_flag=yes
-ac_ext=cpp
-ac_cpp='$CXXCPP $CPPFLAGS'
-ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5'
-ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
-ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
-
-cat confdefs.h - <<_ACEOF >conftest.$ac_ext
-/* end confdefs.h. */
-
-int
-main ()
-{
-
- ;
- return 0;
-}
-_ACEOF
-if ac_fn_cxx_try_compile "$LINENO"; then :
- pgac_cv_prog_CLANGXX_cxxflags__Xclang__no_opaque_pointers=yes
-else
- pgac_cv_prog_CLANGXX_cxxflags__Xclang__no_opaque_pointers=no
-fi
-rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
-ac_ext=c
-ac_cpp='$CPP $CPPFLAGS'
-ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
-ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
-ac_compiler_gnu=$ac_cv_c_compiler_gnu
-
-ac_cxx_werror_flag=$ac_save_cxx_werror_flag
-CXXFLAGS="$pgac_save_CXXFLAGS"
-CXX="$pgac_save_CXX"
-fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv_prog_CLANGXX_cxxflags__Xclang__no_opaque_pointers" >&5
-$as_echo "$pgac_cv_prog_CLANGXX_cxxflags__Xclang__no_opaque_pointers" >&6; }
-if test x"$pgac_cv_prog_CLANGXX_cxxflags__Xclang__no_opaque_pointers" = x"yes"; then
- BITCODE_CXXFLAGS="${BITCODE_CXXFLAGS} -Xclang -no-opaque-pointers"
-fi
-
-
NOT_THE_CFLAGS=""
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${CLANG} supports -Wunused-command-line-argument, for NOT_THE_CFLAGS" >&5
$as_echo_n "checking whether ${CLANG} supports -Wunused-command-line-argument, for NOT_THE_CFLAGS... " >&6; }
diff --git a/configure.ac b/configure.ac
index 440b08d113..2947d0d37a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -649,9 +649,6 @@ if test "$with_llvm" = yes ; then
PGAC_PROG_VARCC_VARFLAGS_OPT(CLANG, BITCODE_CFLAGS, [-fexcess-precision=standard])
PGAC_PROG_VARCXX_VARFLAGS_OPT(CLANGXX, BITCODE_CXXFLAGS, [-fexcess-precision=standard])
- PGAC_PROG_VARCC_VARFLAGS_OPT(CLANG, BITCODE_CFLAGS, [-Xclang -no-opaque-pointers])
- PGAC_PROG_VARCXX_VARFLAGS_OPT(CLANGXX, BITCODE_CXXFLAGS, [-Xclang -no-opaque-pointers])
-
NOT_THE_CFLAGS=""
PGAC_PROG_VARCC_VARFLAGS_OPT(CLANG, NOT_THE_CFLAGS, [-Wunused-command-line-argument])
if test -n "$NOT_THE_CFLAGS"; then
diff --git a/src/backend/jit/llvm/llvmjit.c b/src/backend/jit/llvm/llvmjit.c
index d31e4759a6..a3a44e13e9 100644
--- a/src/backend/jit/llvm/llvmjit.c
+++ b/src/backend/jit/llvm/llvmjit.c
@@ -809,19 +809,6 @@ llvm_session_initialize(void)
llvm_llvm_context_reuse_count = 0;
}
- /*
- * When targeting LLVM 15, turn off opaque pointers for the context we
- * build our code in. We don't need to do so for other contexts (e.g.
- * llvm_ts_context). Once the IR is generated, it carries the necessary
- * information.
- *
- * For 16 and above, opaque pointers must be used, and we have special
- * code for that.
- */
-#if LLVM_VERSION_MAJOR == 15
- LLVMContextSetOpaquePointers(LLVMGetGlobalContext(), false);
-#endif
-
/*
* Synchronize types early, as that also includes inferring the target
* triple.
diff --git a/src/backend/jit/llvm/meson.build b/src/backend/jit/llvm/meson.build
index 8ffaf41460..4743333c3f 100644
--- a/src/backend/jit/llvm/meson.build
+++ b/src/backend/jit/llvm/meson.build
@@ -60,9 +60,6 @@ endif
# XXX: Need to determine proper version of the function cflags for clang
bitcode_cflags = ['-fno-strict-aliasing', '-fwrapv']
-if llvm.version().version_compare('=15.0')
- bitcode_cflags += ['-Xclang', '-no-opaque-pointers']
-endif
bitcode_cflags += cppflags
# XXX: Worth improving on the logic to find directories here
diff --git a/src/include/jit/llvmjit_emit.h b/src/include/jit/llvmjit_emit.h
index b1f0ea56c0..a37b723d28 100644
--- a/src/include/jit/llvmjit_emit.h
+++ b/src/include/jit/llvmjit_emit.h
@@ -107,41 +107,25 @@ l_pbool_const(bool i)
static inline LLVMValueRef
l_struct_gep(LLVMBuilderRef b, LLVMTypeRef t, LLVMValueRef v, int32 idx, const char *name)
{
-#if LLVM_VERSION_MAJOR < 16
- return LLVMBuildStructGEP(b, v, idx, "");
-#else
return LLVMBuildStructGEP2(b, t, v, idx, "");
-#endif
}
static inline LLVMValueRef
l_gep(LLVMBuilderRef b, LLVMTypeRef t, LLVMValueRef v, LLVMValueRef *indices, int32 nindices, const char *name)
{
-#if LLVM_VERSION_MAJOR < 16
- return LLVMBuildGEP(b, v, indices, nindices, name);
-#else
return LLVMBuildGEP2(b, t, v, indices, nindices, name);
-#endif
}
static inline LLVMValueRef
l_load(LLVMBuilderRef b, LLVMTypeRef t, LLVMValueRef v, const char *name)
{
-#if LLVM_VERSION_MAJOR < 16
- return LLVMBuildLoad(b, v, name);
-#else
return LLVMBuildLoad2(b, t, v, name);
-#endif
}
static inline LLVMValueRef
l_call(LLVMBuilderRef b, LLVMTypeRef t, LLVMValueRef fn, LLVMValueRef *args, int32 nargs, const char *name)
{
-#if LLVM_VERSION_MAJOR < 16
- return LLVMBuildCall(b, fn, args, nargs, name);
-#else
return LLVMBuildCall2(b, t, fn, args, nargs, name);
-#endif
}
/*
--
2.42.0
Hi,
Can we also check if the clang's version is compatible with llvm's version
in llvm.m4? I have multiple llvm toolchains installed on my system and I
have to specify the $CLANG and $LLVM_CONFIG variables each time I build the
server against a toolchain that is not present in $PATH. If one of the
variables is missing, the build system will pick up a default one whose
version might not be compatible with the other. E.g., If we use clang-16
and llvm-config-15, there will be issues when creating indexes for bitcodes
at the end of installation.
There will be errors look like
```
LLVM ERROR: ThinLTO cannot create input file: Unknown attribute kind (86)
(Producer: 'LLVM16.0.6' Reader: 'LLVM 15.0.7')
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/
and include the crash backtrace.
Stack dump:
0. Program arguments: /usr/lib/llvm15/bin/llvm-lto -thinlto
-thinlto-action=thinlink -o postgres.index.bc postgres/access/brin/brin.bc
postgres/access/brin/brin_bloom.bc postgres/acces
s/brin/brin_inclusion.bc postgres/access/brin/brin_minmax.bc
postgres/access/brin/brin_minmax_multi.bc
postgres/access/brin/brin_pageops.bc postgres/access/brin/brin_revmap.bc
postgres/acce
ss/brin/brin_tuple.bc postgres/access/brin/brin_validate.bc
postgres/access/brin/brin_xlog.bc postgres/access/common/attmap.bc
postgres/access/common/bufmask.bc postgres/access/common/detoa
st.bc postgres/access/common/heaptuple.bc
postgres/access/common/indextuple.bc postgres/access/common/printsimple.bc
postgres/access/common/printtup.bc postgres/access/common/relation.bc po
stgres/access/common/reloptions.bc postgres/access/common/scankey.bc
postgres/access/common/session.bc postgres/access/common/syncscan.bc
postgres/access/common/toast_compression.bc postgre
s/access/common/toast_internals.bc postgres/access/common/tupconvert.bc
postgres/access/common/tupdesc.bc postgres/access/gin/ginarrayproc.bc
postgres/access/gin/ginbtree.bc postgres/access
/gin/ginbulk.bc postgres/access/gin/gindatapage.bc
postgres/access/gin/ginentrypage.bc postgres/access/gin/ginfast.bc
postgres/access/gin/ginget.bc postgres/access/gin/gininsert.bc postgres
/access/gin/ginlogic.bc postgres/access/gin/ginpostinglist.bc
postgres/access/gin/ginscan.bc postgres/access/gin/ginutil.bc
postgres/access/gin/ginvacuum.bc postgres/access/gin/ginvalidate.
bc postgres/access/gin/ginxlog.bc postgres/access/gist/gist.bc
postgres/access/gist/gistbuild.bc postgres/access/gist/gistbuildbuffers.bc
postgres/access/gist/gistget.bc postgres/access/gis
t/gistproc.bc postgres/access/gist/gistscan.bc
postgres/access/gist/gistsplit.bc postgres/access/gist/gistutil.bc
postgres/access/gist/gistvacuum.bc postgres/access/gist/gistvalidate.bc pos
tgres/access/gist/gistxlog.bc postgres/access/hash/hash.bc
postgres/access/hash/hash_xlog.bc postgres/access/hash/hashfunc.bc
postgres/access/hash/hashinsert.bc postgres/access/hash/hashovf
l.bc postgres/access/hash/hashpage.bc postgres/access/hash/hashsearch.bc
postgres/access/hash/hashsort.bc postgres/access/hash/hashutil.bc
postgres/access/hash/hashvalidate.bc postgres/acce
ss/heap/heapam.bc postgres/access/heap/heapam_handler.bc
postgres/access/heap/heapam_visibility.bc postgres/access/heap/heaptoast.bc
postgres/access/heap/hio.bc postgres/access/heap/prunehe
```
If we can check the llvm-config versions and clang versions at the
configuration phase we can detect the problem earlier.
Best Regards,
Xing
On Sun, Oct 22, 2023 at 10:07 AM Thomas Munro <thomas.munro@gmail.com>
wrote:
Show quoted text
Rebased. I also noticed this woefully out of date line:
- PGAC_PATH_PROGS(LLVM_CONFIG, llvm-config llvm-config-7 llvm-config-6.0 llvm-config-5.0 llvm-config-4.0 llvm-config-3.9) + PGAC_PATH_PROGS(LLVM_CONFIG, llvm-config llvm-config-17 llvm-config-16 llvm-config-15 llvm-config-14)
On Sun, Oct 22, 2023 at 3:46 PM Xing Guo <higuoxing@gmail.com> wrote:
Can we also check if the clang's version is compatible with llvm's version in llvm.m4? I have multiple llvm toolchains installed on my system and I have to specify the $CLANG and $LLVM_CONFIG variables each time I build the server against a toolchain that is not present in $PATH. If one of the variables is missing, the build system will pick up a default one whose version might not be compatible with the other. E.g., If we use clang-16 and llvm-config-15, there will be issues when creating indexes for bitcodes at the end of installation.
Hmm. Problems that occur to me:
1. We need to decide if our rule is that clang must be <= llvm, or
==. I think this question has been left unanswered in the past when
it has come up. So far I think <= would be enough to avoid the error
you showed but can we find where this policy (ie especially
commitments for future releases) is written down in LLVM literature?
2. Apple's clang lies about its version (I don't know the story
behind that, but my wild guess is that someone from marketing wanted
the compiler's version numbers to align with xcode's version numbers?
they're off by 1 or something like that).
Another idea could be to produce some bitcode with clang, and then
check if a relevant LLVM tool can deal with it.
Hi,
On October 21, 2023 7:46:17 PM PDT, Xing Guo <higuoxing@gmail.com> wrote:
Can we also check if the clang's version is compatible with llvm's version
in llvm.m4? I have multiple llvm toolchains installed on my system and I
have to specify the $CLANG and $LLVM_CONFIG variables each time I build the
server against a toolchain that is not present in $PATH. If one of the
variables is missing, the build system will pick up a default one whose
version might not be compatible with the other. E.g., If we use clang-16
and llvm-config-15, there will be issues when creating indexes for bitcodes
at the end of installation.
It's unfortunately not that obvious to figure out what is compatible and what not. Older clang versions work, except if too old. Newer versions sometimes work. We could perhaps write a script that will find many, but not all, incompatibilities.
For the meson build I made it just use clang belonging to the llvm install - but that's very painful when building against an assert enabled llvm, clang is slower by an order of magnitude or so.
I wonder if we should change the search order to 1) CLANG, iff explicitly specified, 2) use explicitly specified or inferred llvm-config, 3) only if that didn't find clang, search path.
wrote:
Rebased. I also noticed this woefully out of date line:
- PGAC_PATH_PROGS(LLVM_CONFIG, llvm-config llvm-config-7 llvm-config-6.0 llvm-config-5.0 llvm-config-4.0 llvm-config-3.9) + PGAC_PATH_PROGS(LLVM_CONFIG, llvm-config llvm-config-17 llvm-config-16 llvm-config-15 llvm-config-14)
It's outdated, but not completely absurd - back then often no llvm-config -> llvm-config-XY was installed, but these days there pretty much always is.
Andres
--
Sent from my Android device with K-9 Mail. Please excuse my brevity.
Here are some systematic rules I'd like to propose to anchor this
stuff to reality and avoid future doubt and litigation:
1. Build farm animals testing LLVM determine the set of OSes and LLVM
versions we consider.
2. We exclude OSes that will be out of full vendor support when a
release ships.
3. We exclude OSes that don't bless an LLVM release (eg macOS running
an arbitrarily picked version), and animals running only to cover
ancient LLVM compiled from source for coverage (Andres's sid
menagerie).
By these rules we can't require LLVM 14 for another year, because
Ubuntu and Amazon Linux are standing in the way*:
animal | arch | llvm_version | os | os_release | end_of_support
---------------+---------+--------------+--------+------------+----------------
branta | s390x | 10.0.0 | Ubuntu | 20.04 | 2025-04-01
splitfin | aarch64 | 10.0.0 | Ubuntu | 20.04 | 2025-04-01
urutau | s390x | 10.0.0 | Ubuntu | 20.04 | 2025-04-01
massasauga | aarch64 | 11.1.0 | Amazon | 2 | 2025-06-30
snakefly | aarch64 | 11.1.0 | Amazon | 2 | 2025-06-30
sarus | s390x | 14.0.0 | Ubuntu | 22.04 | 2027-06-01
shiner | aarch64 | 14.0.0 | Ubuntu | 22.04 | 2027-06-01
turbot | aarch64 | 14.0.0 | Ubuntu | 22.04 | 2027-06-01
lora | s390x | 15.0.7 | RHEL | 9 | 2027-05-31
mamushi | s390x | 15.0.7 | RHEL | 9 | 2027-05-31
nicator | ppc64le | 15.0.7 | Alma | 9 | 2027-05-31
oystercatcher | aarch64 | 15.0.7 | Alma | 9 | 2027-05-31
Ideally more distros would be present in this vacuum-horizon decision
table, but I don't think it'd change the conclusion: 10 is the
trailing edge. Therefore the attached patch scales back its ambition
to that release. Tested on LLVM 10-18.
If I pushed this we'd need to disable or upgrade the following to
avoid failure in configure on master:
animal | arch | llvm_version | os | os_release
| end_of_support
-------------+--------------------+--------------+--------+------------+----------------
dragonet | x86_64 | 3.9.1 | Debian | sid |
phycodurus | x86_64 | 3.9.1 | Debian | sid |
desmoxytes | x86_64 | 4.0.1 | Debian | sid |
petalura | x86_64 | 4.0.1 | Debian | sid |
mantid | x86_64 | 5.0.1 | CentOS | 7
| 2019-08-06
idiacanthus | x86_64 | 5.0.2 | Debian | sid |
pogona | x86_64 | 5.0.2 | Debian | sid |
cotinga | s390x | 6.0.0 | Ubuntu | 18.04
| 2023-06-01
vimba | aarch64 | 6.0.0 | Ubuntu | 18.04
| 2023-06-01
komodoensis | x86_64 | 6.0.1 | Debian | sid |
topminnow | mips64el; -mabi=32 | 6.0.1 | Debian | 8
| 2018-06-17
xenodermus | x86_64 | 6.0.1 | Debian | sid |
alimoche | aarch64 | 7.0.1 | Debian | 10
| 2022-09-10
blackneck | aarch64 | 7.0.1 | Debian | 10
| 2022-09-10
bonito | ppc64le | 7.0.1 | Fedora | 29
| 2019-11-26
*Some distros announce EOL date by month without saying which day, so
in my data collecting operation I just punched in the first of the
month, *shrug*
Attachments:
v4-0001-jit-Require-at-least-LLVM-10.patchtext/x-patch; charset=US-ASCII; name=v4-0001-jit-Require-at-least-LLVM-10.patchDownload
From 581b88879316065dab113d1512aeac7e9932b0af Mon Sep 17 00:00:00 2001
From: Thomas Munro <thomas.munro@gmail.com>
Date: Thu, 19 Oct 2023 04:45:46 +1300
Subject: [PATCH v4] jit: Require at least LLVM 10.
Remove support for older LLVM versions. The default on common software
distributions will be at least LLVM 10 when PostgreSQL 17 ships.
Discussion: https://postgr.es/m/CA%2BhUKGLhNs5geZaVNj2EJ79Dx9W8fyWUU3HxcpZy55sMGcY%3DiA%40mail.gmail.com
---
config/llvm.m4 | 10 ++--
configure | 43 ++---------------
doc/src/sgml/installation.sgml | 4 +-
meson.build | 2 +-
src/backend/jit/llvm/llvmjit.c | 53 ++-------------------
src/backend/jit/llvm/llvmjit_error.cpp | 10 ----
src/backend/jit/llvm/llvmjit_expr.c | 6 +--
src/backend/jit/llvm/llvmjit_inline.cpp | 38 +--------------
src/backend/jit/llvm/llvmjit_wrap.cpp | 61 -------------------------
src/include/jit/llvmjit.h | 17 -------
src/include/pg_config.h.in | 12 -----
src/tools/msvc/Solution.pm | 3 --
12 files changed, 17 insertions(+), 242 deletions(-)
diff --git a/config/llvm.m4 b/config/llvm.m4
index 21d8cd4f90..44769d819a 100644
--- a/config/llvm.m4
+++ b/config/llvm.m4
@@ -13,7 +13,7 @@ AC_DEFUN([PGAC_LLVM_SUPPORT],
AC_REQUIRE([AC_PROG_AWK])
AC_ARG_VAR(LLVM_CONFIG, [path to llvm-config command])
- PGAC_PATH_PROGS(LLVM_CONFIG, llvm-config llvm-config-7 llvm-config-6.0 llvm-config-5.0 llvm-config-4.0 llvm-config-3.9)
+ PGAC_PATH_PROGS(LLVM_CONFIG, llvm-config llvm-config-17 llvm-config-16 llvm-config-15 llvm-config-14 llvm-config-13 llvm-config-12 llvm-config-11 llvm-config-10)
# no point continuing if llvm wasn't found
if test -z "$LLVM_CONFIG"; then
@@ -25,14 +25,14 @@ AC_DEFUN([PGAC_LLVM_SUPPORT],
AC_MSG_ERROR([$LLVM_CONFIG does not work])
fi
# and whether the version is supported
- if echo $pgac_llvm_version | $AWK -F '.' '{ if ([$]1 >= 4 || ([$]1 == 3 && [$]2 >= 9)) exit 1; else exit 0;}';then
- AC_MSG_ERROR([$LLVM_CONFIG version is $pgac_llvm_version but at least 3.9 is required])
+ if echo $pgac_llvm_version | $AWK -F '.' '{ if ([$]1 >= 10) exit 1; else exit 0;}';then
+ AC_MSG_ERROR([$LLVM_CONFIG version is $pgac_llvm_version but at least 10 is required])
fi
AC_MSG_NOTICE([using llvm $pgac_llvm_version])
# need clang to create some bitcode files
AC_ARG_VAR(CLANG, [path to clang compiler to generate bitcode])
- PGAC_PATH_PROGS(CLANG, clang clang-7 clang-6.0 clang-5.0 clang-4.0 clang-3.9)
+ PGAC_PATH_PROGS(CLANG, clang clang-17 clang-16 clang-15 clang-14 clang-13 clang-12 clang-11 clang-10)
if test -z "$CLANG"; then
AC_MSG_ERROR([clang not found, but required when compiling --with-llvm, specify with CLANG=])
fi
@@ -115,8 +115,6 @@ AC_DEFUN([PGAC_CHECK_LLVM_FUNCTIONS],
# Check which functionality is present
SAVE_CPPFLAGS="$CPPFLAGS"
CPPFLAGS="$CPPFLAGS $LLVM_CPPFLAGS"
- AC_CHECK_DECLS([LLVMOrcGetSymbolAddressIn], [], [], [[#include <llvm-c/OrcBindings.h>]])
- AC_CHECK_DECLS([LLVMGetHostCPUName, LLVMGetHostCPUFeatures], [], [], [[#include <llvm-c/TargetMachine.h>]])
AC_CHECK_DECLS([LLVMCreateGDBRegistrationListener, LLVMCreatePerfJITEventListener], [], [], [[#include <llvm-c/ExecutionEngine.h>]])
CPPFLAGS="$SAVE_CPPFLAGS"
])# PGAC_CHECK_LLVM_FUNCTIONS
diff --git a/configure b/configure
index c2cb1b1b24..1f848959ef 100755
--- a/configure
+++ b/configure
@@ -5056,7 +5056,7 @@ if test "$with_llvm" = yes; then :
if test -z "$LLVM_CONFIG"; then
- for ac_prog in llvm-config llvm-config-7 llvm-config-6.0 llvm-config-5.0 llvm-config-4.0 llvm-config-3.9
+ for ac_prog in llvm-config llvm-config-17 llvm-config-16 llvm-config-15 llvm-config-14 llvm-config-13 llvm-config-12 llvm-config-11 llvm-config-10
do
# Extract the first word of "$ac_prog", so it can be a program name with args.
set dummy $ac_prog; ac_word=$2
@@ -5120,8 +5120,8 @@ fi
as_fn_error $? "$LLVM_CONFIG does not work" "$LINENO" 5
fi
# and whether the version is supported
- if echo $pgac_llvm_version | $AWK -F '.' '{ if ($1 >= 4 || ($1 == 3 && $2 >= 9)) exit 1; else exit 0;}';then
- as_fn_error $? "$LLVM_CONFIG version is $pgac_llvm_version but at least 3.9 is required" "$LINENO" 5
+ if echo $pgac_llvm_version | $AWK -F '.' '{ if ($1 >= 10) exit 1; else exit 0;}';then
+ as_fn_error $? "$LLVM_CONFIG version is $pgac_llvm_version but at least 10 is required" "$LINENO" 5
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: using llvm $pgac_llvm_version" >&5
$as_echo "$as_me: using llvm $pgac_llvm_version" >&6;}
@@ -5129,7 +5129,7 @@ $as_echo "$as_me: using llvm $pgac_llvm_version" >&6;}
# need clang to create some bitcode files
if test -z "$CLANG"; then
- for ac_prog in clang clang-7 clang-6.0 clang-5.0 clang-4.0 clang-3.9
+ for ac_prog in clang clang-17 clang-16 clang-15 clang-14 clang-13 clang-12 clang-11 clang-10
do
# Extract the first word of "$ac_prog", so it can be a program name with args.
set dummy $ac_prog; ac_word=$2
@@ -16573,41 +16573,6 @@ if test "$with_llvm" = yes; then
# Check which functionality is present
SAVE_CPPFLAGS="$CPPFLAGS"
CPPFLAGS="$CPPFLAGS $LLVM_CPPFLAGS"
- ac_fn_c_check_decl "$LINENO" "LLVMOrcGetSymbolAddressIn" "ac_cv_have_decl_LLVMOrcGetSymbolAddressIn" "#include <llvm-c/OrcBindings.h>
-"
-if test "x$ac_cv_have_decl_LLVMOrcGetSymbolAddressIn" = xyes; then :
- ac_have_decl=1
-else
- ac_have_decl=0
-fi
-
-cat >>confdefs.h <<_ACEOF
-#define HAVE_DECL_LLVMORCGETSYMBOLADDRESSIN $ac_have_decl
-_ACEOF
-
- ac_fn_c_check_decl "$LINENO" "LLVMGetHostCPUName" "ac_cv_have_decl_LLVMGetHostCPUName" "#include <llvm-c/TargetMachine.h>
-"
-if test "x$ac_cv_have_decl_LLVMGetHostCPUName" = xyes; then :
- ac_have_decl=1
-else
- ac_have_decl=0
-fi
-
-cat >>confdefs.h <<_ACEOF
-#define HAVE_DECL_LLVMGETHOSTCPUNAME $ac_have_decl
-_ACEOF
-ac_fn_c_check_decl "$LINENO" "LLVMGetHostCPUFeatures" "ac_cv_have_decl_LLVMGetHostCPUFeatures" "#include <llvm-c/TargetMachine.h>
-"
-if test "x$ac_cv_have_decl_LLVMGetHostCPUFeatures" = xyes; then :
- ac_have_decl=1
-else
- ac_have_decl=0
-fi
-
-cat >>confdefs.h <<_ACEOF
-#define HAVE_DECL_LLVMGETHOSTCPUFEATURES $ac_have_decl
-_ACEOF
-
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 :
diff --git a/doc/src/sgml/installation.sgml b/doc/src/sgml/installation.sgml
index 8e0b2705d3..dc95752f89 100644
--- a/doc/src/sgml/installation.sgml
+++ b/doc/src/sgml/installation.sgml
@@ -965,7 +965,7 @@ build-postgresql:
linkend="jit"/>)</phrase>. This
requires the <productname>LLVM</productname> library to be installed.
The minimum required version of <productname>LLVM</productname> is
- currently 3.9.
+ currently 10.
</para>
<para>
<command>llvm-config</command><indexterm><primary>llvm-config</primary></indexterm>
@@ -2432,7 +2432,7 @@ ninja install
condition="standalone-ignore"> (see <xref linkend="jit"/>)</phrase>.
This requires the <productname>LLVM</productname> library to be
installed. The minimum required version of
- <productname>LLVM</productname> is currently 3.9. Disabled by
+ <productname>LLVM</productname> is currently 10. Disabled by
default.
</para>
diff --git a/meson.build b/meson.build
index 2d516c8f37..8e43f76bdf 100644
--- a/meson.build
+++ b/meson.build
@@ -748,7 +748,7 @@ endif
llvmopt = get_option('llvm')
llvm = not_found_dep
if add_languages('cpp', required: llvmopt, native: false)
- llvm = dependency('llvm', version: '>=3.9', method: 'config-tool', required: llvmopt)
+ llvm = dependency('llvm', version: '>=10', method: 'config-tool', required: llvmopt)
if llvm.found()
diff --git a/src/backend/jit/llvm/llvmjit.c b/src/backend/jit/llvm/llvmjit.c
index 58f638859a..fcb065cec9 100644
--- a/src/backend/jit/llvm/llvmjit.c
+++ b/src/backend/jit/llvm/llvmjit.c
@@ -34,10 +34,8 @@
#include <llvm-c/Transforms/IPO.h>
#include <llvm-c/Transforms/PassManagerBuilder.h>
#include <llvm-c/Transforms/Scalar.h>
-#if LLVM_VERSION_MAJOR > 6
#include <llvm-c/Transforms/Utils.h>
#endif
-#endif
#include "jit/llvmjit.h"
#include "jit/llvmjit_emit.h"
@@ -354,10 +352,7 @@ llvm_expand_funcname(struct LLVMJitContext *context, const char *basename)
void *
llvm_get_function(LLVMJitContext *context, const char *funcname)
{
-#if LLVM_VERSION_MAJOR > 11 || \
- defined(HAVE_DECL_LLVMORCGETSYMBOLADDRESSIN) && HAVE_DECL_LLVMORCGETSYMBOLADDRESSIN
ListCell *lc;
-#endif
llvm_assert_in_fatal_section();
@@ -405,7 +400,7 @@ llvm_get_function(LLVMJitContext *context, const char *funcname)
if (addr)
return (void *) (uintptr_t) addr;
}
-#elif defined(HAVE_DECL_LLVMORCGETSYMBOLADDRESSIN) && HAVE_DECL_LLVMORCGETSYMBOLADDRESSIN
+#else
foreach(lc, context->handles)
{
LLVMOrcTargetAddress addr;
@@ -417,28 +412,6 @@ llvm_get_function(LLVMJitContext *context, const char *funcname)
if (addr)
return (void *) (uintptr_t) addr;
}
-#elif LLVM_VERSION_MAJOR < 5
- {
- LLVMOrcTargetAddress addr;
-
- if ((addr = LLVMOrcGetSymbolAddress(llvm_opt0_orc, funcname)))
- return (void *) (uintptr_t) addr;
- if ((addr = LLVMOrcGetSymbolAddress(llvm_opt3_orc, funcname)))
- return (void *) (uintptr_t) addr;
- }
-#else
- {
- LLVMOrcTargetAddress addr;
-
- if (LLVMOrcGetSymbolAddress(llvm_opt0_orc, &addr, funcname))
- elog(ERROR, "failed to look up symbol \"%s\"", funcname);
- if (addr)
- return (void *) (uintptr_t) addr;
- if (LLVMOrcGetSymbolAddress(llvm_opt3_orc, &addr, funcname))
- elog(ERROR, "failed to look up symbol \"%s\"", funcname);
- if (addr)
- return (void *) (uintptr_t) addr;
- }
#endif
elog(ERROR, "failed to JIT: %s", funcname);
@@ -526,7 +499,7 @@ llvm_copy_attributes_at_index(LLVMValueRef v_from, LLVMValueRef v_to, uint32 ind
int num_attributes;
LLVMAttributeRef *attrs;
- num_attributes = LLVMGetAttributeCountAtIndexPG(v_from, index);
+ num_attributes = LLVMGetAttributeCountAtIndex(v_from, index);
/*
* Not just for efficiency: LLVM <= 3.9 crashes when
@@ -825,7 +798,7 @@ llvm_compile_module(LLVMJitContext *context)
/* LLVMOrcLLJITAddLLVMIRModuleWithRT takes ownership of the module */
}
-#elif LLVM_VERSION_MAJOR > 6
+#else
{
handle->stack = compile_orc;
if (LLVMOrcAddEagerlyCompiledIR(compile_orc, &handle->orc_handle, context->module,
@@ -834,26 +807,6 @@ llvm_compile_module(LLVMJitContext *context)
/* LLVMOrcAddEagerlyCompiledIR takes ownership of the module */
}
-#elif LLVM_VERSION_MAJOR > 4
- {
- LLVMSharedModuleRef smod;
-
- smod = LLVMOrcMakeSharedModule(context->module);
- handle->stack = compile_orc;
- if (LLVMOrcAddEagerlyCompiledIR(compile_orc, &handle->orc_handle, smod,
- llvm_resolve_symbol, NULL))
- elog(ERROR, "failed to JIT module");
-
- LLVMOrcDisposeSharedModuleRef(smod);
- }
-#else /* LLVM 4.0 and 3.9 */
- {
- handle->stack = compile_orc;
- handle->orc_handle = LLVMOrcAddEagerlyCompiledIR(compile_orc, context->module,
- llvm_resolve_symbol, NULL);
-
- LLVMDisposeModule(context->module);
- }
#endif
INSTR_TIME_SET_CURRENT(endtime);
diff --git a/src/backend/jit/llvm/llvmjit_error.cpp b/src/backend/jit/llvm/llvmjit_error.cpp
index ea40f5a124..58b5959baf 100644
--- a/src/backend/jit/llvm/llvmjit_error.cpp
+++ b/src/backend/jit/llvm/llvmjit_error.cpp
@@ -29,12 +29,10 @@ static int fatal_new_handler_depth = 0;
static std::new_handler old_new_handler = NULL;
static void fatal_system_new_handler(void);
-#if LLVM_VERSION_MAJOR > 4
static void fatal_llvm_new_handler(void *user_data, const char *reason, bool gen_crash_diag);
#if LLVM_VERSION_MAJOR < 14
static void fatal_llvm_new_handler(void *user_data, const std::string& reason, bool gen_crash_diag);
#endif
-#endif
static void fatal_llvm_error_handler(void *user_data, const char *reason, bool gen_crash_diag);
#if LLVM_VERSION_MAJOR < 14
static void fatal_llvm_error_handler(void *user_data, const std::string& reason, bool gen_crash_diag);
@@ -65,9 +63,7 @@ llvm_enter_fatal_on_oom(void)
if (fatal_new_handler_depth == 0)
{
old_new_handler = std::set_new_handler(fatal_system_new_handler);
-#if LLVM_VERSION_MAJOR > 4
llvm::install_bad_alloc_error_handler(fatal_llvm_new_handler);
-#endif
llvm::install_fatal_error_handler(fatal_llvm_error_handler);
}
fatal_new_handler_depth++;
@@ -83,9 +79,7 @@ llvm_leave_fatal_on_oom(void)
if (fatal_new_handler_depth == 0)
{
std::set_new_handler(old_new_handler);
-#if LLVM_VERSION_MAJOR > 4
llvm::remove_bad_alloc_error_handler();
-#endif
llvm::remove_fatal_error_handler();
}
}
@@ -110,9 +104,7 @@ llvm_reset_after_error(void)
if (fatal_new_handler_depth != 0)
{
std::set_new_handler(old_new_handler);
-#if LLVM_VERSION_MAJOR > 4
llvm::remove_bad_alloc_error_handler();
-#endif
llvm::remove_fatal_error_handler();
}
fatal_new_handler_depth = 0;
@@ -133,7 +125,6 @@ fatal_system_new_handler(void)
errdetail("while in LLVM")));
}
-#if LLVM_VERSION_MAJOR > 4
static void
fatal_llvm_new_handler(void *user_data,
const char *reason,
@@ -153,7 +144,6 @@ fatal_llvm_new_handler(void *user_data,
fatal_llvm_new_handler(user_data, reason.c_str(), gen_crash_diag);
}
#endif
-#endif
static void
fatal_llvm_error_handler(void *user_data,
diff --git a/src/backend/jit/llvm/llvmjit_expr.c b/src/backend/jit/llvm/llvmjit_expr.c
index a3a0876bff..a950564afa 100644
--- a/src/backend/jit/llvm/llvmjit_expr.c
+++ b/src/backend/jit/llvm/llvmjit_expr.c
@@ -2644,12 +2644,8 @@ create_LifetimeEnd(LLVMModuleRef mod)
LLVMTypeRef param_types[2];
LLVMContextRef lc;
- /* LLVM 5+ has a variadic pointer argument */
-#if LLVM_VERSION_MAJOR < 5
- const char *nm = "llvm.lifetime.end";
-#else
+ /* variadic pointer argument */
const char *nm = "llvm.lifetime.end.p0i8";
-#endif
fn = LLVMGetNamedFunction(mod, nm);
if (fn)
diff --git a/src/backend/jit/llvm/llvmjit_inline.cpp b/src/backend/jit/llvm/llvmjit_inline.cpp
index d92d7f3c88..b38f48b026 100644
--- a/src/backend/jit/llvm/llvmjit_inline.cpp
+++ b/src/backend/jit/llvm/llvmjit_inline.cpp
@@ -49,12 +49,7 @@ extern "C"
#include <llvm/ADT/StringSet.h>
#include <llvm/ADT/StringMap.h>
#include <llvm/Analysis/ModuleSummaryAnalysis.h>
-#if LLVM_VERSION_MAJOR > 3
#include <llvm/Bitcode/BitcodeReader.h>
-#else
-#include <llvm/Bitcode/ReaderWriter.h>
-#include <llvm/Support/Error.h>
-#endif
#include <llvm/IR/Attributes.h>
#include <llvm/IR/DebugInfo.h>
#include <llvm/IR/IntrinsicInst.h>
@@ -267,14 +262,12 @@ llvm_build_inline_plan(LLVMContextRef lc, llvm::Module *mod)
fs = llvm::cast<llvm::FunctionSummary>(gvs);
-#if LLVM_VERSION_MAJOR > 3
if (gvs->notEligibleToImport())
{
ilog(DEBUG1, "ineligibile to import %s due to summary",
symbolName.data());
continue;
}
-#endif
if ((int) fs->instCount() > inlineState.costLimit)
{
@@ -458,16 +451,9 @@ llvm_execute_inline_plan(llvm::Module *mod, ImportMapTy *globalsToInline)
}
-#if LLVM_VERSION_MAJOR > 4
-#define IRMOVE_PARAMS , /*IsPerformingImport=*/false
-#elif LLVM_VERSION_MAJOR > 3
-#define IRMOVE_PARAMS , /*LinkModuleInlineAsm=*/false, /*IsPerformingImport=*/false
-#else
-#define IRMOVE_PARAMS
-#endif
if (Mover.move(std::move(importMod), GlobalsToImport.getArrayRef(),
- [](llvm::GlobalValue &, llvm::IRMover::ValueAdder) {}
- IRMOVE_PARAMS))
+ [](llvm::GlobalValue &, llvm::IRMover::ValueAdder) {},
+ /*IsPerformingImport=*/false))
elog(FATAL, "function import failed with linker error");
}
}
@@ -793,7 +779,6 @@ llvm_load_summary(llvm::StringRef path)
{
llvm::MemoryBufferRef ref(*MBOrErr.get().get());
-#if LLVM_VERSION_MAJOR > 3
llvm::Expected<std::unique_ptr<llvm::ModuleSummaryIndex> > IndexOrErr =
llvm::getModuleSummaryIndex(ref);
if (IndexOrErr)
@@ -801,15 +786,6 @@ llvm_load_summary(llvm::StringRef path)
elog(FATAL, "failed to load summary \"%s\": %s",
path.data(),
toString(IndexOrErr.takeError()).c_str());
-#else
- llvm::ErrorOr<std::unique_ptr<llvm::ModuleSummaryIndex> > IndexOrErr =
- llvm::getModuleSummaryIndex(ref, [](const llvm::DiagnosticInfo &) {});
- if (IndexOrErr)
- return std::move(IndexOrErr.get());
- elog(FATAL, "failed to load summary \"%s\": %s",
- path.data(),
- IndexOrErr.getError().message().c_str());
-#endif
}
return nullptr;
}
@@ -853,22 +829,12 @@ summaries_for_guid(const InlineSearchPath& path, llvm::GlobalValue::GUID guid)
for (auto index : path)
{
-#if LLVM_VERSION_MAJOR > 4
llvm::ValueInfo funcVI = index->getValueInfo(guid);
/* if index doesn't know function, we don't have a body, continue */
if (funcVI)
for (auto &gv : funcVI.getSummaryList())
matches.push_back(gv.get());
-#else
- const llvm::const_gvsummary_iterator &I =
- index->findGlobalValueSummaryList(guid);
- if (I != index->end())
- {
- for (auto &gv : I->second)
- matches.push_back(gv.get());
- }
-#endif
}
return matches;
diff --git a/src/backend/jit/llvm/llvmjit_wrap.cpp b/src/backend/jit/llvm/llvmjit_wrap.cpp
index 90a41b9191..6f6ccb36c5 100644
--- a/src/backend/jit/llvm/llvmjit_wrap.cpp
+++ b/src/backend/jit/llvm/llvmjit_wrap.cpp
@@ -21,16 +21,7 @@ extern "C"
/* Avoid macro clash with LLVM's C++ headers */
#undef Min
-#include <llvm/IR/Attributes.h>
#include <llvm/IR/Function.h>
-#if LLVM_VERSION_MAJOR < 17
-#include <llvm/MC/SubtargetFeature.h>
-#endif
-#if LLVM_VERSION_MAJOR > 16
-#include <llvm/TargetParser/Host.h>
-#else
-#include <llvm/Support/Host.h>
-#endif
#include "jit/llvmjit.h"
@@ -38,50 +29,6 @@ extern "C"
/*
* C-API extensions.
*/
-#if defined(HAVE_DECL_LLVMGETHOSTCPUNAME) && !HAVE_DECL_LLVMGETHOSTCPUNAME
-char *LLVMGetHostCPUName(void) {
- return strdup(llvm::sys::getHostCPUName().data());
-}
-#endif
-
-
-#if defined(HAVE_DECL_LLVMGETHOSTCPUFEATURES) && !HAVE_DECL_LLVMGETHOSTCPUFEATURES
-char *LLVMGetHostCPUFeatures(void) {
- llvm::SubtargetFeatures Features;
- llvm::StringMap<bool> HostFeatures;
-
- if (llvm::sys::getHostCPUFeatures(HostFeatures))
- for (auto &F : HostFeatures)
- Features.AddFeature(F.first(), F.second);
-
- return strdup(Features.getString().c_str());
-}
-#endif
-
-/*
- * Like LLVM's LLVMGetAttributeCountAtIndex(), works around a bug in LLVM 3.9.
- *
- * In LLVM <= 3.9, LLVMGetAttributeCountAtIndex() segfaults if there are no
- * attributes at an index (fixed in LLVM commit ce9bb1097dc2).
- */
-unsigned
-LLVMGetAttributeCountAtIndexPG(LLVMValueRef F, uint32 Idx)
-{
- /*
- * This is more expensive, so only do when using a problematic LLVM
- * version.
- */
-#if LLVM_VERSION_MAJOR < 4
- if (!llvm::unwrap<llvm::Function>(F)->getAttributes().hasAttributes(Idx))
- return 0;
-#endif
-
- /*
- * There is no nice public API to determine the count nicely, so just
- * always fall back to LLVM's C API.
- */
- return LLVMGetAttributeCountAtIndex(F, Idx);
-}
LLVMTypeRef
LLVMGetFunctionReturnType(LLVMValueRef r)
@@ -94,11 +41,3 @@ LLVMGetFunctionType(LLVMValueRef r)
{
return llvm::wrap(llvm::unwrap<llvm::Function>(r)->getFunctionType());
}
-
-#if LLVM_VERSION_MAJOR < 8
-LLVMTypeRef
-LLVMGlobalGetValueType(LLVMValueRef g)
-{
- return llvm::wrap(llvm::unwrap<llvm::GlobalValue>(g)->getValueType());
-}
-#endif
diff --git a/src/include/jit/llvmjit.h b/src/include/jit/llvmjit.h
index 3ab86de3ac..e90b390bf4 100644
--- a/src/include/jit/llvmjit.h
+++ b/src/include/jit/llvmjit.h
@@ -130,26 +130,9 @@ extern LLVMValueRef slot_compile_deform(struct LLVMJitContext *context, TupleDes
* Error handling related functions.
****************************************************************************
*/
-#if defined(HAVE_DECL_LLVMGETHOSTCPUNAME) && !HAVE_DECL_LLVMGETHOSTCPUNAME
-/** Get the host CPU as a string. The result needs to be disposed with
- LLVMDisposeMessage. */
-extern char *LLVMGetHostCPUName(void);
-#endif
-
-#if defined(HAVE_DECL_LLVMGETHOSTCPUFEATURES) && !HAVE_DECL_LLVMGETHOSTCPUFEATURES
-/** Get the host CPU features as a string. The result needs to be disposed
- with LLVMDisposeMessage. */
-extern char *LLVMGetHostCPUFeatures(void);
-#endif
-
-extern unsigned LLVMGetAttributeCountAtIndexPG(LLVMValueRef F, uint32 Idx);
extern LLVMTypeRef LLVMGetFunctionReturnType(LLVMValueRef r);
extern LLVMTypeRef LLVMGetFunctionType(LLVMValueRef r);
-#if LLVM_MAJOR_VERSION < 8
-extern LLVMTypeRef LLVMGlobalGetValueType(LLVMValueRef g);
-#endif
-
#ifdef __cplusplus
} /* extern "C" */
#endif
diff --git a/src/include/pg_config.h.in b/src/include/pg_config.h.in
index d8a2985567..481470ee59 100644
--- a/src/include/pg_config.h.in
+++ b/src/include/pg_config.h.in
@@ -103,18 +103,6 @@
`LLVMCreatePerfJITEventListener', and to 0 if you don't. */
#undef HAVE_DECL_LLVMCREATEPERFJITEVENTLISTENER
-/* Define to 1 if you have the declaration of `LLVMGetHostCPUFeatures', and to
- 0 if you don't. */
-#undef HAVE_DECL_LLVMGETHOSTCPUFEATURES
-
-/* Define to 1 if you have the declaration of `LLVMGetHostCPUName', and to 0
- if you don't. */
-#undef HAVE_DECL_LLVMGETHOSTCPUNAME
-
-/* Define to 1 if you have the declaration of `LLVMOrcGetSymbolAddressIn', and
- to 0 if you don't. */
-#undef HAVE_DECL_LLVMORCGETSYMBOLADDRESSIN
-
/* 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/tools/msvc/Solution.pm b/src/tools/msvc/Solution.pm
index a50f730260..5066bd9e28 100644
--- a/src/tools/msvc/Solution.pm
+++ b/src/tools/msvc/Solution.pm
@@ -235,9 +235,6 @@ sub GenerateFiles
HAVE_DECL_F_FULLFSYNC => 0,
HAVE_DECL_LLVMCREATEGDBREGISTRATIONLISTENER => 0,
HAVE_DECL_LLVMCREATEPERFJITEVENTLISTENER => 0,
- HAVE_DECL_LLVMGETHOSTCPUNAME => 0,
- HAVE_DECL_LLVMGETHOSTCPUFEATURES => 0,
- HAVE_DECL_LLVMORCGETSYMBOLADDRESSIN => 0,
HAVE_DECL_POSIX_FADVISE => 0,
HAVE_DECL_PREADV => 0,
HAVE_DECL_PWRITEV => 0,
--
2.42.0
Thomas Munro <thomas.munro@gmail.com> writes:
Here are some systematic rules I'd like to propose to anchor this
stuff to reality and avoid future doubt and litigation:
1. Build farm animals testing LLVM determine the set of OSes and LLVM
versions we consider.
2. We exclude OSes that will be out of full vendor support when a
release ships.
3. We exclude OSes that don't bless an LLVM release (eg macOS running
an arbitrarily picked version), and animals running only to cover
ancient LLVM compiled from source for coverage (Andres's sid
menagerie).
Seems generally reasonable. Maybe rephrase 3 as "We consider only
an OS release's default LLVM version"? Or a bit more forgivingly,
"... only LLVM versions available from the OS vendor"? Also,
what's an OS vendor? You rejected macOS which is fine, but
I think the packages available from MacPorts or Homebrew should
be considered.
You could imagine somebody trying to game the system by standing up a
buildfarm animal running some really arbitrary combination of versions
--- but what would be the point? I think we can deal with that
when/if it happens. But "macOS running an LLVM version available
from MacPorts" doesn't seem arbitrary.
regards, tom lane
On Wed, Oct 25, 2023 at 7:12 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
Thomas Munro <thomas.munro@gmail.com> writes:
3. We exclude OSes that don't bless an LLVM release (eg macOS running
an arbitrarily picked version), and animals running only to cover
ancient LLVM compiled from source for coverage (Andres's sid
menagerie).Seems generally reasonable. Maybe rephrase 3 as "We consider only
an OS release's default LLVM version"? Or a bit more forgivingly,
"... only LLVM versions available from the OS vendor"? Also,
what's an OS vendor? You rejected macOS which is fine, but
I think the packages available from MacPorts or Homebrew should
be considered.
OK. For me the key differences are that they are independent of OS
releases and time lines, they promptly add new releases, they have a
wide back-catalogue of the old releases and they let the user decide
which to use. So I don't think they constrain us and it makes no
sense to try to apply 'end of support' logic to them.
https://formulae.brew.sh/formula/llvm
https://ports.macports.org/search/?q=llvm&name=on
(Frustratingly, the ancient releases of clang don't actually seem to
work on MacPorts at least on aarch64, and they tell you so when you
try to install them.)
The BSDs may be closer to macOS in that respect too, since they have
ports separate from OS releases and they offer a rolling and wide
range of LLVMs and generally default to a very new one, so I don't
think they constrain us either. It's really Big Linux that is
drawing the lines in the sand here, though (unusually) not
RHEL-and-frenemies as they've opted for rolling to the latest in every
minor release as Devrim explained.
Hi,
On Thu, 2023-10-19 at 08:13 +1300, Thomas Munro wrote:
If we used Debian as a yardstick, PostgreSQL 17 wouldn't need anything
older than LLVM 14 AFAICS. Who else do we need to ask?
LLVM 15 is the minimum one for the platforms that I build the packages
on. So LLVM >= 14 is great for HEAD.
Regards,
--
Devrim Gündüz
Open Source Solution Architect, PostgreSQL Major Contributor
Twitter: @DevrimGunduz , @DevrimGunduzTR
So it sounds like we're in agreement that it is time to require LLVM
10+ in master. Could the owners (CC'd) of the following animals
please turn off --with-llvm on master (and future 17+ branches), or
consider upgrading to a modern OS release? Otherwise they'll turn
red.
animal | arch | llvm_version | os | os_release
| end_of_support
-------------+--------------------+--------------+--------+------------+----------------
mantid | x86_64 | 5.0.1 | CentOS | 7
| 2019-08-06
cotinga | s390x | 6.0.0 | Ubuntu | 18.04
| 2023-06-01
vimba | aarch64 | 6.0.0 | Ubuntu | 18.04
| 2023-06-01
topminnow | mips64el; -mabi=32 | 6.0.1 | Debian | 8
| 2018-06-17
alimoche | aarch64 | 7.0.1 | Debian | 10
| 2022-09-10
blackneck | aarch64 | 7.0.1 | Debian | 10
| 2022-09-10
And of course Andres would need to do the same for his coverage
animals in that range:
animal | arch | llvm_version | os | os_release
| end_of_support
-------------+--------------------+--------------+--------+------------+----------------
dragonet | x86_64 | 3.9.1 | Debian | sid |
phycodurus | x86_64 | 3.9.1 | Debian | sid |
desmoxytes | x86_64 | 4.0.1 | Debian | sid |
petalura | x86_64 | 4.0.1 | Debian | sid |
idiacanthus | x86_64 | 5.0.2 | Debian | sid |
pogona | x86_64 | 5.0.2 | Debian | sid |
komodoensis | x86_64 | 6.0.1 | Debian | sid |
xenodermus | x86_64 | 6.0.1 | Debian | sid |
Hi,
On 2023-11-02 10:46:52 +1300, Thomas Munro wrote:
So it sounds like we're in agreement that it is time to require LLVM
10+ in master. Could the owners (CC'd) of the following animals
please turn off --with-llvm on master (and future 17+ branches), or
consider upgrading to a modern OS release? Otherwise they'll turn
red.And of course Andres would need to do the same for his coverage
animals in that range:animal | arch | llvm_version | os | os_release
| end_of_support
-------------+--------------------+--------------+--------+------------+----------------
dragonet | x86_64 | 3.9.1 | Debian | sid |
phycodurus | x86_64 | 3.9.1 | Debian | sid |
desmoxytes | x86_64 | 4.0.1 | Debian | sid |
petalura | x86_64 | 4.0.1 | Debian | sid |
idiacanthus | x86_64 | 5.0.2 | Debian | sid |
pogona | x86_64 | 5.0.2 | Debian | sid |
komodoensis | x86_64 | 6.0.1 | Debian | sid |
xenodermus | x86_64 | 6.0.1 | Debian | sid |
Would you want me to do this now or just before you apply the patch?
I think I should stand up a few more replacement animals to cover older llvm
versions with assertions enabled...
Greetings,
Andres Freund
On 25.10.23 07:47, Thomas Munro wrote:
Ideally more distros would be present in this vacuum-horizon decision
table, but I don't think it'd change the conclusion: 10 is the
trailing edge. Therefore the attached patch scales back its ambition
to that release. Tested on LLVM 10-18.
This patch and the associated reasoning look good to me. I think this
is good to go for PG17.
2024-01 Commitfest.
Hi, This patch has a CF status of "Ready for Committer", but it looks
like it failed when the CFbot test for it was last run [1]https://cirrus-ci.com/github/postgresql-cfbot/postgresql/commitfest/46/4640. Please
have a look and post an updated version..
======
[1]: https://cirrus-ci.com/github/postgresql-cfbot/postgresql/commitfest/46/4640
Kind Regards,
Peter Smith.
Thanks all for the discussion. Pushed. A few build farm animals will
now fail in the configure step as discussed, and need some adjustment
(ie disable LLVM or upgrade to LLVM 10+ for the master branch).
Next year I think we should be able to do a much bigger cleanup, by
moving to LLVM 14+.
On Thu, Jan 25, 2024 at 4:44 PM Thomas Munro <thomas.munro@gmail.com> wrote:
... A few build farm animals will
now fail in the configure step as discussed, and need some adjustment
(ie disable LLVM or upgrade to LLVM 10+ for the master branch).
Owners pinged.
On 1/25/24 13:41, Thomas Munro wrote:
On Thu, Jan 25, 2024 at 4:44 PM Thomas Munro <thomas.munro@gmail.com> wrote:
... A few build farm animals will
now fail in the configure step as discussed, and need some adjustment
(ie disable LLVM or upgrade to LLVM 10+ for the master branch).Owners pinged.
I think I fixed up the 4 or 6 under my name...
Regards,
Mark