summaryrefslogtreecommitdiff
path: root/compiler/main/DynFlags.hs
diff options
context:
space:
mode:
authorBen Gamari <ben@smart-cactus.org>2019-07-29 19:34:57 -0400
committerMarge Bot <ben+marge-bot@smart-cactus.org>2019-10-07 12:01:46 -0400
commitb2577081528fe36facf5153bed256fe838a74ae6 (patch)
treec0ce42d462656bc3dae6543c5239a8e56a5e2217 /compiler/main/DynFlags.hs
parent825c108bd26f20accf1eaef2ba652a2ee12924bb (diff)
downloadhaskell-b2577081528fe36facf5153bed256fe838a74ae6.tar.gz
Refactor, document, and optimize LLVM configuration loading
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/main/DynFlags.hs')
-rw-r--r--compiler/main/DynFlags.hs25
1 files changed, 13 insertions, 12 deletions
diff --git a/compiler/main/DynFlags.hs b/compiler/main/DynFlags.hs
index 465dd2737b..146020887b 100644
--- a/compiler/main/DynFlags.hs
+++ b/compiler/main/DynFlags.hs
@@ -83,7 +83,7 @@ module DynFlags (
unsafeFlags, unsafeFlagsForInfer,
-- ** LLVM Targets
- LlvmTarget(..), LlvmTargets, LlvmPasses, LlvmConfig,
+ LlvmTarget(..), LlvmConfig(..),
-- ** System tool settings and locations
Settings(..),
@@ -970,8 +970,9 @@ data DynFlags = DynFlags {
integerLibrary :: IntegerLibrary,
-- ^ IntegerGMP or IntegerSimple. Set at configure time, but may be overriden
-- by GHC-API users. See Note [The integer library] in PrelNames
- llvmTargets :: LlvmTargets,
- llvmPasses :: LlvmPasses,
+ llvmConfig :: LlvmConfig,
+ -- ^ N.B. It's important that this field is lazy since we load the LLVM
+ -- configuration lazily. See Note [LLVM Configuration] in SysTools.
verbosity :: Int, -- ^ Verbosity level: see Note [Verbosity levels]
optLevel :: Int, -- ^ Optimisation level
debugLevel :: Int, -- ^ How much debug information to produce
@@ -1391,9 +1392,10 @@ data LlvmTarget = LlvmTarget
, lAttributes :: [String]
}
-type LlvmTargets = [(String, LlvmTarget)]
-type LlvmPasses = [(Int, String)]
-type LlvmConfig = (LlvmTargets, LlvmPasses)
+-- | See Note [LLVM Configuration] in SysTools.
+data LlvmConfig = LlvmConfig { llvmTargets :: [(String, LlvmTarget)]
+ , llvmPasses :: [(Int, String)]
+ }
-----------------------------------------------------------------------------
-- Accessessors from 'DynFlags'
@@ -1924,7 +1926,7 @@ initDynFlags dflags = do
-- | The normal 'DynFlags'. Note that they are not suitable for use in this form
-- and must be fully initialized by 'GHC.runGhc' first.
defaultDynFlags :: Settings -> LlvmConfig -> DynFlags
-defaultDynFlags mySettings (myLlvmTargets, myLlvmPasses) =
+defaultDynFlags mySettings llvmConfig =
-- See Note [Updating flag description in the User's Guide]
DynFlags {
ghcMode = CompManager,
@@ -2035,8 +2037,8 @@ defaultDynFlags mySettings (myLlvmTargets, myLlvmPasses) =
platformConstants = sPlatformConstants mySettings,
rawSettings = sRawSettings mySettings,
- llvmTargets = myLlvmTargets,
- llvmPasses = myLlvmPasses,
+ -- See Note [LLVM configuration].
+ llvmConfig = llvmConfig,
-- ghc -M values
depMakefile = "Makefile",
@@ -5731,11 +5733,10 @@ makeDynFlagsConsistent dflags
-- initialized.
defaultGlobalDynFlags :: DynFlags
defaultGlobalDynFlags =
- (defaultDynFlags settings (llvmTargets, llvmPasses)) { verbosity = 2 }
+ (defaultDynFlags settings llvmConfig) { verbosity = 2 }
where
settings = panic "v_unsafeGlobalDynFlags: settings not initialised"
- llvmTargets = panic "v_unsafeGlobalDynFlags: llvmTargets not initialised"
- llvmPasses = panic "v_unsafeGlobalDynFlags: llvmPasses not initialised"
+ llvmConfig = panic "v_unsafeGlobalDynFlags: llvmConfig not initialised"
#if STAGE < 2
GLOBAL_VAR(v_unsafeGlobalDynFlags, defaultGlobalDynFlags, DynFlags)