v3-0002-jit-Changes-for-LLVM-17.patch
application/x-patch
Filename: v3-0002-jit-Changes-for-LLVM-17.patch
Type: application/x-patch
Part: 1
Message:
Re: LLVM 16 (opaque pointers)
Patch
Same data as JSON:
GET /api/v1/attachments/:id/patch
the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes.
API reference →
Format: format-patch
Series: patch v3-0002
Subject: jit: Changes for LLVM 17.
| File | + | − |
|---|---|---|
| src/backend/jit/llvm/llvmjit.c | 35 | 0 |
| src/backend/jit/llvm/llvmjit_wrap.cpp | 6 | 0 |
From 291d2eb56222b0f619db22cb5e9c7d263d975889 Mon Sep 17 00:00:00 2001
From: Dmitrii Dolgov <9erthalion6@gmail.com>
Date: Sun, 4 Jun 2023 11:10:41 +0200
Subject: [PATCH v3 2/2] 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>
Discussion: https://postgr.es/m/CA%2BhUKG%2BWXznXCyTgCADd%3DHWkP9Qksa6chd7L%3DGCnZo-MBgg9Lg%40mail.gmail.com
---
src/backend/jit/llvm/llvmjit.c | 35 +++++++++++++++++++++++++++
src/backend/jit/llvm/llvmjit_wrap.cpp | 6 +++++
2 files changed, 41 insertions(+)
diff --git a/src/backend/jit/llvm/llvmjit.c b/src/backend/jit/llvm/llvmjit.c
index 1c8e1ab3a7..a4cc0664f7 100644
--- a/src/backend/jit/llvm/llvmjit.c
+++ b/src/backend/jit/llvm/llvmjit.c
@@ -18,6 +18,9 @@
#include <llvm-c/BitWriter.h>
#include <llvm-c/Core.h>
#include <llvm-c/ExecutionEngine.h>
+#if LLVM_VERSION_MAJOR > 16
+#include <llvm-c/Transforms/PassBuilder.h>
+#endif
#if LLVM_VERSION_MAJOR > 11
#include <llvm-c/Orc.h>
#include <llvm-c/OrcEE.h>
@@ -27,12 +30,14 @@
#endif
#include <llvm-c/Support.h>
#include <llvm-c/Target.h>
+#if LLVM_VERSION_MAJOR < 17
#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"
@@ -630,6 +635,7 @@ llvm_function_reference(LLVMJitContext *context,
static void
llvm_optimize_module(LLVMJitContext *context, LLVMModuleRef module)
{
+#if LLVM_VERSION_MAJOR < 17
LLVMPassManagerBuilderRef llvm_pmb;
LLVMPassManagerRef llvm_mpm;
LLVMPassManagerRef llvm_fpm;
@@ -693,6 +699,35 @@ llvm_optimize_module(LLVMJitContext *context, LLVMModuleRef module)
LLVMDisposePassManager(llvm_mpm);
LLVMPassManagerBuilderDispose(llvm_pmb);
+#else
+ LLVMPassBuilderOptionsRef options;
+ LLVMErrorRef err;
+ int compile_optlevel;
+ char *passes;
+
+ if (context->base.flags & PGJIT_OPT3)
+ compile_optlevel = 3;
+ else
+ compile_optlevel = 0;
+
+ passes = psprintf("default<O%d>,mem2reg,function(no-op-function),no-op-module",
+ compile_optlevel);
+
+ options = LLVMCreatePassBuilderOptions();
+
+#ifdef LLVM_PASS_DEBUG
+ LLVMPassBuilderOptionsSetDebugLogging(options, 1);
+#endif
+
+ LLVMPassBuilderOptionsSetInlinerThreshold(options, 512);
+
+ err = LLVMRunPasses(module, passes, NULL, options);
+
+ if (err)
+ elog(ERROR, "failed to JIT module: %s", llvm_error_message(err));
+
+ LLVMDisposePassBuilderOptions(options);
+#endif
}
/*
diff --git a/src/backend/jit/llvm/llvmjit_wrap.cpp b/src/backend/jit/llvm/llvmjit_wrap.cpp
index 997a2c0278..3cf4d911df 100644
--- a/src/backend/jit/llvm/llvmjit_wrap.cpp
+++ b/src/backend/jit/llvm/llvmjit_wrap.cpp
@@ -23,8 +23,14 @@ extern "C"
#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"
--
2.42.0