Skip to content

Commit 7741850

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 60596f1 commit 7741850

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"
@@ -561,6 +566,7 @@ llvm_function_reference(LLVMJitContext *context,
561566
static void
562567
llvm_optimize_module(LLVMJitContext *context, LLVMModuleRef module)
563568
{
569+
#if LLVM_VERSION_MAJOR < 17
564570
LLVMPassManagerBuilderRef llvm_pmb;
565571
LLVMPassManagerRef llvm_mpm;
566572
LLVMPassManagerRef llvm_fpm;
@@ -624,6 +630,31 @@ llvm_optimize_module(LLVMJitContext *context, LLVMModuleRef module)
624630
LLVMDisposePassManager(llvm_mpm);
625631

626632
LLVMPassManagerBuilderDispose(llvm_pmb);
633+
#else
634+
LLVMPassBuilderOptionsRef options;
635+
LLVMErrorRef err;
636+
const char *passes;
637+
638+
if (context->base.flags & PGJIT_OPT3)
639+
passes = "default<O3>";
640+
else
641+
passes = "default<O0>,mem2reg";
642+
643+
options = LLVMCreatePassBuilderOptions();
644+
645+
#ifdef LLVM_PASS_DEBUG
646+
LLVMPassBuilderOptionsSetDebugLogging(options, 1);
647+
#endif
648+
649+
LLVMPassBuilderOptionsSetInlinerThreshold(options, 512);
650+
651+
err = LLVMRunPasses(module, passes, NULL, options);
652+
653+
if (err)
654+
elog(ERROR, "failed to JIT module: %s", llvm_error_message(err));
655+
656+
LLVMDisposePassBuilderOptions(options);
657+
#endif
627658
}
628659

629660
/*

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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy