summaryrefslogtreecommitdiff
path: root/compiler/llvmGen/LlvmCodeGen.hs
diff options
context:
space:
mode:
authorBen Gamari <ben@smart-cactus.org>2019-07-29 19:34:57 -0400
committerBen Gamari <ben@smart-cactus.org>2019-10-06 17:38:32 -0400
commit3da872c3d250b47dd4ce00f96bea5936601571fd (patch)
treef5df7cabd02fa688aad6e50bbf7763a151cf0ac9 /compiler/llvmGen/LlvmCodeGen.hs
parent8039b6257ce5288e9e38c2593ff2d5d6d316efd4 (diff)
downloadhaskell-wip/llvm-config.tar.gz
Refactor, document, and optimize LLVM configuration loadingwip/llvm-config
As described in the new Note [LLVM Configuration] in SysTools, we now load llvm-targets and llvm-passes lazily to avoid the overhead of doing so when -fllvm isn't used (also known as "the common case"). Noticed in #17003. Metric Decrease: T12234 T12150
Diffstat (limited to 'compiler/llvmGen/LlvmCodeGen.hs')
-rw-r--r--compiler/llvmGen/LlvmCodeGen.hs14
1 files changed, 10 insertions, 4 deletions
diff --git a/compiler/llvmGen/LlvmCodeGen.hs b/compiler/llvmGen/LlvmCodeGen.hs
index cc86c4254e..b566b99a1f 100644
--- a/compiler/llvmGen/LlvmCodeGen.hs
+++ b/compiler/llvmGen/LlvmCodeGen.hs
@@ -94,12 +94,18 @@ llvmCodeGen' cmm_stream
header :: SDoc
header = sdocWithDynFlags $ \dflags ->
let target = platformMisc_llvmTarget $ platformMisc dflags
- 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 ++ "\"")
+ in text ("target datalayout = \"" ++ getDataLayout dflags target ++ "\"")
$+$ text ("target triple = \"" ++ target ++ "\"")
+ getDataLayout :: DynFlags -> String -> String
+ getDataLayout dflags target =
+ case lookup target (llvmTargets $ llvmConfig dflags) of
+ Just (LlvmTarget {lDataLayout=dl}) -> dl
+ Nothing -> pprPanic "Failed to lookup LLVM data layout" $
+ text "Target:" <+> text target $$
+ hang (text "Available targets:") 4
+ (vcat $ map (text . fst) $ llvmTargets $ llvmConfig dflags)
+
llvmGroupLlvmGens :: RawCmmGroup -> LlvmM ()
llvmGroupLlvmGens cmm = do