Skip to content

Commit

Permalink
Support for optimizing and emitting code in LLVM JIT provider.
Browse files Browse the repository at this point in the history
This commit introduces the ability to actually generate code using
LLVM. In particular, this adds:

- Ability to emit code both in heavily optimized and largely
  unoptimized fashion
- Batching facility to allow functions to be defined in small
  increments, but optimized and emitted in executable form in larger
  batches (for performance and memory efficiency)
- Type and function declaration synchronization between runtime
  generated code and normal postgres code. This is critical to be able
  to access struct fields etc.
- Developer oriented jit_dump_bitcode GUC, for inspecting / debugging
  the generated code.
- per JitContext statistics of number of functions, time spent
  generating code, optimizing, and emitting it.  This will later be
  employed for EXPLAIN support.

This commit doesn't yet contain any code actually generating
functions. That'll follow in later commits.

Documentation for GUCs added, and for JIT in general, will be added in
later commits.

Author: Andres Freund, with contributions by Pierre Ducroquet
Testing-By: Thomas Munro, Peter Eisentraut
Discussion: https://postgr.es/m/20170901064131.tazjxwus3k2w3ybh@alap3.anarazel.de
  • Loading branch information
anarazel committed Mar 22, 2018
1 parent 2fe6336 commit b96d550
Show file tree
Hide file tree
Showing 11 changed files with 748 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1,6 +1,7 @@
# Global excludes across all subdirectories
*.o
*.obj
*.bc
*.so
*.so.[0-9]
*.so.[0-9].[0-9]
Expand Down
21 changes: 21 additions & 0 deletions src/Makefile.global.in
Expand Up @@ -951,3 +951,24 @@ coverage-clean:
rm -f `find . -name '*.gcda' -print`

endif # enable_coverage

##########################################################################
#
# LLVM support
#

ifndef COMPILE.c.bc
# -Wno-ignored-attributes added so gnu_printf doesn't trigger
# warnings, when the main binary is compiled with C.
COMPILE.c.bc = $(CLANG) -Wno-ignored-attributes $(BITCODE_CFLAGS) $(CPPFLAGS) -flto=thin -emit-llvm -c
endif

ifndef COMPILE.cxx.bc
COMPILE.cxx.bc = $(CLANG) -xc++ -Wno-ignored-attributes $(BITCODE_CXXFLAGS) $(CPPFLAGS) -flto=thin -emit-llvm -c
endif

%.bc : %.c
$(COMPILE.c.bc) -o $@ $<

%.bc : %.cpp
$(COMPILE.cxx.bc) -o $@ $<
1 change: 1 addition & 0 deletions src/backend/common.mk
Expand Up @@ -46,3 +46,4 @@ clean-local:
rm -f $(subsysfilename) $(OBJS)

$(call recurse,coverage)
$(call recurse,install)
1 change: 1 addition & 0 deletions src/backend/jit/jit.c
Expand Up @@ -33,6 +33,7 @@
/* GUCs */
bool jit_enabled = true;
char *jit_provider = "llvmjit";
bool jit_dump_bitcode = false;

static JitProviderCallbacks provider;
static bool provider_successfully_loaded = false;
Expand Down
14 changes: 11 additions & 3 deletions src/backend/jit/llvm/Makefile
Expand Up @@ -41,15 +41,23 @@ OBJS += llvmjit.o llvmjit_error.o llvmjit_wrap.o
# Code generation
OBJS +=

all: all-shared-lib
all: all-shared-lib llvmjit_types.bc

install: all installdirs install-lib
install: all installdirs install-lib install-types

installdirs: installdirs-lib

uninstall: uninstall-lib
uninstall: uninstall-lib uninstall-types

# Note this is intentionally not in bitcodedir, as it's not for inlining */
install-types: llvmjit_types.bc
$(INSTALL_DATA) llvmjit_types.bc '$(DESTDIR)$(pkglibdir)'

uninstall-types:
rm -f '$(DESTDIR)$(pkglibdir)/llvmjit_types.bc'

include $(top_srcdir)/src/Makefile.shlib

clean distclean maintainer-clean: clean-lib
rm -f $(OBJS)
rm -f llvmjit_types.bc

0 comments on commit b96d550

Please sign in to comment.