Skip to content

Commit 76200e5

Browse files
committed
jit: Changes for LLVM 17.
Changes required by https://llvm.org/docs/NewPassManager.html. Back-patch to 12, leaving the final release of 11 unchanged, consistent with earlier decision not to back-patch LLVM 16 support either. Author: Dmitry Dolgov <9erthalion6@gmail.com> Reviewed-by: Andres Freund <andres@anarazel.de> Reviewed-by: Thomas Munro <thomas.munro@gmail.com> Discussion: https://postgr.es/m/CA%2BhUKG%2BWXznXCyTgCADd%3DHWkP9Qksa6chd7L%3DGCnZo-MBgg9Lg%40mail.gmail.com
1 parent f90b4a8 commit 76200e5

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

src/backend/jit/llvm/llvmjit.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
#include <llvm-c/BitWriter.h>
1919
#include <llvm-c/Core.h>
2020
#include <llvm-c/ExecutionEngine.h>
21+
#if LLVM_VERSION_MAJOR > 16
22+
#include <llvm-c/Transforms/PassBuilder.h>
23+
#endif
2124
#if LLVM_VERSION_MAJOR > 11
2225
#include <llvm-c/Orc.h>
2326
#include <llvm-c/OrcEE.h>
@@ -27,12 +30,14 @@
2730
#endif
2831
#include <llvm-c/Support.h>
2932
#include <llvm-c/Target.h>
33+
#if LLVM_VERSION_MAJOR < 17
3034
#include <llvm-c/Transforms/IPO.h>
3135
#include <llvm-c/Transforms/PassManagerBuilder.h>
3236
#include <llvm-c/Transforms/Scalar.h>
3337
#if LLVM_VERSION_MAJOR > 6
3438
#include <llvm-c/Transforms/Utils.h>
3539
#endif
40+
#endif
3641

3742
#include "jit/llvmjit.h"
3843
#include "jit/llvmjit_emit.h"
@@ -630,6 +635,7 @@ llvm_function_reference(LLVMJitContext *context,
630635
static void
631636
llvm_optimize_module(LLVMJitContext *context, LLVMModuleRef module)
632637
{
638+
#if LLVM_VERSION_MAJOR < 17
633639
LLVMPassManagerBuilderRef llvm_pmb;
634640
LLVMPassManagerRef llvm_mpm;
635641
LLVMPassManagerRef llvm_fpm;
@@ -693,6 +699,31 @@ llvm_optimize_module(LLVMJitContext *context, LLVMModuleRef module)
693699
LLVMDisposePassManager(llvm_mpm);
694700

695701
LLVMPassManagerBuilderDispose(llvm_pmb);
702+
#else
703+
LLVMPassBuilderOptionsRef options;
704+
LLVMErrorRef err;
705+
const char *passes;
706+
707+
if (context->base.flags & PGJIT_OPT3)
708+
passes = "default<O3>";
709+
else
710+
passes = "default<O0>,mem2reg";
711+
712+
options = LLVMCreatePassBuilderOptions();
713+
714+
#ifdef LLVM_PASS_DEBUG
715+
LLVMPassBuilderOptionsSetDebugLogging(options, 1);
716+
#endif
717+
718+
LLVMPassBuilderOptionsSetInlinerThreshold(options, 512);
719+
720+
err = LLVMRunPasses(module, passes, NULL, options);
721+
722+
if (err)
723+
elog(ERROR, "failed to JIT module: %s", llvm_error_message(err));
724+
725+
LLVMDisposePassBuilderOptions(options);
726+
#endif
696727
}
697728

698729
/*

src/backend/jit/llvm/llvmjit_wrap.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,14 @@ extern "C"
2323

2424
#include <llvm/IR/Attributes.h>
2525
#include <llvm/IR/Function.h>
26+
#if LLVM_VERSION_MAJOR < 17
2627
#include <llvm/MC/SubtargetFeature.h>
28+
#endif
29+
#if LLVM_VERSION_MAJOR > 16
30+
#include <llvm/TargetParser/Host.h>
31+
#else
2732
#include <llvm/Support/Host.h>
33+
#endif
2834

2935
#include "jit/llvmjit.h"
3036

0 commit comments

Comments
 (0)