Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 5b2526c

Browse files
committed
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
1 parent 6869b4f commit 5b2526c

File tree

7 files changed

+939
-69
lines changed

7 files changed

+939
-69
lines changed

aclocal.m4

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ m4_include([config/c-library.m4])
77
m4_include([config/docbook.m4])
88
m4_include([config/general.m4])
99
m4_include([config/libtool.m4])
10+
m4_include([config/llvm.m4])
1011
m4_include([config/perl.m4])
1112
m4_include([config/pkg.m4])
1213
m4_include([config/programs.m4])

config/llvm.m4

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
# config/llvm.m4
2+
3+
# PGAC_LLVM_SUPPORT
4+
# ---------------
5+
#
6+
# Look for the LLVM installation, check that it's new enough, set the
7+
# corresponding LLVM_{CFLAGS,CXXFLAGS,BINPATH} and LDFLAGS
8+
# variables. Also verifies that CLANG is available, to transform C
9+
# into bitcode.
10+
#
11+
AC_DEFUN([PGAC_LLVM_SUPPORT],
12+
[
13+
AC_REQUIRE([AC_PROG_AWK])
14+
15+
AC_ARG_VAR(LLVM_CONFIG, [path to llvm-config command])
16+
PGAC_PATH_PROGS(LLVM_CONFIG, llvm-config llvm-config-6.0 llvm-config-5.0 llvm-config-4.0 llvm-config-3.9)
17+
18+
# no point continuing if llvm wasn't found
19+
if test -z "$LLVM_CONFIG"; then
20+
AC_MSG_ERROR([llvm-config not found, but required when compiling --with-llvm, specify with LLVM_CONFIG=])
21+
fi
22+
# check if detected $LLVM_CONFIG is executable
23+
pgac_llvm_version="$($LLVM_CONFIG --version 2> /dev/null || echo no)"
24+
if test "x$pgac_llvm_version" = "xno"; then
25+
AC_MSG_ERROR([$LLVM_CONFIG does not work])
26+
fi
27+
# and whether the version is supported
28+
if echo $pgac_llvm_version | $AWK -F '.' '{ if ([$]1 >= 4 || ([$]1 == 3 && [$]2 >= 9)) exit 1; else exit 0;}';then
29+
AC_MSG_ERROR([$LLVM_CONFIG version is $pgac_llvm_version but at least 3.9 is required])
30+
fi
31+
32+
# need clang to create some bitcode files
33+
AC_ARG_VAR(CLANG, [path to clang compiler to generate bitcode])
34+
PGAC_PATH_PROGS(CLANG, clang clang-6.0 clang-5.0 clang-4.0 clang-3.9)
35+
if test -z "$CLANG"; then
36+
AC_MSG_ERROR([clang not found, but required when compiling --with-llvm, specify with CLANG=])
37+
fi
38+
# make sure clang is executable
39+
if test "x$($CLANG --version 2> /dev/null || echo no)" = "xno"; then
40+
AC_MSG_ERROR([$CLANG does not work])
41+
fi
42+
# Could check clang version, but it doesn't seem that
43+
# important. Systems with a new enough LLVM version are usually
44+
# going to have a decent clang version too. It's also not entirely
45+
# clear what the minimum version is.
46+
47+
# Collect compiler flags necessary to build the LLVM dependent
48+
# shared library.
49+
for pgac_option in `$LLVM_CONFIG --cppflags`; do
50+
case $pgac_option in
51+
-I*|-D*) LLVM_CPPFLAGS="$pgac_option $LLVM_CPPFLAGS";;
52+
esac
53+
done
54+
55+
for pgac_option in `$LLVM_CONFIG --ldflags`; do
56+
case $pgac_option in
57+
-L*) LDFLAGS="$LDFLAGS $pgac_option";;
58+
esac
59+
done
60+
61+
# ABI influencing options, standard influencing options
62+
for pgac_option in `$LLVM_CONFIG --cxxflags`; do
63+
case $pgac_option in
64+
-fno-rtti*) LLVM_CXXFLAGS="$LLVM_CXXFLAGS $pgac_option";;
65+
-std=*) LLVM_CXXFLAGS="$LLVM_CXXFLAGS $pgac_option";;
66+
esac
67+
done
68+
69+
# Look for components we're interested in, collect necessary
70+
# libs. As some components are optional, we can't just list all of
71+
# them as it'd raise an error.
72+
pgac_components='';
73+
for pgac_component in `$LLVM_CONFIG --components`; do
74+
case $pgac_component in
75+
engine) pgac_components="$pgac_components $pgac_component";;
76+
debuginfodwarf) pgac_components="$pgac_components $pgac_component";;
77+
orcjit) pgac_components="$pgac_components $pgac_component";;
78+
passes) pgac_components="$pgac_components $pgac_component";;
79+
perfjitevents) pgac_components="$pgac_components $pgac_component";;
80+
esac
81+
done;
82+
83+
# And then get the libraries that need to be linked in for the
84+
# selected components. They're large libraries, we only want to
85+
# link them into the LLVM using shared library.
86+
for pgac_option in `$LLVM_CONFIG --libs --system-libs $pgac_components`; do
87+
case $pgac_option in
88+
-l*) LLVM_LIBS="$LLVM_LIBS $pgac_option";;
89+
esac
90+
done
91+
92+
LLVM_BINPATH=`$LLVM_CONFIG --bindir`
93+
94+
# Check which functionality is present
95+
SAVE_CPPFLAGS="$CPPFLAGS"
96+
CPPFLAGS="$CPPFLAGS $LLVM_CPPFLAGS"
97+
AC_CHECK_DECLS([LLVMOrcGetSymbolAddressIn, LLVMOrcRegisterGDB, LLVMOrcRegisterPerf], [], [], [[#include <llvm-c/OrcBindings.h>]])
98+
AC_CHECK_DECLS([LLVMGetHostCPUName], [], [], [[#include <llvm-c/TargetMachine.h>]])
99+
CPPFLAGS="$SAVE_CPPFLAGS"
100+
101+
# LLVM_CONFIG, CLANG are already output via AC_ARG_VAR
102+
AC_SUBST(LLVM_LIBS)
103+
AC_SUBST(LLVM_CPPFLAGS)
104+
AC_SUBST(LLVM_CFLAGS)
105+
AC_SUBST(LLVM_CXXFLAGS)
106+
AC_SUBST(LLVM_BINPATH)
107+
108+
])# PGAC_LLVM_SUPPORT

0 commit comments

Comments
 (0)