summaryrefslogtreecommitdiff
path: root/src/backend/jit/llvm
diff options
context:
space:
mode:
authorThomas Munro2024-01-25 02:23:04 +0000
committerThomas Munro2024-01-25 02:42:34 +0000
commit820b5af73dcc6a5d0db6a98a62a6b859e5d107b6 (patch)
treecc46c2147142da3b000398e001ea2315ff3e298e /src/backend/jit/llvm
parent729439607ad210dbb446e31754e8627d7e3f7dda (diff)
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. Reviewed-by: Peter Eisentraut <[email protected]> Discussion: https://postgr.es/m/CA%2BhUKGLhNs5geZaVNj2EJ79Dx9W8fyWUU3HxcpZy55sMGcY%3DiA%40mail.gmail.com
Diffstat (limited to 'src/backend/jit/llvm')
-rw-r--r--src/backend/jit/llvm/llvmjit.c57
-rw-r--r--src/backend/jit/llvm/llvmjit_error.cpp10
-rw-r--r--src/backend/jit/llvm/llvmjit_expr.c6
-rw-r--r--src/backend/jit/llvm/llvmjit_inline.cpp38
-rw-r--r--src/backend/jit/llvm/llvmjit_wrap.cpp61
5 files changed, 6 insertions, 166 deletions
diff --git a/src/backend/jit/llvm/llvmjit.c b/src/backend/jit/llvm/llvmjit.c
index 7e1d348e6b6..ec0fdd49324 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"
@@ -381,10 +379,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();
@@ -432,7 +427,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;
@@ -444,28 +439,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);
@@ -553,12 +526,8 @@ 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
- * LLVMGetAttributesAtIndex() is called for an index with 0 attributes.
- */
if (num_attributes == 0)
return;
@@ -852,7 +821,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,
@@ -861,26 +830,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 69a23f6eff9..ebe2f1baa10 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 09994503b15..0c448422e20 100644
--- a/src/backend/jit/llvm/llvmjit_expr.c
+++ b/src/backend/jit/llvm/llvmjit_expr.c
@@ -2650,12 +2650,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 c9efc0bc994..2007eb523c9 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;
}
@@ -856,22 +832,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 878f8edf55c..641c8841ca3 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