Re: JIT compiling with LLVM v11

Thomas Munro <thomas.munro@enterprisedb.com>

From: Thomas Munro <thomas.munro@enterprisedb.com>
To: Andres Freund <andres@anarazel.de>
Cc: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>, Pg Hackers <pgsql-hackers@postgresql.org>, Pierre Ducroquet <p.psql@pinaraf.info>
Date: 2018-03-05T04:32:09Z
Lists: pgsql-hackers
On Sun, Mar 4, 2018 at 8:39 AM, Andres Freund <andres@anarazel.de> wrote:
> On 2018-03-03 09:37:35 -0500, Peter Eisentraut wrote:
>> [discussion of making this work on a Mac]

I tried out your "jit" branch on my macOS 10.13.3 system.  Vendor "cc"
and "c++" are version "Apple LLVM version 9.0.0 (clang-900.0.39.2)".
I used MacPorts (whereas Peter E is using HomeBrew) to install LLVM
with "sudo port install llvm-5.0".

First, I built it like this:

./configure
  --prefix=$HOME/install/postgres \
  --enable-debug --enable-cassert --enable-depend --with-llvm --with-openssl \
  --enable-tap-tests \
  --with-includes="/opt/local/include" --with-libraries="/opt/local/lib" \
  CC="ccache cc" CXX="ccache c++" LLVM_CONFIG=/opt/local/bin/llvm-config-mp-5.0

The build succeeded, initdb ran, the server started up, and then I
tried the sequence Andres showed:

set jit_above_cost = 0;
set client_min_messages=debug2;
SELECT pg_jit_available();

On that last command I got:

DEBUG:  probing availability of llvm for JIT at
/Users/munro/install/postgres/lib/llvmjit.so
DEBUG:  successfully loaded LLVM in current session
DEBUG:  time to opt: 0.001s
DEBUG:  time to emit: 0.034s
ERROR:  failed to JIT: evalexpr_0_0

Looking at the server output I saw:

warning: ignoring debug info with an invalid version (700000003) in
/Users/munro/install/postgres/lib/llvmjit_types.bc
2018-03-05 16:50:05.888 NZDT [14797] ERROR:  failed to JIT: evalexpr_0_0
2018-03-05 16:50:05.888 NZDT [14797] STATEMENT:  SELECT pg_jit_available();

I could see that llvmjit_types.bc had been produced by this command:

/usr/bin/clang -Wno-ignored-attributes -Wno-unknown-warning-option
-Wno-ignored-optimization-argument -Wall -Wmissing-prototypes
-Wpointer-arith -Wdeclaration-after-statement -Wendif-labels
-Wmissing-format-attribute -Wformat-security -fno-strict-aliasing
-fwrapv -Wno-unused-command-line-argument -g -O0 -Wall -Werror  -O1
-I../../../../src/include  -I/opt/local/include -flto=thin -emit-llvm
-c -o pseudotypes.bc pseudotypes.c

So I tried installing a later clang with "sudo port install clang-5.0"
and setting CLANG=/pt/local/bin/clang-mp-5.0.  It builds and uses that
clang to generate the .bc files, but gives the same error, this time
without the "warning" message.

Looking at llvm_get_function(), the function that raises that error, I
see that there are a few different paths here.  I don't have
HAVE_DECL_LLVMORCGETSYMBOLADDRESSIN defined, and I don't have LLVM <
5, so I should be getting the symbol address with
LLVMOrcGetSymbolAddress(llvm_opt0_orc, &addr, mangled) or
LLVMOrcGetSymbolAddress(llvm_opt3_orc, &addr, mangled), but clearly
those are returning NULL.

Not sure what's happening yet...

-- 
Thomas Munro
http://www.enterprisedb.com


Commits

  1. Improve JIT docs.

  2. Add documentation for the JIT feature.

  3. Add EXPLAIN support for JIT.

  4. Add inlining support to LLVM JIT provider.

  5. JIT tuple deforming in LLVM JIT provider.

  6. Add FIELDNO_* macro designating offset into structs required for JIT.

  7. Add expression compilation support to LLVM JIT provider.

  8. Expand list of synchronized types and functions in LLVM JIT provider.

  9. Add helpers for emitting LLVM IR.

  10. Basic planner and executor integration for JIT.

  11. Debugging and profiling support for LLVM JIT provider.

  12. Support for optimizing and emitting code in LLVM JIT provider.

  13. Add file containing extensions of the LLVM C API.

  14. Basic JIT provider and error handling infrastructure.

  15. Add configure infrastructure (--with-llvm) to enable LLVM support.

  16. Add C++ support to configure.

  17. Add PGAC_PROG_VARCC_VARFLAGS_OPT autoconf macro.

  18. Fix VM buffer pin management in heap_lock_updated_tuple_rec().

  19. Allow tupleslots to have a fixed tupledesc, use in executor nodes.

  20. Expression evaluation based aggregate transition invocation.

  21. Perform slot validity checks in a separate pass over expression.

  22. Rely on executor utils to build targetlist for DML RETURNING.

  23. Refer to OS X as "macOS", except for the port name which is still "darwin".