summaryrefslogtreecommitdiff
path: root/utils/llvm-targets
diff options
context:
space:
mode:
authorMoritz Angermann <moritz.angermann@gmail.com>2017-09-06 11:31:01 -0400
committerBen Gamari <ben@smart-cactus.org>2017-09-06 11:33:07 -0400
commit22733532171330136d87533d523f565f2a4f102f (patch)
treed399f168096fe203d459fb5fa0fc1210ff05bd4c /utils/llvm-targets
parent0cd467b2269595e1ae2bc273c3acf9e14adeb9e7 (diff)
downloadhaskell-22733532171330136d87533d523f565f2a4f102f.tar.gz
Clean up opt and llc
The LLVM backend shells out to LLVMs `opt` and `llc` tools. This clean up introduces a shared data structure to carry the arguments we pass to each tool so that corresponding flags are next to each other. It drops the hard coded data layouts in favor of using `-mtriple` and have LLVM infer them. Furthermore we add `clang` as a proper tool, so we don't rely on assuming that `clang` is called `clang` on the `PATH` when using `clang` as the assembler. Finally this diff also changes the type of `optLevel` from `Int` to `Word`, as we do not have negative optimization levels. Reviewers: erikd, hvr, austin, rwbarton, bgamari, kavon Reviewed By: kavon Subscribers: michalt, Ericson2314, ryantrinkle, dfeuer, carter, simonpj, kavon, simonmar, thomie, erikd, snowleopard Differential Revision: https://phabricator.haskell.org/D3352
Diffstat (limited to 'utils/llvm-targets')
-rwxr-xr-xutils/llvm-targets/gen-data-layout.sh80
1 files changed, 80 insertions, 0 deletions
diff --git a/utils/llvm-targets/gen-data-layout.sh b/utils/llvm-targets/gen-data-layout.sh
new file mode 100755
index 0000000000..315222fe1d
--- /dev/null
+++ b/utils/llvm-targets/gen-data-layout.sh
@@ -0,0 +1,80 @@
+#!/bin/bash
+#
+# llvm-target generator
+#
+# Author: Moritz Angermann <moritz.angermann@gmail.com>
+#
+# This file generates the `llvm-targets` file, which contains the
+# data-layout, cpu and attributes for the target. This is done by
+# querying `clang` for the data-layout, cpu and attributes based
+# on a given target.
+#
+# To utilize it run it as
+#
+# $ ./gen-data-layout.sh > llvm-targets
+#
+# Add missing targets to the list below to have them included in
+# llvm-targets file.
+
+# Target sets
+WINDOWS_x86="i386-unknown-windows i686-unknown-windows x86_64-unknown-windows"
+LINUX_ARM="arm-unknown-linux-gnueabihf armv6-unknown-linux-gnueabihf armv7-unknown-linux-gnueabihf aarch64-unknown-linux-gnu aarch64-unknown-linux"
+LINUX_x86="i386-unknown-linux-gnu i386-unknown-linux x86_64-unknown-linux-gnu x86_64-unknown-linux"
+ANDROID="armv7-unknown-linux-androideabi aarch64-unknown-linux-android"
+QNX="arm-unknown-nto-qnx-eabi"
+MACOS="i386-apple-darwin x86_64-apple-darwin"
+IOS="armv7-apple-ios arm64-apple-ios i386-apple-ios x86_64-apple-ios"
+
+# targets for which to generate the llvm-targets file
+TARGETS="${WINDOWS_x86} ${LINUX_ARM} ${LINUX_x86} ${ANDROID} ${QNX} ${MACOS} ${IOS}"
+
+# given the call to clang -c11 that clang --target -v generates,
+# parse the -target-cpu <CPU> and -target-feature <feature> from
+# the output.
+function get_cpu_and_attr() {
+ # echo $@
+ while [ "$#" -gt 0 ]; do
+ case "$1" in
+ -target-cpu) CPU=$2; shift 2;;
+ -target-feature) ATTR+=("$2"); shift 2;;
+ *) shift 1;;
+ esac
+ done
+}
+
+# first marker to discrimiate the first line being outputted.
+FST=1
+# a dummy file to use for the clang invocation.
+FILE=_____dummy.c
+touch $FILE
+
+for target in $TARGETS; do
+ # find the cpu and attributes emitte by clang for the given $target
+ CPU=""
+ ATTR=()
+ args=$(clang --target=$target -S $FILE -o /dev/null -v 2>&1 |grep $FILE)
+ get_cpu_and_attr $args
+
+ # find the data-layout from the llvm code emitted by clang.
+ dl=$(clang --target=$target -S $FILE -emit-llvm -o -|grep datalayout |awk -F\ '{ print $4 }')
+ # GNU and Apple/LLVM can't agree on the aarch64 target.
+ # aarch64-apple-ios, is understood by autotools but not by LLVM.
+ # arm64-apple-ios, is understood by LLVM, but not by autotools.
+ #
+ # therefore, while we query clang with arm64-apple-ios, we put
+ # aarch64-apple-ios into the llvm-target list, as that is what
+ # we have to configure ghc with --target with anyway. Also we
+ # want to retain the GNU naming for compatibility with libraries
+ # that use autotools.
+ if [ "$target" == "arm64-apple-ios" ]; then
+ target="aarch64-apple-ios"
+ fi
+ if [ $FST -eq 1 ]; then
+ echo "[(\"${target}\", ($dl, \"$CPU\", \"${ATTR[*]}\"))"
+ FST=0
+ else
+ echo ",(\"${target}\", ($dl, \"$CPU\", \"${ATTR[*]}\"))"
+ fi
+done
+rm $FILE
+echo "]"