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://firstname.lastname@example.org
9370462e9a Add inlining support to LLVM JIT provider.
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(-)