Back-patch LLVM 14 API changes.
Since LLVM 14 has stopped changing and is about to be released, back-patch the following changes from the master branch: e6a7600202105919bffd62b3dfd941f4a94e082b 807fee1a39de6bb8184082012e643951abb9ad1d a56e7b66010f330782243de9e25ac2a6596be0e1 Back-patch to 11, where LLVM JIT support came in.
This commit is contained in:
parent
8dcd1c3564
commit
d9f7ad54e5
@ -22,6 +22,12 @@ endif
|
|||||||
PGFILEDESC = "llvmjit - JIT using LLVM"
|
PGFILEDESC = "llvmjit - JIT using LLVM"
|
||||||
NAME = llvmjit
|
NAME = llvmjit
|
||||||
|
|
||||||
|
# LLVM 14 produces deprecation warnings. We'll need to make some changes
|
||||||
|
# before the relevant functions are removed, but for now silence the warnings.
|
||||||
|
ifeq ($(GCC), yes)
|
||||||
|
LLVM_CFLAGS += -Wno-deprecated-declarations
|
||||||
|
endif
|
||||||
|
|
||||||
# All files in this directory use LLVM.
|
# All files in this directory use LLVM.
|
||||||
CFLAGS += $(LLVM_CFLAGS)
|
CFLAGS += $(LLVM_CFLAGS)
|
||||||
CXXFLAGS += $(LLVM_CXXFLAGS)
|
CXXFLAGS += $(LLVM_CXXFLAGS)
|
||||||
|
@ -23,15 +23,22 @@ extern "C"
|
|||||||
|
|
||||||
#include "jit/llvmjit.h"
|
#include "jit/llvmjit.h"
|
||||||
|
|
||||||
|
#include <new>
|
||||||
|
|
||||||
static int fatal_new_handler_depth = 0;
|
static int fatal_new_handler_depth = 0;
|
||||||
static std::new_handler old_new_handler = NULL;
|
static std::new_handler old_new_handler = NULL;
|
||||||
|
|
||||||
static void fatal_system_new_handler(void);
|
static void fatal_system_new_handler(void);
|
||||||
#if LLVM_VERSION_MAJOR > 4
|
#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);
|
static void fatal_llvm_new_handler(void *user_data, const std::string& reason, bool gen_crash_diag);
|
||||||
#endif
|
#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);
|
static void fatal_llvm_error_handler(void *user_data, const std::string& reason, bool gen_crash_diag);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -129,23 +136,41 @@ fatal_system_new_handler(void)
|
|||||||
#if LLVM_VERSION_MAJOR > 4
|
#if LLVM_VERSION_MAJOR > 4
|
||||||
static void
|
static void
|
||||||
fatal_llvm_new_handler(void *user_data,
|
fatal_llvm_new_handler(void *user_data,
|
||||||
const std::string& reason,
|
const char *reason,
|
||||||
bool gen_crash_diag)
|
bool gen_crash_diag)
|
||||||
{
|
{
|
||||||
ereport(FATAL,
|
ereport(FATAL,
|
||||||
(errcode(ERRCODE_OUT_OF_MEMORY),
|
(errcode(ERRCODE_OUT_OF_MEMORY),
|
||||||
errmsg("out of memory"),
|
errmsg("out of memory"),
|
||||||
errdetail("While in LLVM: %s", reason.c_str())));
|
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
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static void
|
||||||
|
fatal_llvm_error_handler(void *user_data,
|
||||||
|
const char *reason,
|
||||||
|
bool gen_crash_diag)
|
||||||
|
{
|
||||||
|
ereport(FATAL,
|
||||||
|
(errcode(ERRCODE_OUT_OF_MEMORY),
|
||||||
|
errmsg("fatal llvm error: %s", reason)));
|
||||||
|
}
|
||||||
|
|
||||||
|
#if LLVM_VERSION_MAJOR < 14
|
||||||
static void
|
static void
|
||||||
fatal_llvm_error_handler(void *user_data,
|
fatal_llvm_error_handler(void *user_data,
|
||||||
const std::string& reason,
|
const std::string& reason,
|
||||||
bool gen_crash_diag)
|
bool gen_crash_diag)
|
||||||
{
|
{
|
||||||
ereport(FATAL,
|
fatal_llvm_error_handler(user_data, reason.c_str(), gen_crash_diag);
|
||||||
(errcode(ERRCODE_OUT_OF_MEMORY),
|
|
||||||
errmsg("fatal llvm error: %s",
|
|
||||||
reason.c_str())));
|
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
@ -594,7 +594,11 @@ function_inlinable(llvm::Function &F,
|
|||||||
if (F.materialize())
|
if (F.materialize())
|
||||||
elog(FATAL, "failed to materialize metadata");
|
elog(FATAL, "failed to materialize metadata");
|
||||||
|
|
||||||
if (F.getAttributes().hasFnAttribute(llvm::Attribute::NoInline))
|
#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",
|
ilog(DEBUG1, "ineligibile to import %s due to noinline",
|
||||||
F.getName().data());
|
F.getName().data());
|
||||||
@ -871,7 +875,9 @@ create_redirection_function(std::unique_ptr<llvm::Module> &importMod,
|
|||||||
llvm::Function *AF;
|
llvm::Function *AF;
|
||||||
llvm::BasicBlock *BB;
|
llvm::BasicBlock *BB;
|
||||||
llvm::CallInst *fwdcall;
|
llvm::CallInst *fwdcall;
|
||||||
|
#if LLVM_VERSION_MAJOR < 14
|
||||||
llvm::Attribute inlineAttribute;
|
llvm::Attribute inlineAttribute;
|
||||||
|
#endif
|
||||||
|
|
||||||
AF = llvm::Function::Create(F->getFunctionType(),
|
AF = llvm::Function::Create(F->getFunctionType(),
|
||||||
LinkageTypes::AvailableExternallyLinkage,
|
LinkageTypes::AvailableExternallyLinkage,
|
||||||
@ -880,9 +886,13 @@ create_redirection_function(std::unique_ptr<llvm::Module> &importMod,
|
|||||||
|
|
||||||
Builder.SetInsertPoint(BB);
|
Builder.SetInsertPoint(BB);
|
||||||
fwdcall = Builder.CreateCall(F, &*AF->arg_begin());
|
fwdcall = Builder.CreateCall(F, &*AF->arg_begin());
|
||||||
|
#if LLVM_VERSION_MAJOR < 14
|
||||||
inlineAttribute = llvm::Attribute::get(Context,
|
inlineAttribute = llvm::Attribute::get(Context,
|
||||||
llvm::Attribute::AlwaysInline);
|
llvm::Attribute::AlwaysInline);
|
||||||
fwdcall->addAttribute(~0U, inlineAttribute);
|
fwdcall->addAttribute(~0U, inlineAttribute);
|
||||||
|
#else
|
||||||
|
fwdcall->addFnAttr(llvm::Attribute::AlwaysInline);
|
||||||
|
#endif
|
||||||
Builder.CreateRet(fwdcall);
|
Builder.CreateRet(fwdcall);
|
||||||
|
|
||||||
return AF;
|
return AF;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user