Commit 42448e37 authored by Erik de Castro Lopo's avatar Erik de Castro Lopo
Browse files

Do version specific detection of LLVM tools (#10170).

The LLVM developers seem to make breaking changes in the LLVM IR
language between major releases. As a consumer of the LLVM tools
GHC now needs to be locked more tightly to a single version of
the LLVM tools.

GHC HEAD currently only supports LLVM version 3.6. This commit
changes the configure script to look for `llc-3.6` and `opt-3.6`
before looking for `llc` and `opt`. If the former are not found,
but the later are, check that they actually are version 3.6.

At the same time, when detecting known problems with the LLVM
tools (ie #9439) test for it using the versions of the LLVM tools
retrieved from the bootstrap compiler's settings file.

Test Plan: Manual testing.

Reviewers: thomie, rwbarton, nomeata, austin

Subscribers: thomie

Differential Revision: https://phabricator.haskell.org/D745

GHC Trac Issues: #10170
parent aef4de47
......@@ -2096,38 +2096,43 @@ AC_DEFUN([XCODE_VERSION],[
# $1 = the variable to set
# $2 = the with option name
# $3 = the command to look for
# $4 = the version of the command to look for
#
AC_DEFUN([FIND_LLVM_PROG],[
FP_ARG_WITH_PATH_GNU_PROG_OPTIONAL_NOTARGET([$1], [$2], [$3])
# Test for program with version name.
FP_ARG_WITH_PATH_GNU_PROG_OPTIONAL_NOTARGET([$1], [$2], [$3-$4])
if test "$$1" = ""; then
echo -n "checking for $3-x.x... "
save_IFS=$IFS
IFS=":;"
if test "$windows" = YES; then
PERM=
MODE=
# Test for program without version name.
FP_ARG_WITH_PATH_GNU_PROG_OPTIONAL_NOTARGET([$1], [$2], [$3])
AC_MSG_CHECKING([$$1 is version $4])
if test `$$1 --version | grep -c "version $4"` -gt 0 ; then
AC_MSG_RESULT(yes)
else
# Search for executables.
PERM="-perm"
MODE="/+x"
fi
for p in ${PATH}; do
if test -d "${p}"; then
$1=`${FindCmd} "${p}" -maxdepth 1 \( -type f -o -type l \) ${PERM} ${MODE} -regex ".*/$3-[[0-9]]\.[[0-9]]" | ${SortCmd} -n | tail -1`
if test -n "$$1"; then
break
fi
fi
done
IFS=$save_IFS
if test -n "$$1"; then
echo "$$1"
else
echo "no"
fi
AC_MSG_RESULT(no)
$1=""
fi
fi
])
# FIND_GHC_BOOTSTRAP_PROG()
# --------------------------------
# Parse the bootstrap GHC's compier settings file for the location of things
# like the `llc` and `opt` commands.
#
# $1 = the variable to set
# $2 = The bootstrap compiler.
# $3 = The string to grep for to find the correct line.
#
AC_DEFUN([FIND_GHC_BOOTSTRAP_PROG],[
BootstrapTmpCmd=`grep $3 $($2 --print-libdir)/settings 2>/dev/null | sed 's/.*", "//;s/".*//'`
if test -n "$BootstrapTmpCmd" && test `basename $BootstrapTmpCmd` = $BootstrapTmpCmd ; then
AC_PATH_PROG([$1], [$BootstrapTmpCmd], "")
else
$1=$BootstrapTmpCmd
fi
])
# FIND_GCC()
# --------------------------------
# Finds where gcc is
......
......@@ -483,15 +483,21 @@ cygwin32|mingw32)
;;
esac
# Here is where we re-target which specific version of the LLVM
# tools we are looking for. In the past, GHC supported a number of
# versions of LLVM simultaneously, but that stopped working around
# 3.5/3.6 release of LLVM.
llvm_version=3.6
dnl ** Which LLVM llc to use?
dnl --------------------------------------------------------------
FIND_LLVM_PROG([LLC], [llc], [llc])
FIND_LLVM_PROG([LLC], [llc], [llc], [$llvm_version])
LlcCmd="$LLC"
AC_SUBST([LlcCmd])
dnl ** Which LLVM opt to use?
dnl --------------------------------------------------------------
FIND_LLVM_PROG([OPT], [opt], [opt])
FIND_LLVM_PROG([OPT], [opt], [opt], [$llvm_version])
OptCmd="$OPT"
AC_SUBST([OptCmd])
......@@ -513,13 +519,24 @@ dnl whether -fllvm is the stage 0 compiler's default. If so we
dnl fail. If not, we check whether -fllvm is affected explicitly and
dnl if so set a flag. The build system will later check this flag
dnl after the desired build flags are known.
if test -n "$LlcCmd" && test -n "$OptCmd"
dnl This problem is further complicated by the fact that the llvm
dnl version used by the bootstrap compiler may be different from the
dnl version we arre trying to compile GHC against. Therefore, we need
dnl to find the boostrap compiler's `settings` file then check to see
dnl if the `opt` and `llc` command strings are non-empty and if these
dnl programs exist. Only if they exist to we test for bug #9439.
FIND_GHC_BOOTSTRAP_PROG([BootstrapLlcCmd], [${WithGhc}], "LLVM llc command")
FIND_GHC_BOOTSTRAP_PROG([BootstrapOptCmd], [${WithGhc}], "LLVM opt command")
if test -n "$BootstrapLlcCmd" && test -n "$BootstrapOptCmd"
then
AC_MSG_CHECKING(whether bootstrap compiler is affected by bug 9439)
echo "main = putStrLn \"%function\"" > conftestghc.hs
# Check whether LLVM backend is default for this platform
"${WithGhc}" -pgmlc="${LlcCmd}" -pgmlo="${OptCmd}" conftestghc.hs 2>&1 >/dev/null
"${WithGhc}" -pgmlc="${BootstrapLlcCmd}" -pgmlo="${BootstrapOptCmd}" conftestghc.hs 2>&1 >/dev/null
res=`./conftestghc`
if test "x$res" = "x%object"
then
......@@ -536,7 +553,7 @@ then
# -fllvm is not the default, but set a flag so the Makefile can check
# -for it in the build flags later on
"${WithGhc}" -fforce-recomp -pgmlc="${LlcCmd}" -pgmlo="${OptCmd}" -fllvm conftestghc.hs 2>&1 >/dev/null
"${WithGhc}" -fforce-recomp -pgmlc="${BootstrapLlcCmd}" -pgmlo="${BootstrapOptCmd}" -fllvm conftestghc.hs 2>&1 >/dev/null
if test $? = 0
then
res=`./conftestghc`
......
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