summaryrefslogtreecommitdiff
path: root/compiler/GHC/Driver/Config
diff options
context:
space:
mode:
authorSylvain Henry <sylvain@haskus.fr>2021-05-21 16:51:59 +0200
committerSylvain Henry <sylvain@haskus.fr>2021-06-07 10:35:39 +0200
commit4dc681c7c0345ee8ae268749d98b419dabf6a3bc (patch)
treeab05546d61b2d90f2fc9e652a13da48ce89096ae /compiler/GHC/Driver/Config
parent5e1a224435fc6ebd34d02566f17fe1eaf5475bab (diff)
downloadhaskell-4dc681c7c0345ee8ae268749d98b419dabf6a3bc.tar.gz
Make Logger independent of DynFlags
Introduce LogFlags as a independent subset of DynFlags used for logging. As a consequence in many places we don't have to pass both Logger and DynFlags anymore. The main reason for this refactoring is that I want to refactor the systools interfaces: for now many systools functions use DynFlags both to use the Logger and to fetch their parameters (e.g. ldInputs for the linker). I'm interested in refactoring the way they fetch their parameters (i.e. use dedicated XxxOpts data types instead of DynFlags) for #19877. But if I did this refactoring before refactoring the Logger, we would have duplicate parameters (e.g. ldInputs from DynFlags and linkerInputs from LinkerOpts). Hence this patch first. Some flags don't really belong to LogFlags because they are subsystem specific (e.g. most DumpFlags). For example -ddump-asm should better be passed in NCGConfig somehow. This patch doesn't fix this tight coupling: the dump flags are part of the UI but they are passed all the way down for example to infer the file name for the dumps. Because LogFlags are a subset of the DynFlags, we must update the former when the latter changes (not so often). As a consequence we now use accessors to read/write DynFlags in HscEnv instead of using `hsc_dflags` directly. In the process I've also made some subsystems less dependent on DynFlags: - CmmToAsm: by passing some missing flags via NCGConfig (see new fields in GHC.CmmToAsm.Config) - Core.Opt.*: - by passing -dinline-check value into UnfoldingOpts - by fixing some Core passes interfaces (e.g. CallArity, FloatIn) that took DynFlags argument for no good reason. - as a side-effect GHC.Core.Opt.Pipeline.doCorePass is much less convoluted.
Diffstat (limited to 'compiler/GHC/Driver/Config')
-rw-r--r--compiler/GHC/Driver/Config/CmmToAsm.hs70
-rw-r--r--compiler/GHC/Driver/Config/Logger.hs29
-rw-r--r--compiler/GHC/Driver/Config/Parser.hs24
3 files changed, 123 insertions, 0 deletions
diff --git a/compiler/GHC/Driver/Config/CmmToAsm.hs b/compiler/GHC/Driver/Config/CmmToAsm.hs
new file mode 100644
index 0000000000..91be35832a
--- /dev/null
+++ b/compiler/GHC/Driver/Config/CmmToAsm.hs
@@ -0,0 +1,70 @@
+module GHC.Driver.Config.CmmToAsm
+ ( initNCGConfig
+ )
+where
+
+import GHC.Prelude
+
+import GHC.Driver.Session
+
+import GHC.Platform
+import GHC.Unit.Types (Module)
+import GHC.CmmToAsm.Config
+import GHC.Utils.Outputable
+
+-- | Initialize the native code generator configuration from the DynFlags
+initNCGConfig :: DynFlags -> Module -> NCGConfig
+initNCGConfig dflags this_mod = NCGConfig
+ { ncgPlatform = targetPlatform dflags
+ , ncgThisModule = this_mod
+ , ncgAsmContext = initSDocContext dflags (PprCode AsmStyle)
+ , ncgProcAlignment = cmmProcAlignment dflags
+ , ncgExternalDynamicRefs = gopt Opt_ExternalDynamicRefs dflags
+ , ncgPIC = positionIndependent dflags
+ , ncgInlineThresholdMemcpy = fromIntegral $ maxInlineMemcpyInsns dflags
+ , ncgInlineThresholdMemset = fromIntegral $ maxInlineMemsetInsns dflags
+ , ncgSplitSections = gopt Opt_SplitSections dflags
+ , ncgRegsIterative = gopt Opt_RegsIterative dflags
+ , ncgRegsGraph = gopt Opt_RegsGraph dflags
+ , ncgAsmLinting = gopt Opt_DoAsmLinting dflags
+ , ncgCfgWeights = cfgWeights dflags
+ , ncgCfgBlockLayout = gopt Opt_CfgBlocklayout dflags
+ , ncgCfgWeightlessLayout = gopt Opt_WeightlessBlocklayout dflags
+
+ -- With -O1 and greater, the cmmSink pass does constant-folding, so
+ -- we don't need to do it again in the native code generator.
+ , ncgDoConstantFolding = optLevel dflags < 1
+
+ , ncgDumpRegAllocStages = dopt Opt_D_dump_asm_regalloc_stages dflags
+ , ncgDumpAsmStats = dopt Opt_D_dump_asm_stats dflags
+ , ncgDumpAsmConflicts = dopt Opt_D_dump_asm_conflicts dflags
+ , ncgBmiVersion = case platformArch (targetPlatform dflags) of
+ ArchX86_64 -> bmiVersion dflags
+ ArchX86 -> bmiVersion dflags
+ _ -> Nothing
+
+ -- We assume SSE1 and SSE2 operations are available on both
+ -- x86 and x86_64. Historically we didn't default to SSE2 and
+ -- SSE1 on x86, which results in defacto nondeterminism for how
+ -- rounding behaves in the associated x87 floating point instructions
+ -- because variations in the spill/fpu stack placement of arguments for
+ -- operations would change the precision and final result of what
+ -- would otherwise be the same expressions with respect to single or
+ -- double precision IEEE floating point computations.
+ , ncgSseVersion =
+ let v | sseVersion dflags < Just SSE2 = Just SSE2
+ | otherwise = sseVersion dflags
+ in case platformArch (targetPlatform dflags) of
+ ArchX86_64 -> v
+ ArchX86 -> v
+ _ -> Nothing
+
+ , ncgDwarfEnabled = osElfTarget (platformOS (targetPlatform dflags)) && debugLevel dflags > 0 && platformArch (targetPlatform dflags) /= ArchAArch64
+ , ncgDwarfUnwindings = osElfTarget (platformOS (targetPlatform dflags)) && debugLevel dflags > 0
+ , ncgDwarfStripBlockInfo = osElfTarget (platformOS (targetPlatform dflags)) && debugLevel dflags < 2 -- We strip out block information when running with -g0 or -g1.
+ , ncgDwarfSourceNotes = osElfTarget (platformOS (targetPlatform dflags)) && debugLevel dflags > 2 -- We produce GHC-specific source-note DIEs only with -g3
+ , ncgExposeInternalSymbols = gopt Opt_ExposeInternalSymbols dflags
+ , ncgCmmStaticPred = gopt Opt_CmmStaticPred dflags
+ , ncgEnableShortcutting = gopt Opt_AsmShortcutting dflags
+ , ncgComputeUnwinding = debugLevel dflags > 0
+ }
diff --git a/compiler/GHC/Driver/Config/Logger.hs b/compiler/GHC/Driver/Config/Logger.hs
new file mode 100644
index 0000000000..c448a7d58e
--- /dev/null
+++ b/compiler/GHC/Driver/Config/Logger.hs
@@ -0,0 +1,29 @@
+module GHC.Driver.Config.Logger
+ ( initLogFlags
+ )
+where
+
+import GHC.Prelude
+
+import GHC.Driver.Session
+
+import GHC.Utils.Logger (LogFlags (..))
+import GHC.Utils.Outputable
+
+-- | Initialize LogFlags from DynFlags
+initLogFlags :: DynFlags -> LogFlags
+initLogFlags dflags = LogFlags
+ { log_default_user_context = initSDocContext dflags defaultUserStyle
+ , log_default_dump_context = initSDocContext dflags defaultDumpStyle
+ , log_dump_flags = dumpFlags dflags
+ , log_show_caret = gopt Opt_DiagnosticsShowCaret dflags
+ , log_show_warn_groups = gopt Opt_ShowWarnGroups dflags
+ , log_enable_timestamps = not (gopt Opt_SuppressTimestamps dflags)
+ , log_dump_to_file = gopt Opt_DumpToFile dflags
+ , log_dump_dir = dumpDir dflags
+ , log_dump_prefix = dumpPrefix dflags
+ , log_dump_prefix_override = dumpPrefixForce dflags
+ , log_enable_debug = not (hasNoDebugOutput dflags)
+ , log_verbosity = verbosity dflags
+ }
+
diff --git a/compiler/GHC/Driver/Config/Parser.hs b/compiler/GHC/Driver/Config/Parser.hs
new file mode 100644
index 0000000000..bc4c589bf8
--- /dev/null
+++ b/compiler/GHC/Driver/Config/Parser.hs
@@ -0,0 +1,24 @@
+module GHC.Driver.Config.Parser
+ ( initParserOpts
+ )
+where
+
+import GHC.Prelude
+
+import GHC.Driver.Session
+import GHC.Utils.Error
+
+import GHC.Parser.Lexer
+
+-- | Extracts the flags needed for parsing
+initParserOpts :: DynFlags -> ParserOpts
+initParserOpts =
+ mkParserOpts
+ <$> warningFlags
+ <*> extensionFlags
+ <*> mkPlainMsgEnvelope
+ <*> safeImportsOn
+ <*> gopt Opt_Haddock
+ <*> gopt Opt_KeepRawTokenStream
+ <*> const True -- use LINE/COLUMN to update the internal location
+