pgsql: jit: Support opaque pointers in LLVM 16.

From: Thomas Munro <tmunro(at)postgresql(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: jit: Support opaque pointers in LLVM 16.
Date: 2023-10-18 10:33:25
Message-ID: E1qt3rg-00195L-KR@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers pgsql-hackers

jit: Support opaque pointers in LLVM 16.

Remove use of LLVMGetElementType() and provide the type of all pointers
to LLVMBuildXXX() functions when emitting IR, as required by modern LLVM
versions[1].

* For LLVM <= 14, we'll still use the old LLVMBuildXXX() functions.
* For LLVM == 15, we'll continue to do the same, explicitly opting
out of opaque pointer mode.
* For LLVM >= 16, we'll use the new LLVMBuildXXX2() functions that take
the extra type argument.

The difference is hidden behind some new IR emitting wrapper functions
l_load(), l_gep(), l_call() etc. The change is mostly mechanical,
except that at each site the correct type had to be provided.

In some places we needed to do some extra work to get functions types,
including some new wrappers for C++ APIs that are not yet exposed by in
LLVM's C API, and some new "example" functions in llvmjit_types.c
because it's no longer possible to start from the function pointer type
and ask for the function type.

Back-patch to 12, because it's a little tricker in 11 and we agreed not
to put the latest LLVM support into the upcoming final release of 11.

[1] https://llvm.org/docs/OpaquePointers.html

Reviewed-by: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>
Reviewed-by: Ronan Dunklau <ronan(dot)dunklau(at)aiven(dot)io>
Reviewed-by: Andres Freund <andres(at)anarazel(dot)de>
Discussion: https://postgr.es/m/CA%2BhUKGKNX_%3Df%2B1C4r06WETKTq0G4Z_7q4L4Fxn5WWpMycDj9Fw%40mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/37d5babb5cfa4c6795b3cb6de964ba019d3d60ab

Modified Files
--------------
src/backend/jit/llvm/llvmjit.c | 59 ++---
src/backend/jit/llvm/llvmjit_deform.c | 119 +++++-----
src/backend/jit/llvm/llvmjit_expr.c | 401 ++++++++++++++++++++--------------
src/backend/jit/llvm/llvmjit_types.c | 39 +++-
src/backend/jit/llvm/llvmjit_wrap.cpp | 12 +
src/backend/jit/llvm/meson.build | 2 +-
src/include/jit/llvmjit.h | 7 +
src/include/jit/llvmjit_emit.h | 106 ++++++---
8 files changed, 481 insertions(+), 264 deletions(-)

Responses

Browse pgsql-committers by date

  From Date Subject
Next Message Thomas Munro 2023-10-18 10:33:36 pgsql: jit: Support opaque pointers in LLVM 16.
Previous Message Michael Paquier 2023-10-18 09:24:18 pgsql: pg_upgrade: Fix test name in 002_pg_upgrade.pl

Browse pgsql-hackers by date

  From Date Subject
Next Message Alexander Korotkov 2023-10-18 10:34:49 Re: On login trigger: take three
Previous Message Mikhail Gribkov 2023-10-18 10:29:50 Re: On login trigger: take three