Commit 22733532 authored by Moritz Angermann's avatar Moritz Angermann Committed by Ben Gamari

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
parent 0cd467b2
...@@ -519,6 +519,12 @@ AC_DEFUN([FP_SETTINGS], ...@@ -519,6 +519,12 @@ AC_DEFUN([FP_SETTINGS],
else else
SettingsLibtoolCommand="$LibtoolCmd" SettingsLibtoolCommand="$LibtoolCmd"
fi fi
if test -z "$ClangCmd"
then
SettingsClangCommand="clang"
else
SettingsClangCommand="$ClangCmd"
fi
if test -z "$LlcCmd" if test -z "$LlcCmd"
then then
SettingsLlcCommand="llc" SettingsLlcCommand="llc"
...@@ -549,6 +555,7 @@ AC_DEFUN([FP_SETTINGS], ...@@ -549,6 +555,7 @@ AC_DEFUN([FP_SETTINGS],
AC_SUBST(SettingsWindresCommand) AC_SUBST(SettingsWindresCommand)
AC_SUBST(SettingsLibtoolCommand) AC_SUBST(SettingsLibtoolCommand)
AC_SUBST(SettingsTouchCommand) AC_SUBST(SettingsTouchCommand)
AC_SUBST(SettingsClangCommand)
AC_SUBST(SettingsLlcCommand) AC_SUBST(SettingsLlcCommand)
AC_SUBST(SettingsOptCommand) AC_SUBST(SettingsOptCommand)
]) ])
......
...@@ -72,7 +72,7 @@ llvmCodeGen dflags h us cmm_stream ...@@ -72,7 +72,7 @@ llvmCodeGen dflags h us cmm_stream
llvmCodeGen' :: Stream.Stream LlvmM RawCmmGroup () -> LlvmM () llvmCodeGen' :: Stream.Stream LlvmM RawCmmGroup () -> LlvmM ()
llvmCodeGen' cmm_stream llvmCodeGen' cmm_stream
= do -- Preamble = do -- Preamble
renderLlvm pprLlvmHeader renderLlvm header
ghcInternalFunctions ghcInternalFunctions
cmmMetaLlvmPrelude cmmMetaLlvmPrelude
...@@ -85,6 +85,15 @@ llvmCodeGen' cmm_stream ...@@ -85,6 +85,15 @@ llvmCodeGen' cmm_stream
-- Postamble -- Postamble
cmmUsedLlvmGens cmmUsedLlvmGens
where
header :: SDoc
header = sdocWithDynFlags $ \dflags ->
let target = LLVM_TARGET
layout = case lookup target (llvmTargets dflags) of
Just (LlvmTarget dl _ _) -> dl
Nothing -> error $ "Failed to lookup the datalayout for " ++ target ++ "; available targets: " ++ show (map fst $ llvmTargets dflags)
in text ("target datalayout = \"" ++ layout ++ "\"")
$+$ text ("target triple = \"" ++ target ++ "\"")
llvmGroupLlvmGens :: RawCmmGroup -> LlvmM () llvmGroupLlvmGens :: RawCmmGroup -> LlvmM ()
llvmGroupLlvmGens cmm = do llvmGroupLlvmGens cmm = do
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
-- | Pretty print helpers for the LLVM Code generator. -- | Pretty print helpers for the LLVM Code generator.
-- --
module LlvmCodeGen.Ppr ( module LlvmCodeGen.Ppr (
pprLlvmHeader, pprLlvmCmmDecl, pprLlvmData, infoSection pprLlvmCmmDecl, pprLlvmData, infoSection
) where ) where
#include "HsVersions.h" #include "HsVersions.h"
...@@ -15,7 +15,6 @@ import LlvmCodeGen.Data ...@@ -15,7 +15,6 @@ import LlvmCodeGen.Data
import CLabel import CLabel
import Cmm import Cmm
import Platform
import FastString import FastString
import Outputable import Outputable
...@@ -25,66 +24,6 @@ import Unique ...@@ -25,66 +24,6 @@ import Unique
-- * Top level -- * Top level
-- --
-- | Header code for LLVM modules
pprLlvmHeader :: SDoc
pprLlvmHeader = moduleLayout
-- | LLVM module layout description for the host target
moduleLayout :: SDoc
moduleLayout = sdocWithPlatform $ \platform ->
case platform of
Platform { platformArch = ArchX86, platformOS = OSDarwin } ->
text "target datalayout = \"e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128-n8:16:32\""
$+$ text "target triple = \"i386-apple-darwin9.8\""
Platform { platformArch = ArchX86, platformOS = OSMinGW32 } ->
text "target datalayout = \"e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-f80:128:128-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32\""
$+$ text "target triple = \"i686-pc-win32\""
Platform { platformArch = ArchX86, platformOS = OSLinux } ->
text "target datalayout = \"e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32\""
$+$ text "target triple = \"i386-pc-linux-gnu\""
Platform { platformArch = ArchX86_64, platformOS = OSDarwin } ->
text "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64\""
$+$ text "target triple = \"x86_64-apple-darwin10.0.0\""
Platform { platformArch = ArchX86_64, platformOS = OSLinux } ->
text "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64\""
$+$ text "target triple = \"x86_64-linux-gnu\""
Platform { platformArch = ArchARM {}, platformOS = OSLinux } ->
text "target datalayout = \"e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:64:128-a0:0:64-n32\""
$+$ text "target triple = \"armv6-unknown-linux-gnueabihf\""
Platform { platformArch = ArchARM {}, platformOS = OSAndroid } ->
text "target datalayout = \"e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:64:128-a0:0:64-n32\""
$+$ text "target triple = \"arm-unknown-linux-androideabi\""
Platform { platformArch = ArchARM {}, platformOS = OSQNXNTO } ->
text "target datalayout = \"e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:64:128-a0:0:64-n32\""
$+$ text "target triple = \"arm-unknown-nto-qnx8.0.0eabi\""
Platform { platformArch = ArchARM {}, platformOS = OSiOS } ->
text "target datalayout = \"e-m:o-p:32:32-f64:32:64-v64:32:64-v128:32:128-a:0:32-n32-S32\""
$+$ text "target triple = \"thumbv7-apple-ios7.0.0\""
Platform { platformArch = ArchARM64, platformOS = OSiOS } ->
text "target datalayout = \"e-m:o-i64:64-i128:128-n32:64-S128\""
$+$ text "target triple = \"arm64-apple-ios7.0.0\""
Platform { platformArch = ArchX86, platformOS = OSiOS } ->
text "target datalayout = \"e-m:o-p:32:32-f64:32:64-f80:128-n8:16:32-S128\""
$+$ text "target triple = \"i386-apple-ios7.0.0\""
Platform { platformArch = ArchX86_64, platformOS = OSiOS } ->
text "target datalayout = \"e-m:o-i64:64-f80:128-n8:16:32:64-S128\""
$+$ text "target triple = \"x86_64-apple-ios7.0.0\""
Platform { platformArch = ArchARM64, platformOS = OSLinux } ->
text "target datalayout = \"e-m:e-i64:64-i128:128-n32:64-S128\""
$+$ text "target triple = \"aarch64-unknown-linux-gnu\""
_ ->
if platformIsCrossCompiling platform
then panic "LlvmCodeGen.Ppr: Cross compiling without valid target info."
else empty
-- If you see the above panic, GHC is missing the required target datalayout
-- and triple information. You can obtain this info by compiling a simple
-- 'hello world' C program with the clang C compiler eg:
-- clang -S hello.c -emit-llvm -o -
-- and the first two lines of hello.ll should provide the 'target datalayout'
-- and 'target triple' lines required.
-- | Pretty print LLVM data code -- | Pretty print LLVM data code
pprLlvmData :: LlvmData -> SDoc pprLlvmData :: LlvmData -> SDoc
pprLlvmData (globals, types) = pprLlvmData (globals, types) =
......
This diff is collapsed.
...@@ -76,6 +76,9 @@ module DynFlags ( ...@@ -76,6 +76,9 @@ module DynFlags (
safeDirectImpsReq, safeImplicitImpsReq, safeDirectImpsReq, safeImplicitImpsReq,
unsafeFlags, unsafeFlagsForInfer, unsafeFlags, unsafeFlagsForInfer,
-- ** LLVM Targets
LlvmTarget(..), LlvmTargets,
-- ** System tool settings and locations -- ** System tool settings and locations
Settings(..), Settings(..),
targetPlatform, programName, projectVersion, targetPlatform, programName, projectVersion,
...@@ -83,9 +86,9 @@ module DynFlags ( ...@@ -83,9 +86,9 @@ module DynFlags (
versionedAppDir, versionedAppDir,
extraGccViaCFlags, systemPackageConfig, extraGccViaCFlags, systemPackageConfig,
pgm_L, pgm_P, pgm_F, pgm_c, pgm_s, pgm_a, pgm_l, pgm_dll, pgm_T, pgm_L, pgm_P, pgm_F, pgm_c, pgm_s, pgm_a, pgm_l, pgm_dll, pgm_T,
pgm_windres, pgm_libtool, pgm_lo, pgm_lc, pgm_i, pgm_windres, pgm_libtool, pgm_lo, pgm_lc, pgm_lcc, pgm_i,
opt_L, opt_P, opt_F, opt_c, opt_a, opt_l, opt_i, opt_L, opt_P, opt_F, opt_c, opt_a, opt_l, opt_i,
opt_windres, opt_lo, opt_lc, opt_windres, opt_lo, opt_lc, opt_lcc,
-- ** Manipulating DynFlags -- ** Manipulating DynFlags
...@@ -405,6 +408,7 @@ data GeneralFlag ...@@ -405,6 +408,7 @@ data GeneralFlag
| Opt_DoAsmLinting | Opt_DoAsmLinting
| Opt_DoAnnotationLinting | Opt_DoAnnotationLinting
| Opt_NoLlvmMangler -- hidden flag | Opt_NoLlvmMangler -- hidden flag
| Opt_FastLlvm -- hidden flag
| Opt_WarnIsError -- -Werror; makes warnings fatal | Opt_WarnIsError -- -Werror; makes warnings fatal
| Opt_ShowWarnGroups -- Show the group a warning belongs to | Opt_ShowWarnGroups -- Show the group a warning belongs to
...@@ -700,6 +704,7 @@ data DynFlags = DynFlags { ...@@ -700,6 +704,7 @@ data DynFlags = DynFlags {
ghcLink :: GhcLink, ghcLink :: GhcLink,
hscTarget :: HscTarget, hscTarget :: HscTarget,
settings :: Settings, settings :: Settings,
llvmTargets :: LlvmTargets,
verbosity :: Int, -- ^ Verbosity level: see Note [Verbosity levels] verbosity :: Int, -- ^ Verbosity level: see Note [Verbosity levels]
optLevel :: Int, -- ^ Optimisation level optLevel :: Int, -- ^ Optimisation level
debugLevel :: Int, -- ^ How much debug information to produce debugLevel :: Int, -- ^ How much debug information to produce
...@@ -996,6 +1001,14 @@ data ProfAuto ...@@ -996,6 +1001,14 @@ data ProfAuto
| ProfAutoCalls -- ^ annotate call-sites | ProfAutoCalls -- ^ annotate call-sites
deriving (Eq,Enum) deriving (Eq,Enum)
data LlvmTarget = LlvmTarget
{ lDataLayout :: String
, lCPU :: String
, lAttributes :: [String]
}
type LlvmTargets = [(String, LlvmTarget)]
data Settings = Settings { data Settings = Settings {
sTargetPlatform :: Platform, -- Filled in by SysTools sTargetPlatform :: Platform, -- Filled in by SysTools
sGhcUsagePath :: FilePath, -- Filled in by SysTools sGhcUsagePath :: FilePath, -- Filled in by SysTools
...@@ -1028,6 +1041,7 @@ data Settings = Settings { ...@@ -1028,6 +1041,7 @@ data Settings = Settings {
sPgm_libtool :: String, sPgm_libtool :: String,
sPgm_lo :: (String,[Option]), -- LLVM: opt llvm optimiser sPgm_lo :: (String,[Option]), -- LLVM: opt llvm optimiser
sPgm_lc :: (String,[Option]), -- LLVM: llc static compiler sPgm_lc :: (String,[Option]), -- LLVM: llc static compiler
sPgm_lcc :: (String,[Option]), -- LLVM: c compiler
sPgm_i :: String, sPgm_i :: String,
-- options for particular phases -- options for particular phases
sOpt_L :: [String], sOpt_L :: [String],
...@@ -1039,6 +1053,7 @@ data Settings = Settings { ...@@ -1039,6 +1053,7 @@ data Settings = Settings {
sOpt_windres :: [String], sOpt_windres :: [String],
sOpt_lo :: [String], -- LLVM: llvm optimiser sOpt_lo :: [String], -- LLVM: llvm optimiser
sOpt_lc :: [String], -- LLVM: llc static compiler sOpt_lc :: [String], -- LLVM: llc static compiler
sOpt_lcc :: [String], -- LLVM: c compiler
sOpt_i :: [String], -- iserv options sOpt_i :: [String], -- iserv options
sPlatformConstants :: PlatformConstants sPlatformConstants :: PlatformConstants
...@@ -1086,6 +1101,8 @@ pgm_windres :: DynFlags -> String ...@@ -1086,6 +1101,8 @@ pgm_windres :: DynFlags -> String
pgm_windres dflags = sPgm_windres (settings dflags) pgm_windres dflags = sPgm_windres (settings dflags)
pgm_libtool :: DynFlags -> String pgm_libtool :: DynFlags -> String
pgm_libtool dflags = sPgm_libtool (settings dflags) pgm_libtool dflags = sPgm_libtool (settings dflags)
pgm_lcc :: DynFlags -> (String,[Option])
pgm_lcc dflags = sPgm_lcc (settings dflags)
pgm_lo :: DynFlags -> (String,[Option]) pgm_lo :: DynFlags -> (String,[Option])
pgm_lo dflags = sPgm_lo (settings dflags) pgm_lo dflags = sPgm_lo (settings dflags)
pgm_lc :: DynFlags -> (String,[Option]) pgm_lc :: DynFlags -> (String,[Option])
...@@ -1109,6 +1126,8 @@ opt_l dflags = concatMap (wayOptl (targetPlatform dflags)) (ways dflags) ...@@ -1109,6 +1126,8 @@ opt_l dflags = concatMap (wayOptl (targetPlatform dflags)) (ways dflags)
++ sOpt_l (settings dflags) ++ sOpt_l (settings dflags)
opt_windres :: DynFlags -> [String] opt_windres :: DynFlags -> [String]
opt_windres dflags = sOpt_windres (settings dflags) opt_windres dflags = sOpt_windres (settings dflags)
opt_lcc :: DynFlags -> [String]
opt_lcc dflags = sOpt_lcc (settings dflags)
opt_lo :: DynFlags -> [String] opt_lo :: DynFlags -> [String]
opt_lo dflags = sOpt_lo (settings dflags) opt_lo dflags = sOpt_lo (settings dflags)
opt_lc :: DynFlags -> [String] opt_lc :: DynFlags -> [String]
...@@ -1542,8 +1561,8 @@ initDynFlags dflags = do ...@@ -1542,8 +1561,8 @@ initDynFlags dflags = do
-- | The normal 'DynFlags'. Note that they are not suitable for use in this form -- | The normal 'DynFlags'. Note that they are not suitable for use in this form
-- and must be fully initialized by 'GHC.runGhc' first. -- and must be fully initialized by 'GHC.runGhc' first.
defaultDynFlags :: Settings -> DynFlags defaultDynFlags :: Settings -> LlvmTargets -> DynFlags
defaultDynFlags mySettings = defaultDynFlags mySettings myLlvmTargets =
-- See Note [Updating flag description in the User's Guide] -- See Note [Updating flag description in the User's Guide]
DynFlags { DynFlags {
ghcMode = CompManager, ghcMode = CompManager,
...@@ -1633,6 +1652,8 @@ defaultDynFlags mySettings = ...@@ -1633,6 +1652,8 @@ defaultDynFlags mySettings =
buildTag = mkBuildTag (defaultWays mySettings), buildTag = mkBuildTag (defaultWays mySettings),
splitInfo = Nothing, splitInfo = Nothing,
settings = mySettings, settings = mySettings,
llvmTargets = myLlvmTargets,
-- ghc -M values -- ghc -M values
depMakefile = "Makefile", depMakefile = "Makefile",
depIncludePkgDeps = False, depIncludePkgDeps = False,
...@@ -3058,6 +3079,8 @@ dynamic_flags_deps = [ ...@@ -3058,6 +3079,8 @@ dynamic_flags_deps = [
(NoArg (setGeneralFlag Opt_D_faststring_stats)) (NoArg (setGeneralFlag Opt_D_faststring_stats))
, make_ord_flag defGhcFlag "dno-llvm-mangler" , make_ord_flag defGhcFlag "dno-llvm-mangler"
(NoArg (setGeneralFlag Opt_NoLlvmMangler)) -- hidden flag (NoArg (setGeneralFlag Opt_NoLlvmMangler)) -- hidden flag
, make_ord_flag defGhcFlag "fast-llvm"
(NoArg (setGeneralFlag Opt_FastLlvm)) -- hidden flag
, make_ord_flag defGhcFlag "ddump-debug" , make_ord_flag defGhcFlag "ddump-debug"
(setDumpFlag Opt_D_dump_debug) (setDumpFlag Opt_D_dump_debug)
, make_ord_flag defGhcFlag "ddump-json" , make_ord_flag defGhcFlag "ddump-json"
...@@ -5240,9 +5263,10 @@ makeDynFlagsConsistent dflags ...@@ -5240,9 +5263,10 @@ makeDynFlagsConsistent dflags
-- initialized. -- initialized.
defaultGlobalDynFlags :: DynFlags defaultGlobalDynFlags :: DynFlags
defaultGlobalDynFlags = defaultGlobalDynFlags =
(defaultDynFlags settings) { verbosity = 2 } (defaultDynFlags settings llvmTargets) { verbosity = 2 }
where where
settings = panic "v_unsafeGlobalDynFlags: not initialised" settings = panic "v_unsafeGlobalDynFlags: settings not initialised"
llvmTargets = panic "v_unsafeGlobalDynFlags: llvmTargets not initialised"
#if STAGE < 2 #if STAGE < 2
GLOBAL_VAR(v_unsafeGlobalDynFlags, defaultGlobalDynFlags, DynFlags) GLOBAL_VAR(v_unsafeGlobalDynFlags, defaultGlobalDynFlags, DynFlags)
......
...@@ -493,7 +493,8 @@ initGhcMonad :: GhcMonad m => Maybe FilePath -> m () ...@@ -493,7 +493,8 @@ initGhcMonad :: GhcMonad m => Maybe FilePath -> m ()
initGhcMonad mb_top_dir initGhcMonad mb_top_dir
= do { env <- liftIO $ = do { env <- liftIO $
do { mySettings <- initSysTools mb_top_dir do { mySettings <- initSysTools mb_top_dir
; dflags <- initDynFlags (defaultDynFlags mySettings) ; myLlvmTargets <- initLlvmTargets mb_top_dir
; dflags <- initDynFlags (defaultDynFlags mySettings myLlvmTargets)
; checkBrokenTablesNextToCode dflags ; checkBrokenTablesNextToCode dflags
; setUnsafeGlobalDynFlags dflags ; setUnsafeGlobalDynFlags dflags
-- c.f. DynFlags.parseDynamicFlagsFull, which -- c.f. DynFlags.parseDynamicFlagsFull, which
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
module SysTools ( module SysTools (
-- Initialisation -- Initialisation
initSysTools, initSysTools,
initLlvmTargets,
-- Interface to system tools -- Interface to system tools
runUnlit, runCpp, runCc, -- [Option] -> IO () runUnlit, runCpp, runCc, -- [Option] -> IO ()
...@@ -174,6 +175,20 @@ stuff. ...@@ -174,6 +175,20 @@ stuff.
************************************************************************ ************************************************************************
-} -}
initLlvmTargets :: Maybe String
-> IO LlvmTargets
initLlvmTargets mbMinusB
= do top_dir <- findTopDir mbMinusB
let llvmTargetsFile = top_dir </> "llvm-targets"
llvmTargetsStr <- readFile llvmTargetsFile
case maybeReadFuzzy llvmTargetsStr of
Just s -> return (fmap mkLlvmTarget <$> s)
Nothing -> pgmError ("Can't parse " ++ show llvmTargetsFile)
where
mkLlvmTarget :: (String, String, String) -> LlvmTarget
mkLlvmTarget (dl, cpu, attrs) = LlvmTarget dl cpu (words attrs)
initSysTools :: Maybe String -- Maybe TopDir path (without the '-B' prefix) initSysTools :: Maybe String -- Maybe TopDir path (without the '-B' prefix)
-> IO Settings -- Set all the mutable variables above, holding -> IO Settings -- Set all the mutable variables above, holding
-- (a) the system programs -- (a) the system programs
...@@ -309,6 +324,7 @@ initSysTools mbMinusB ...@@ -309,6 +324,7 @@ initSysTools mbMinusB
-- We just assume on command line -- We just assume on command line
lc_prog <- getSetting "LLVM llc command" lc_prog <- getSetting "LLVM llc command"
lo_prog <- getSetting "LLVM opt command" lo_prog <- getSetting "LLVM opt command"
lcc_prog <- getSetting "LLVM clang command"
let iserv_prog = libexec "ghc-iserv" let iserv_prog = libexec "ghc-iserv"
...@@ -352,6 +368,7 @@ initSysTools mbMinusB ...@@ -352,6 +368,7 @@ initSysTools mbMinusB
sPgm_libtool = libtool_path, sPgm_libtool = libtool_path,
sPgm_lo = (lo_prog,[]), sPgm_lo = (lo_prog,[]),
sPgm_lc = (lc_prog,[]), sPgm_lc = (lc_prog,[]),
sPgm_lcc = (lcc_prog,[]),
sPgm_i = iserv_prog, sPgm_i = iserv_prog,
sOpt_L = [], sOpt_L = [],
sOpt_P = [], sOpt_P = [],
...@@ -360,6 +377,7 @@ initSysTools mbMinusB ...@@ -360,6 +377,7 @@ initSysTools mbMinusB
sOpt_a = [], sOpt_a = [],
sOpt_l = [], sOpt_l = [],
sOpt_windres = [], sOpt_windres = [],
sOpt_lcc = [],
sOpt_lo = [], sOpt_lo = [],
sOpt_lc = [], sOpt_lc = [],
sOpt_i = [], sOpt_i = [],
...@@ -574,8 +592,7 @@ runLlvmLlc dflags args = do ...@@ -574,8 +592,7 @@ runLlvmLlc dflags args = do
-- assembler) -- assembler)
runClang :: DynFlags -> [Option] -> IO () runClang :: DynFlags -> [Option] -> IO ()
runClang dflags args = do runClang dflags args = do
-- we simply assume its available on the PATH let (clang,_) = pgm_lcc dflags
let clang = "clang"
-- be careful what options we call clang with -- be careful what options we call clang with
-- see #5903 and #7617 for bugs caused by this. -- see #5903 and #7617 for bugs caused by this.
(_,args0) = pgm_a dflags (_,args0) = pgm_a dflags
......
...@@ -496,7 +496,7 @@ genRaInsn block_live new_instrs block_id instr r_dying w_dying = do ...@@ -496,7 +496,7 @@ genRaInsn block_live new_instrs block_id instr r_dying w_dying = do
-- debugging -- debugging
{- freeregs <- getFreeRegsR {- freeregs <- getFreeRegsR
assig <- getAssigR assig <- getAssigR
pprDebugAndThen (defaultDynFlags Settings{ sTargetPlatform=platform }) trace "genRaInsn" pprDebugAndThen (defaultDynFlags Settings{ sTargetPlatform=platform } undefined) trace "genRaInsn"
(ppr instr (ppr instr
$$ text "r_dying = " <+> ppr r_dying $$ text "r_dying = " <+> ppr r_dying
$$ text "w_dying = " <+> ppr w_dying $$ text "w_dying = " <+> ppr w_dying
......
...@@ -637,6 +637,12 @@ AC_SUBST([LlvmVersion]) ...@@ -637,6 +637,12 @@ AC_SUBST([LlvmVersion])
sUPPORTED_LLVM_VERSION=$(echo \($LlvmVersion\) | sed 's/\./,/') sUPPORTED_LLVM_VERSION=$(echo \($LlvmVersion\) | sed 's/\./,/')
AC_DEFINE_UNQUOTED([sUPPORTED_LLVM_VERSION], ${sUPPORTED_LLVM_VERSION}, [The supported LLVM version number]) AC_DEFINE_UNQUOTED([sUPPORTED_LLVM_VERSION], ${sUPPORTED_LLVM_VERSION}, [The supported LLVM version number])
dnl ** Which LLVM clang to use?
dnl --------------------------------------------------------------
AC_CHECK_TARGET_TOOL([CLANG], [clang])
ClangCmd="$CLANG"
AC_SUBST([ClangCmd])
dnl ** Which LLVM llc to use? dnl ** Which LLVM llc to use?
dnl -------------------------------------------------------------- dnl --------------------------------------------------------------
FIND_LLVM_PROG([LLC], [llc], [$LlvmVersion]) FIND_LLVM_PROG([LLC], [llc], [$LlvmVersion])
...@@ -1324,6 +1330,7 @@ echo "\ ...@@ -1324,6 +1330,7 @@ echo "\
xelatex : $XELATEX xelatex : $XELATEX
Using LLVM tools Using LLVM tools
clang : $ClangCmd
llc : $LlcCmd llc : $LlcCmd
opt : $OptCmd" opt : $OptCmd"
......
...@@ -1050,6 +1050,7 @@ $(eval $(call bindist-list,.,\ ...@@ -1050,6 +1050,7 @@ $(eval $(call bindist-list,.,\
INSTALL \ INSTALL \
configure config.sub config.guess install-sh \ configure config.sub config.guess install-sh \
settings.in \ settings.in \
llvm-targets \
packages \ packages \
Makefile \ Makefile \
mk/config.mk.in \ mk/config.mk.in \
...@@ -1076,7 +1077,7 @@ $(eval $(call bindist-list,.,\ ...@@ -1076,7 +1077,7 @@ $(eval $(call bindist-list,.,\
$(wildcard compiler/stage2/doc) \ $(wildcard compiler/stage2/doc) \
$(wildcard libraries/*/dist-install/doc/) \ $(wildcard libraries/*/dist-install/doc/) \
$(wildcard libraries/*/*/dist-install/doc/) \ $(wildcard libraries/*/*/dist-install/doc/) \
$(filter-out settings,$(INSTALL_LIBS)) \ $(filter-out settings llvm-targets,$(INSTALL_LIBS)) \
$(RTS_INSTALL_LIBS) \ $(RTS_INSTALL_LIBS) \
$(filter-out %/project.mk mk/config.mk %/mk/install.mk,$(MAKEFILE_LIST)) \ $(filter-out %/project.mk mk/config.mk %/mk/install.mk,$(MAKEFILE_LIST)) \
mk/project.mk \ mk/project.mk \
...@@ -1109,7 +1110,7 @@ BIN_DIST_MK = $(BIN_DIST_PREP_DIR)/bindist.mk ...@@ -1109,7 +1110,7 @@ BIN_DIST_MK = $(BIN_DIST_PREP_DIR)/bindist.mk
unix-binary-dist-prep: unix-binary-dist-prep:
$(call removeTrees,bindistprep/) $(call removeTrees,bindistprep/)
"$(MKDIRHIER)" $(BIN_DIST_PREP_DIR) "$(MKDIRHIER)" $(BIN_DIST_PREP_DIR)
set -e; for i in packages LICENSE compiler ghc iserv rts libraries utils docs libffi includes driver mk rules Makefile aclocal.m4 config.sub config.guess install-sh settings.in ghc.mk inplace distrib/configure.ac distrib/README distrib/INSTALL; do ln -s ../../$$i $(BIN_DIST_PREP_DIR)/; done set -e; for i in packages LICENSE compiler ghc iserv rts libraries utils docs libffi includes driver mk rules Makefile aclocal.m4 config.sub config.guess install-sh settings.in llvm-targets ghc.mk inplace distrib/configure.ac distrib/README distrib/INSTALL; do ln -s ../../$$i $(BIN_DIST_PREP_DIR)/; done
echo "HADDOCK_DOCS = $(HADDOCK_DOCS)" >> $(BIN_DIST_MK) echo "HADDOCK_DOCS = $(HADDOCK_DOCS)" >> $(BIN_DIST_MK)
echo "BUILD_SPHINX_HTML = $(BUILD_SPHINX_HTML)" >> $(BIN_DIST_MK) echo "BUILD_SPHINX_HTML = $(BUILD_SPHINX_HTML)" >> $(BIN_DIST_MK)
echo "BUILD_SPHINX_PDF = $(BUILD_SPHINX_PDF)" >> $(BIN_DIST_MK) echo "BUILD_SPHINX_PDF = $(BUILD_SPHINX_PDF)" >> $(BIN_DIST_MK)
...@@ -1207,7 +1208,7 @@ SRC_DIST_GHC_DIRS = mk rules docs distrib bindisttest libffi includes \ ...@@ -1207,7 +1208,7 @@ SRC_DIST_GHC_DIRS = mk rules docs distrib bindisttest libffi includes \
SRC_DIST_GHC_FILES += \ SRC_DIST_GHC_FILES += \
configure.ac config.guess config.sub configure \ configure.ac config.guess config.sub configure \
aclocal.m4 README.md ANNOUNCE HACKING.md INSTALL.md LICENSE Makefile \ aclocal.m4 README.md ANNOUNCE HACKING.md INSTALL.md LICENSE Makefile \
install-sh settings.in VERSION GIT_COMMIT_ID \ install-sh settings.in llvm-targets VERSION GIT_COMMIT_ID \
boot packages ghc.mk MAKEHELP.md boot packages ghc.mk MAKEHELP.md
.PHONY: VERSION .PHONY: VERSION
......
...@@ -2510,7 +2510,7 @@ showDynFlags show_all dflags = do ...@@ -2510,7 +2510,7 @@ showDynFlags show_all dflags = do
is_on = test f dflags is_on = test f dflags
quiet = not show_all && test f default_dflags == is_on quiet = not show_all && test f default_dflags == is_on
default_dflags = defaultDynFlags (settings dflags) default_dflags = defaultDynFlags (settings dflags) (llvmTargets dflags)
(ghciFlags,others) = partition (\f -> flagSpecFlag f `elem` flgs) (ghciFlags,others) = partition (\f -> flagSpecFlag f `elem` flgs)
DynFlags.fFlags DynFlags.fFlags
...@@ -2921,7 +2921,7 @@ showLanguages' show_all dflags = ...@@ -2921,7 +2921,7 @@ showLanguages' show_all dflags =
quiet = not show_all && test f default_dflags == is_on quiet = not show_all && test f default_dflags == is_on
default_dflags = default_dflags =
defaultDynFlags (settings dflags) `lang_set` defaultDynFlags (settings dflags) (llvmTargets dflags) `lang_set`
case language dflags of case language dflags of
Nothing -> Just Haskell2010 Nothing -> Just Haskell2010
other -> other other -> other
......
...@@ -132,6 +132,9 @@ all_ghc_stage3 : $(GHC_STAGE3) ...@@ -132,6 +132,9 @@ all_ghc_stage3 : $(GHC_STAGE3)
$(INPLACE_LIB)/settings : settings $(INPLACE_LIB)/settings : settings
"$(CP)" $< $@ "$(CP)" $< $@
$(INPLACE_LIB)/llvm-targets : llvm-targets
"$(CP)" $< $@
$(INPLACE_LIB)/platformConstants: $(includes_GHCCONSTANTS_HASKELL_VALUE) $(INPLACE_LIB)/platformConstants: $(includes_GHCCONSTANTS_HASKELL_VALUE)
"$(CP)" $< $@ "$(CP)" $< $@
...@@ -140,6 +143,7 @@ $(INPLACE_LIB)/platformConstants: $(includes_GHCCONSTANTS_HASKELL_VALUE) ...@@ -140,6 +143,7 @@ $(INPLACE_LIB)/platformConstants: $(includes_GHCCONSTANTS_HASKELL_VALUE)
GHC_DEPENDENCIES += $$(unlit_INPLACE) GHC_DEPENDENCIES += $$(unlit_INPLACE)
GHC_DEPENDENCIES += $(INPLACE_LIB)/settings GHC_DEPENDENCIES += $(INPLACE_LIB)/settings
GHC_DEPENDENCIES += $(INPLACE_LIB)/llvm-targets
GHC_DEPENDENCIES += $(INPLACE_LIB)/platformConstants GHC_DEPENDENCIES += $(INPLACE_LIB)/platformConstants
$(GHC_STAGE1) : | $(GHC_DEPENDENCIES) $(GHC_STAGE1) : | $(GHC_DEPENDENCIES)
...@@ -167,6 +171,7 @@ $(GHC_STAGE2) : $(foreach w,$(GhcLibWays),libraries/base/dist-install/build/GHC/ ...@@ -167,6 +171,7 @@ $(GHC_STAGE2) : $(foreach w,$(GhcLibWays),libraries/base/dist-install/build/GHC/
endif endif
INSTALL_LIBS += settings INSTALL_LIBS += settings
INSTALL_LIBS += llvm-targets
ifeq "$(Windows_Host)" "NO" ifeq "$(Windows_Host)" "NO"
install: install_ghc_link install: install_ghc_link
......
[("i386-unknown-windows", ("e-m:x-p:32:32-i64:64-f80:32-n8:16:32-a:0:32-S32", "pentium4", ""))
,("i686-unknown-windows", ("e-m:x-p:32:32-i64:64-f80:32-n8:16:32-a:0:32-S32", "pentium4", ""))
,("x86_64-unknown-windows", ("e-m:w-i64:64-f80:128-n8:16:32:64-S128", "x86-64", ""))
,("arm-unknown-linux-gnueabihf", ("e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64", "arm1176jzf-s", "+strict-align"))
,("armv6-unknown-linux-gnueabihf", ("e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64", "arm1136jf-s", "+strict-align"))
,("armv7-unknown-linux-gnueabihf", ("e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64", "cortex-a8", ""))
,("aarch64-unknown-linux-gnu", ("e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128", "generic", "+neon"))
,("aarch64-unknown-linux", ("e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128", "generic", "+neon"))
,("i386-unknown-linux-gnu", ("e-m:e-p:32:32-f64:32:64-f80:32-n8:16:32-S128", "pentium4", ""))
,("i386-unknown-linux", ("e-m:e-p:32:32-f64:32:64-f80:32-n8:16:32-S128", "pentium4", ""))
,("x86_64-unknown-linux-gnu", ("e-m:e-i64:64-f80:128-n8:16:32:64-S128", "x86-64", ""))
,("x86_64-unknown-linux", ("e-m:e-i64:64-f80:128-n8:16:32:64-S128", "x86-64", ""))
,("armv7-unknown-linux-androideabi", ("e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64", "cortex-a8", "+soft-float-abi"))
,("aarch64-unknown-linux-android", ("e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128", "generic", "+neon"))
,("arm-unknown-nto-qnx-eabi", ("e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64", "arm7tdmi", "+soft-float-abi +strict-align"))
,("i386-apple-darwin", ("e-m:o-p:32:32-f64:32:64-f80:128-n8:16:32-S128", "yonah", ""))
,("x86_64-apple-darwin", ("e-m:o-i64:64-f80:128-n8:16:32:64-S128", "core2", ""))
,("armv7-apple-ios", ("e-m:o-p:32:32-f64:32:64-v64:32:64-v128:32:128-a:0:32-n32-S32", "cortex-a8", "+soft-float-abi"))
,("aarch64-apple-ios", ("e-m:o-i64:64-i128:128-n32:64-S128", "generic", "+neon"))
,("i386-apple-ios", ("e-m:o-p:32:32-f64:32:64-f80:128-n8:16:32-S128", "yonah", ""))
,("x86_64-apple-ios", ("e-m:o-i64:64-f80:128-n8:16:32:64-S128", "core2", ""))
]
...@@ -736,6 +736,7 @@ NM = @NmCmd@ ...@@ -736,6 +736,7 @@ NM = @NmCmd@
AR = @ArCmd@ AR = @ArCmd@
OBJDUMP = @ObjdumpCmd@ OBJDUMP = @ObjdumpCmd@
CLANG = @ClangCmd@
LLC = @LlcCmd@ LLC = @LlcCmd@
OPT = @OptCmd@ OPT = @OptCmd@
......
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
("target has RTS linker", "@HaskellHaveRTSLinker@"), ("target has RTS linker", "@HaskellHaveRTSLinker@"),
("Unregisterised", "@Unregisterised@"), ("Unregisterised", "@Unregisterised@"),
("LLVM llc command", "@SettingsLlcCommand@"), ("LLVM llc command", "@SettingsLlcCommand@"),
("LLVM opt command", "@SettingsOptCommand@") ("LLVM opt command", "@SettingsOptCommand@"),
("LLVM clang command", "@SettingsClangCommand@")
] ]
...@@ -27,6 +27,7 @@ main = do ...@@ -27,6 +27,7 @@ main = do
getGhcFieldOrDefault fields "GhcDynamic" "GHC Dynamic" "NO" getGhcFieldOrDefault fields "GhcDynamic" "GHC Dynamic" "NO"
getGhcFieldOrDefault fields "GhcProfiled" "GHC Profiled" "NO" getGhcFieldOrDefault fields "GhcProfiled" "GHC Profiled" "NO"
getGhcFieldProgWithDefault fields "AR" "ar command" "ar" getGhcFieldProgWithDefault fields "AR" "ar command" "ar"
getGhcFieldProgWithDefault fields "CLANG" "LLVM clang command" "clang"
getGhcFieldProgWithDefault fields "LLC" "LLVM llc command" "llc" getGhcFieldProgWithDefault fields "LLC" "LLVM llc command" "llc"
getGhcFieldProgWithDefault fields "TEST_CC" "C compiler command" "gcc" getGhcFieldProgWithDefault fields "TEST_CC" "C compiler command" "gcc"
......
...@@ -657,7 +657,7 @@ test('T5837', ...@@ -657,7 +657,7 @@ test('T5837',
# 2017-02-19 59161648 (x64/Windows) - Unknown # 2017-02-19 59161648 (x64/Windows) - Unknown
# 2017-04-21 54985248 (x64/Windows) - Unknown # 2017-04-21 54985248 (x64/Windows) - Unknown
(wordsize(64), 52625920, 7)]) (wordsize(64), 56782344, 7)])
# sample: 3926235424 (amd64/Linux, 15/2/2012) # sample: 3926235424 (amd64/Linux, 15/2/2012)
# 2012-10-02 81879216 # 2012-10-02 81879216
# 2012-09-20 87254264 amd64/Linux # 2012-09-20 87254264 amd64/Linux
...@@ -693,6 +693,7 @@ test('T5837', ...@@ -693,6 +693,7 @@ test('T5837',
# 2017-02-20 58648600 amd64/Linux Type-indexed Typeable # 2017-02-20 58648600 amd64/Linux Type-indexed Typeable
# 2017-02-28 54151864 amd64/Linux Likely drift due to recent simplifier improvements # 2017-02-28 54151864 amd64/Linux Likely drift due to recent simplifier improvements
# 2017-02-25 52625920 amd64/Linux Early inlining patch # 2017-02-25 52625920 amd64/Linux Early inlining patch
# 2017-09-06 56782344 amd64/Linux Drift manifest in unrelated LLVM patch
], ],
compile, ['-freduction-depth=50']) compile, ['-freduction-depth=50'])
...@@ -1019,13 +1020,14 @@ test('T12227', ...@@ -1019,13 +1020,14 @@ test('T12227',
test('T12425', test('T12425',
[ only_ways(['optasm']), [ only_ways(['optasm']),
compiler_stats_num_field('bytes allocated', compiler_stats_num_field('bytes allocated',
[(wordsize(64), 127500136, 5), [(wordsize(64), 134780272, 5),
# initial: 125831400 # initial: 125831400
# 2017-01-18: 133380960 Allow top-level string literals in Core # 2017-01-18: 133380960 Allow top-level string literals in Core