pgsql: Add inlining support to LLVM JIT provider.

From: Andres Freund <andres(at)anarazel(dot)de>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Add inlining support to LLVM JIT provider.
Date: 2018-03-28 20:20:58
Message-ID: E1f1HZ4-0003yh-NE@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Add inlining support to LLVM JIT provider.

This provides infrastructure to allow JITed code to inline code
implemented in C. This e.g. can be postgres internal functions or
extension code.

This already speeds up long running queries, by allowing the LLVM
optimizer to optimize across function boundaries. The optimization
potential currently doesn't reach its full potential because LLVM
cannot optimize the FunctionCallInfoData argument fully away, because
it's allocated on the heap rather than the stack. Fixing that is
beyond what's realistic for v11.

To be able to do that, use CLANG to convert C code to LLVM bitcode,
and have LLVM build a summary for it. That bitcode can then be used to
to inline functions at runtime. For that the bitcode needs to be
installed. Postgres bitcode goes into $pkglibdir/bitcode/postgres,
extensions go into equivalent directories. PGXS has been modified so
that happens automatically if postgres has been compiled with LLVM
support.

Currently this isn't the fastest inline implementation, modules are
reloaded from disk during inlining. That's to work around an apparent
LLVM bug, triggering an apparently spurious error in LLVM assertion
enabled builds. Once that is resolved we can remove the superfluous
read from disk.

Docs will follow in a later commit containing docs for the whole JIT
feature.

Author: Andres Freund
Discussion: https://postgr.es/m/20170901064131.tazjxwus3k2w3ybh@alap3.anarazel.de

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/9370462e9a79755aea367c62eb0fef96f0c42258

Modified Files
--------------
src/Makefile.global.in | 34 +
src/backend/Makefile | 10 +
src/backend/common.mk | 6 +-
src/backend/jit/jit.c | 1 +
src/backend/jit/llvm/Makefile | 2 +-
src/backend/jit/llvm/llvmjit.c | 17 +-
src/backend/jit/llvm/llvmjit_inline.cpp | 877 ++++++++++++++++++++++++++
src/backend/optimizer/plan/planner.c | 3 +
src/backend/utils/misc/guc.c | 10 +
src/backend/utils/misc/postgresql.conf.sample | 3 +
src/include/jit/jit.h | 6 +-
src/include/jit/llvmjit.h | 1 +
src/makefiles/pgxs.mk | 26 +-
13 files changed, 988 insertions(+), 8 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Andres Freund 2018-03-28 20:30:41 pgsql: Add EXPLAIN support for JIT.
Previous Message Fujii Masao 2018-03-28 19:59:37 pgsql: Make pg_rewind skip files and directories that are removed durin