Commit 5b2526c8 authored by Andres Freund's avatar Andres Freund

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

LLVM will be used for *optional* Just-in-time compilation
support. This commit just adds the configure infrastructure that
detects LLVM.

No documentation has been added for the --with-llvm flag, that'll be
added after the actual supporting code has been added.

Author: Andres Freund
Discussion: https://postgr.es/m/20170901064131.tazjxwus3k2w3ybh@alap3.anarazel.de
parent 6869b4f2
......@@ -7,6 +7,7 @@ m4_include([config/c-library.m4])
m4_include([config/docbook.m4])
m4_include([config/general.m4])
m4_include([config/libtool.m4])
m4_include([config/llvm.m4])
m4_include([config/perl.m4])
m4_include([config/pkg.m4])
m4_include([config/programs.m4])
......
# config/llvm.m4
# PGAC_LLVM_SUPPORT
# ---------------
#
# Look for the LLVM installation, check that it's new enough, set the
# corresponding LLVM_{CFLAGS,CXXFLAGS,BINPATH} and LDFLAGS
# variables. Also verifies that CLANG is available, to transform C
# into bitcode.
#
AC_DEFUN([PGAC_LLVM_SUPPORT],
[
AC_REQUIRE([AC_PROG_AWK])
AC_ARG_VAR(LLVM_CONFIG, [path to llvm-config command])
PGAC_PATH_PROGS(LLVM_CONFIG, llvm-config llvm-config-6.0 llvm-config-5.0 llvm-config-4.0 llvm-config-3.9)
# no point continuing if llvm wasn't found
if test -z "$LLVM_CONFIG"; then
AC_MSG_ERROR([llvm-config not found, but required when compiling --with-llvm, specify with LLVM_CONFIG=])
fi
# check if detected $LLVM_CONFIG is executable
pgac_llvm_version="$($LLVM_CONFIG --version 2> /dev/null || echo no)"
if test "x$pgac_llvm_version" = "xno"; then
AC_MSG_ERROR([$LLVM_CONFIG does not work])
fi
# and whether the version is supported
if echo $pgac_llvm_version | $AWK -F '.' '{ if ([$]1 >= 4 || ([$]1 == 3 && [$]2 >= 9)) exit 1; else exit 0;}';then
AC_MSG_ERROR([$LLVM_CONFIG version is $pgac_llvm_version but at least 3.9 is required])
fi
# need clang to create some bitcode files
AC_ARG_VAR(CLANG, [path to clang compiler to generate bitcode])
PGAC_PATH_PROGS(CLANG, clang clang-6.0 clang-5.0 clang-4.0 clang-3.9)
if test -z "$CLANG"; then
AC_MSG_ERROR([clang not found, but required when compiling --with-llvm, specify with CLANG=])
fi
# make sure clang is executable
if test "x$($CLANG --version 2> /dev/null || echo no)" = "xno"; then
AC_MSG_ERROR([$CLANG does not work])
fi
# Could check clang version, but it doesn't seem that
# important. Systems with a new enough LLVM version are usually
# going to have a decent clang version too. It's also not entirely
# clear what the minimum version is.
# Collect compiler flags necessary to build the LLVM dependent
# shared library.
for pgac_option in `$LLVM_CONFIG --cppflags`; do
case $pgac_option in
-I*|-D*) LLVM_CPPFLAGS="$pgac_option $LLVM_CPPFLAGS";;
esac
done
for pgac_option in `$LLVM_CONFIG --ldflags`; do
case $pgac_option in
-L*) LDFLAGS="$LDFLAGS $pgac_option";;
esac
done
# ABI influencing options, standard influencing options
for pgac_option in `$LLVM_CONFIG --cxxflags`; do
case $pgac_option in
-fno-rtti*) LLVM_CXXFLAGS="$LLVM_CXXFLAGS $pgac_option";;
-std=*) LLVM_CXXFLAGS="$LLVM_CXXFLAGS $pgac_option";;
esac
done
# Look for components we're interested in, collect necessary
# libs. As some components are optional, we can't just list all of
# them as it'd raise an error.
pgac_components='';
for pgac_component in `$LLVM_CONFIG --components`; do
case $pgac_component in
engine) pgac_components="$pgac_components $pgac_component";;
debuginfodwarf) pgac_components="$pgac_components $pgac_component";;
orcjit) pgac_components="$pgac_components $pgac_component";;
passes) pgac_components="$pgac_components $pgac_component";;
perfjitevents) pgac_components="$pgac_components $pgac_component";;
esac
done;
# And then get the libraries that need to be linked in for the
# selected components. They're large libraries, we only want to
# link them into the LLVM using shared library.
for pgac_option in `$LLVM_CONFIG --libs --system-libs $pgac_components`; do
case $pgac_option in
-l*) LLVM_LIBS="$LLVM_LIBS $pgac_option";;
esac
done
LLVM_BINPATH=`$LLVM_CONFIG --bindir`
# Check which functionality is present
SAVE_CPPFLAGS="$CPPFLAGS"
CPPFLAGS="$CPPFLAGS $LLVM_CPPFLAGS"
AC_CHECK_DECLS([LLVMOrcGetSymbolAddressIn, LLVMOrcRegisterGDB, LLVMOrcRegisterPerf], [], [], [[#include <llvm-c/OrcBindings.h>]])
AC_CHECK_DECLS([LLVMGetHostCPUName], [], [], [[#include <llvm-c/TargetMachine.h>]])
CPPFLAGS="$SAVE_CPPFLAGS"
# LLVM_CONFIG, CLANG are already output via AC_ARG_VAR
AC_SUBST(LLVM_LIBS)
AC_SUBST(LLVM_CPPFLAGS)
AC_SUBST(LLVM_CFLAGS)
AC_SUBST(LLVM_CXXFLAGS)
AC_SUBST(LLVM_BINPATH)
])# PGAC_LLVM_SUPPORT
This diff is collapsed.
......@@ -375,6 +375,19 @@ choke me
AC_SUBST(SUN_STUDIO_CC)
#
# LLVM
#
# Checked early because subsequent tests depend on it.
PGAC_ARG_BOOL(with, llvm, no, [build with LLVM based JIT support],
[AC_DEFINE([USE_LLVM], 1, [Define to 1 to build with LLVM based JIT support. (--with-llvm)])])
AC_SUBST(with_llvm)
if test "$with_llvm" = yes ; then
PGAC_LLVM_SUPPORT()
fi
unset CFLAGS
#
......@@ -419,11 +432,32 @@ else
fi
fi
# When generating bitcode (for inlining) we always want to use -O2
# even when --enable-debug is specified. The bitcode it's not going to
# be used for line-by-line debugging, and JIT inlining doesn't work
# without at least -O1 (otherwise clang will emit 'noinline'
# attributes everywhere), which is bad for testing. Still allow the
# environment to override if done explicitly.
if test "$ac_env_BITCODE_CFLAGS_set" = set; then
BITCODE_CFLAGS=$ac_env_BITCODE_CFLAGS_value
else
BITCODE_CFLAGS="-O2 $BITCODE_CFLAGS"
fi
if test "$ac_env_BITCODE_CXXFLAGS_set" = set; then
BITCODE_CXXFLAGS=$ac_env_BITCODE_CXXFLAGS_value
else
BITCODE_CXXFLAGS="-O2 BITCODE_CXXFLAGS"
fi
# C[XX]FLAGS we determined above will be added back at the end
user_CFLAGS=$CFLAGS
CFLAGS=""
user_CXXFLAGS=$CXXFLAGS
CXXFLAGS=""
user_BITCODE_CFLAGS=$BITCODE_CFLAGS
BITCODE_CFLAGS=""
user_BITCODE_CXXFLAGS=$BITCODE_CXXFLAGS
BITCODE_CXXFLAGS=""
# set CFLAGS_VECTOR from the environment, if available
if test "$ac_env_CFLAGS_VECTOR_set" = set; then
......@@ -490,6 +524,20 @@ fi
AC_SUBST(CFLAGS_VECTOR, $CFLAGS_VECTOR)
# Determine flags used to emit bitcode for JIT inlining. Need to test
# for behaviour changing compiler flags, to keep compatibility with
# compiler used for normal postgres code.
if test "$with_llvm" = yes ; then
CLANGXX="$CLANG -xc++"
PGAC_PROG_VARCC_VARFLAGS_OPT(CLANG, BITCODE_CFLAGS, [-fno-strict-aliasing])
PGAC_PROG_VARCXX_VARFLAGS_OPT(CLANGXX, BITCODE_CXXFLAGS, [-fno-strict-aliasing])
PGAC_PROG_VARCC_VARFLAGS_OPT(CLANG, BITCODE_CFLAGS, [-fwrapv])
PGAC_PROG_VARCXX_VARFLAGS_OPT(CLANGXX, BITCODE_CXXFLAGS, [-fwrapv])
PGAC_PROG_VARCC_VARFLAGS_OPT(CLANG, BITCODE_CFLAGS, [-fexcess-precision=standard])
PGAC_PROG_VARCXX_VARFLAGS_OPT(CLANGXX, BITCODE_CXXFLAGS, [-fexcess-precision=standard])
fi
# supply -g if --enable-debug
if test "$enable_debug" = yes && test "$ac_cv_prog_cc_g" = yes; then
CFLAGS="$CFLAGS -g"
......@@ -531,6 +579,11 @@ fi
# the automatic additions.
CFLAGS="$CFLAGS $user_CFLAGS"
CXXFLAGS="$CXXFLAGS $user_CXXFLAGS"
BITCODE_CFLAGS="$BITCODE_CFLAGS $user_BITCODE_CFLAGS"
BITCODE_CXXFLAGS="$BITCODE_CXXFLAGS $user_BITCODE_CXXFLAGS"
AC_SUBST(BITCODE_CFLAGS, $BITCODE_CFLAGS)
AC_SUBST(BITCODE_CXXFLAGS, $BITCODE_CXXFLAGS)
# Check if the compiler still works with the final flag settings
# (note, we're not checking that for CXX, which is optional)
......@@ -2246,9 +2299,16 @@ AC_SUBST(PG_VERSION_NUM)
AC_MSG_NOTICE([using compiler=$cc_string])
AC_MSG_NOTICE([using CFLAGS=$CFLAGS])
AC_MSG_NOTICE([using CXXFLAGS=$CXXFLAGS])
AC_MSG_NOTICE([using CPPFLAGS=$CPPFLAGS])
AC_MSG_NOTICE([using LDFLAGS=$LDFLAGS])
# Currently only used when LLVM is used
if test "$with_llvm" = yes ; then
AC_MSG_NOTICE([using CXX=$CXX])
AC_MSG_NOTICE([using CXXFLAGS=$CXXFLAGS])
AC_MSG_NOTICE([using CLANG=$CLANG])
AC_MSG_NOTICE([using BITCODE_CFLAGS=$BITCODE_CFLAGS])
AC_MSG_NOTICE([using BITCODE_CXXFLAGS=$BITCODE_CXXFLAGS])
fi
# prepare build tree if outside source tree
# Note 1: test -ef might not exist, but it's more reliable than `pwd`.
......
......@@ -191,6 +191,7 @@ with_krb_srvnam = @with_krb_srvnam@
with_ldap = @with_ldap@
with_libxml = @with_libxml@
with_libxslt = @with_libxslt@
with_llvm = @with_llvm@
with_system_tzdata = @with_system_tzdata@
with_uuid = @with_uuid@
with_zlib = @with_zlib@
......@@ -225,6 +226,11 @@ TCL_SHLIB_LD_LIBS = @TCL_SHLIB_LD_LIBS@
PTHREAD_CFLAGS = @PTHREAD_CFLAGS@
PTHREAD_LIBS = @PTHREAD_LIBS@
LLVM_CONFIG = @LLVM_CONFIG@
LLVM_BINPATH = @LLVM_BINPATH@
CLANG = @CLANG@
BITCODE_CFLAGS = @BITCODE_CFLAGS@
BITCODE_CXXFLAGS = @BITCODE_CXXFLAGS@
##########################################################################
#
......@@ -255,6 +261,10 @@ CFLAGS_VECTOR = @CFLAGS_VECTOR@
CFLAGS_SSE42 = @CFLAGS_SSE42@
CXXFLAGS = @CXXFLAGS@
LLVM_CPPFLAGS = @LLVM_CPPFLAGS@
LLVM_CFLAGS = @LLVM_CFLAGS@
LLVM_CXXFLAGS = @LLVM_CXXFLAGS@
# Kind-of compilers
BISON = @BISON@
......@@ -275,6 +285,7 @@ LDAP_LIBS_FE = @LDAP_LIBS_FE@
LDAP_LIBS_BE = @LDAP_LIBS_BE@
UUID_LIBS = @UUID_LIBS@
UUID_EXTRA_OBJS = @UUID_EXTRA_OBJS@
LLVM_LIBS=@LLVM_LIBS@
LD = @LD@
with_gnu_ld = @with_gnu_ld@
......
......@@ -134,6 +134,22 @@
don't. */
#undef HAVE_DECL_F_FULLFSYNC
/* Define to 1 if you have the declaration of `LLVMGetHostCPUName', and to 0
if you don't. */
#undef HAVE_DECL_LLVMGETHOSTCPUNAME
/* Define to 1 if you have the declaration of `LLVMOrcGetSymbolAddressIn', and
to 0 if you don't. */
#undef HAVE_DECL_LLVMORCGETSYMBOLADDRESSIN
/* Define to 1 if you have the declaration of `LLVMOrcRegisterGDB', and to 0
if you don't. */
#undef HAVE_DECL_LLVMORCREGISTERGDB
/* Define to 1 if you have the declaration of `LLVMOrcRegisterPerf', and to 0
if you don't. */
#undef HAVE_DECL_LLVMORCREGISTERPERF
/* Define to 1 if you have the declaration of `posix_fadvise', and to 0 if you
don't. */
#undef HAVE_DECL_POSIX_FADVISE
......@@ -850,6 +866,9 @@
(--with-libxslt) */
#undef USE_LIBXSLT
/* Define to 1 to build with LLVM based JIT support. (--with-llvm) */
#undef USE_LLVM
/* Define to select named POSIX semaphores. */
#undef USE_NAMED_POSIX_SEMAPHORES
......
......@@ -98,6 +98,22 @@
don't. */
#define HAVE_DECL_F_FULLFSYNC 0
/* Define to 1 if you have the declaration of `LLVMGetHostCPUName', and to 0
if you don't. */
#define HAVE_DECL_LLVMGETHOSTCPUNAME 0
/* Define to 1 if you have the declaration of `LLVMOrcGetSymbolAddressIn', and
to 0 if you don't. */
#define HAVE_DECL_LLVMORCGETSYMBOLADDRESSIN 0
/* Define to 1 if you have the declaration of `LLVMOrcRegisterGDB', and to 0
if you don't. */
#define HAVE_DECL_LLVMORCREGISTERGDB 0
/* Define to 1 if you have the declaration of `LLVMOrcRegisterPerf', and to 0
if you don't. */
#define HAVE_DECL_LLVMORCREGISTERPERF 0
/* Define to 1 if you have the declaration of `snprintf', and to 0 if you
don't. */
#define HAVE_DECL_SNPRINTF 1
......@@ -631,6 +647,9 @@
/* Define to 1 to build with LDAP support. (--with-ldap) */
/* #undef USE_LDAP */
/* Define to 1 to build with LLVM based JIT support. (--with-llvm) */
/* #undef USE_LLVM */
/* Define to select named POSIX semaphores. */
/* #undef USE_NAMED_POSIX_SEMAPHORES */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment