diff options
author | Sylvain Henry <sylvain@haskus.fr> | 2021-05-21 16:51:59 +0200 |
---|---|---|
committer | Sylvain Henry <sylvain@haskus.fr> | 2021-06-07 10:35:39 +0200 |
commit | 4dc681c7c0345ee8ae268749d98b419dabf6a3bc (patch) | |
tree | ab05546d61b2d90f2fc9e652a13da48ce89096ae /testsuite/tests/regalloc | |
parent | 5e1a224435fc6ebd34d02566f17fe1eaf5475bab (diff) | |
download | haskell-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 'testsuite/tests/regalloc')
-rw-r--r-- | testsuite/tests/regalloc/regalloc_unit_tests.hs | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/testsuite/tests/regalloc/regalloc_unit_tests.hs b/testsuite/tests/regalloc/regalloc_unit_tests.hs index f68cd040df..419a723062 100644 --- a/testsuite/tests/regalloc/regalloc_unit_tests.hs +++ b/testsuite/tests/regalloc/regalloc_unit_tests.hs @@ -24,6 +24,7 @@ import qualified GHC.CmmToAsm.Reg.Graph.Stats as Color import qualified GHC.CmmToAsm.Reg.Linear.Base as Linear import qualified GHC.CmmToAsm.X86.Instr as X86.Instr import qualified GHC.CmmToAsm.X86 as X86 +import GHC.Driver.Config.CmmToAsm import GHC.Driver.Main import GHC.Driver.Env import GHC.StgToCmm.CgUtils @@ -44,6 +45,7 @@ import GHC.Types.Unique.Supply import GHC.Driver.Session import GHC.Driver.Errors import GHC.Utils.Error +import GHC.Utils.Logger import GHC.Utils.Outputable import GHC.Types.Basic import GHC.Unit.Home @@ -64,8 +66,15 @@ main = do --get a GHC context and run the tests runGhc (Just libdir) $ do - dflags0 <- fmap setOptions getDynFlags - setSessionDynFlags dflags0 + dflags0 <- flip gopt_set Opt_RegsGraph <$> getDynFlags + --the register allocator's intermediate data + --structures are usually discarded + --(in GHC.CmmToAsm.cmmNativeGen) for performance + --reasons. To prevent this we need to tell + --cmmNativeGen we want them printed out even + --though we ignore stderr in the test configuration. + let dflags1 = dopt_set dflags0 Opt_D_dump_asm_stats + setSessionDynFlags dflags1 dflags <- getDynFlags logger <- getLogger @@ -75,8 +84,6 @@ main = do return () - where setOptions = (flip gopt_set) Opt_RegsGraph - -- | TODO: Make this an IORef along the lines of Data.Unique.newUnique to add -- stronger guarantees a UniqSupply won't be accidentally reused @@ -113,7 +120,7 @@ compileCmmForRegAllocStats :: UniqSupply -> IO [( Maybe [Color.RegAllocStats (Alignment, RawCmmStatics) X86.Instr.Instr] , Maybe [Linear.RegAllocStats])] -compileCmmForRegAllocStats logger dflags' cmmFile ncgImplF us = do +compileCmmForRegAllocStats logger dflags cmmFile ncgImplF us = do let ncgImpl = ncgImplF (initNCGConfig dflags thisMod) hscEnv <- newHscEnv dflags @@ -127,13 +134,14 @@ compileCmmForRegAllocStats logger dflags' cmmFile ncgImplF us = do let initTopSRT = emptySRT thisMod cmmGroup <- fmap snd $ cmmPipeline hscEnv initTopSRT $ fst $ fromJust parsedCmm - rawCmms <- cmmToRawCmm logger dflags (Stream.yield cmmGroup) + let profile = targetProfile dflags + rawCmms <- cmmToRawCmm logger profile (Stream.yield cmmGroup) collectedCmms <- mconcat <$> Stream.collect rawCmms -- compile and discard the generated code, returning regalloc stats mapM (\ (count, thisCmm) -> - cmmNativeGen logger dflags thisModLoc ncgImpl + cmmNativeGen logger thisModLoc ncgImpl usb dwarfFileIds dbgMap thisCmm count >>= (\(_, _, _, _, colorStats, linearStats, _) -> -- scrub unneeded output from cmmNativeGen @@ -141,13 +149,6 @@ compileCmmForRegAllocStats logger dflags' cmmFile ncgImplF us = do $ zip [0.. (length collectedCmms)] collectedCmms where - --the register allocator's intermediate data - --structures are usually discarded - --(in AsmCodeGen.cmmNativeGen) for performance - --reasons. To prevent this we need to tell - --cmmNativeGen we want them printed out even - --though we ignore stderr in the test configuration. - dflags = dopt_set dflags' Opt_D_dump_asm_stats [usa, usb, usc, usd] = take 4 . listSplitUniqSupply $ us -- don't need debugging information dwarfFileIds = emptyUFM |