Skip to content

Commit d9f7ad5

Browse files
committed
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: e6a7600 807fee1 a56e7b6 Back-patch to 11, where LLVM JIT support came in.
1 parent 8dcd1c3 commit d9f7ad5

File tree

3 files changed

+47
-6
lines changed

3 files changed

+47
-6
lines changed

src/backend/jit/llvm/Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ endif
2222
PGFILEDESC = "llvmjit - JIT using LLVM"
2323
NAME = llvmjit
2424

25+
# LLVM 14 produces deprecation warnings. We'll need to make some changes
26+
# before the relevant functions are removed, but for now silence the warnings.
27+
ifeq ($(GCC), yes)
28+
LLVM_CFLAGS += -Wno-deprecated-declarations
29+
endif
30+
2531
# All files in this directory use LLVM.
2632
CFLAGS += $(LLVM_CFLAGS)
2733
CXXFLAGS += $(LLVM_CXXFLAGS)

src/backend/jit/llvm/llvmjit_error.cpp

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,22 @@ extern "C"
2323

2424
#include "jit/llvmjit.h"
2525

26+
#include <new>
2627

2728
static int fatal_new_handler_depth = 0;
2829
static std::new_handler old_new_handler = NULL;
2930

3031
static void fatal_system_new_handler(void);
3132
#if LLVM_VERSION_MAJOR > 4
33+
static void fatal_llvm_new_handler(void *user_data, const char *reason, bool gen_crash_diag);
34+
#if LLVM_VERSION_MAJOR < 14
3235
static void fatal_llvm_new_handler(void *user_data, const std::string& reason, bool gen_crash_diag);
3336
#endif
37+
#endif
38+
static void fatal_llvm_error_handler(void *user_data, const char *reason, bool gen_crash_diag);
39+
#if LLVM_VERSION_MAJOR < 14
3440
static void fatal_llvm_error_handler(void *user_data, const std::string& reason, bool gen_crash_diag);
41+
#endif
3542

3643

3744
/*
@@ -129,23 +136,41 @@ fatal_system_new_handler(void)
129136
#if LLVM_VERSION_MAJOR > 4
130137
static void
131138
fatal_llvm_new_handler(void *user_data,
132-
const std::string& reason,
139+
const char *reason,
133140
bool gen_crash_diag)
134141
{
135142
ereport(FATAL,
136143
(errcode(ERRCODE_OUT_OF_MEMORY),
137144
errmsg("out of memory"),
138-
errdetail("While in LLVM: %s", reason.c_str())));
145+
errdetail("While in LLVM: %s", reason)));
146+
}
147+
#if LLVM_VERSION_MAJOR < 14
148+
static void
149+
fatal_llvm_new_handler(void *user_data,
150+
const std::string& reason,
151+
bool gen_crash_diag)
152+
{
153+
fatal_llvm_new_handler(user_data, reason.c_str(), gen_crash_diag);
139154
}
140155
#endif
156+
#endif
141157

142158
static void
143159
fatal_llvm_error_handler(void *user_data,
144-
const std::string& reason,
160+
const char *reason,
145161
bool gen_crash_diag)
146162
{
147163
ereport(FATAL,
148164
(errcode(ERRCODE_OUT_OF_MEMORY),
149-
errmsg("fatal llvm error: %s",
150-
reason.c_str())));
165+
errmsg("fatal llvm error: %s", reason)));
151166
}
167+
168+
#if LLVM_VERSION_MAJOR < 14
169+
static void
170+
fatal_llvm_error_handler(void *user_data,
171+
const std::string& reason,
172+
bool gen_crash_diag)
173+
{
174+
fatal_llvm_error_handler(user_data, reason.c_str(), gen_crash_diag);
175+
}
176+
#endif

src/backend/jit/llvm/llvmjit_inline.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,11 @@ function_inlinable(llvm::Function &F,
594594
if (F.materialize())
595595
elog(FATAL, "failed to materialize metadata");
596596

597-
if (F.getAttributes().hasFnAttribute(llvm::Attribute::NoInline))
597+
#if LLVM_VERSION_MAJOR < 14
598+
#define hasFnAttr hasFnAttribute
599+
#endif
600+
601+
if (F.getAttributes().hasFnAttr(llvm::Attribute::NoInline))
598602
{
599603
ilog(DEBUG1, "ineligibile to import %s due to noinline",
600604
F.getName().data());
@@ -871,7 +875,9 @@ create_redirection_function(std::unique_ptr<llvm::Module> &importMod,
871875
llvm::Function *AF;
872876
llvm::BasicBlock *BB;
873877
llvm::CallInst *fwdcall;
878+
#if LLVM_VERSION_MAJOR < 14
874879
llvm::Attribute inlineAttribute;
880+
#endif
875881

876882
AF = llvm::Function::Create(F->getFunctionType(),
877883
LinkageTypes::AvailableExternallyLinkage,
@@ -880,9 +886,13 @@ create_redirection_function(std::unique_ptr<llvm::Module> &importMod,
880886

881887
Builder.SetInsertPoint(BB);
882888
fwdcall = Builder.CreateCall(F, &*AF->arg_begin());
889+
#if LLVM_VERSION_MAJOR < 14
883890
inlineAttribute = llvm::Attribute::get(Context,
884891
llvm::Attribute::AlwaysInline);
885892
fwdcall->addAttribute(~0U, inlineAttribute);
893+
#else
894+
fwdcall->addFnAttr(llvm::Attribute::AlwaysInline);
895+
#endif
886896
Builder.CreateRet(fwdcall);
887897

888898
return AF;

0 commit comments

Comments
 (0)