diff options
author | Sylvain Henry <sylvain@haskus.fr> | 2020-08-12 16:26:03 +0200 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2020-08-21 09:36:38 -0400 |
commit | 50eb4460cd8412387e0c3755a9e0bafaced12bb2 (patch) | |
tree | 4d9904ba5fc8f4ad87c456d3978c5653e2a751e6 | |
parent | 293c7fba6cde31151baaf2a92c723605ed458ade (diff) | |
download | haskell-50eb4460cd8412387e0c3755a9e0bafaced12bb2.tar.gz |
Don't use DynFlags in CmmToAsm.BlockLayout (#17957)
-rw-r--r-- | compiler/GHC/CmmToAsm.hs | 3 | ||||
-rw-r--r-- | compiler/GHC/CmmToAsm/BlockLayout.hs | 45 | ||||
-rw-r--r-- | compiler/GHC/CmmToAsm/Config.hs | 2 |
3 files changed, 28 insertions, 22 deletions
diff --git a/compiler/GHC/CmmToAsm.hs b/compiler/GHC/CmmToAsm.hs index c2b32574ba..677c7bdcbf 100644 --- a/compiler/GHC/CmmToAsm.hs +++ b/compiler/GHC/CmmToAsm.hs @@ -644,7 +644,6 @@ cmmNativeGen dflags this_mod modLoc ncgImpl us fileIds dbgMap cmm count checkLayout shorted $ {-# SCC "sequenceBlocks" #-} map (BlockLayout.sequenceTop - dflags ncgImpl optimizedCFG) shorted @@ -1151,6 +1150,8 @@ initNCGConfig dflags = NCGConfig , ncgRegsIterative = gopt Opt_RegsIterative 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. diff --git a/compiler/GHC/CmmToAsm/BlockLayout.hs b/compiler/GHC/CmmToAsm/BlockLayout.hs index 21b6865699..2e05d2dfa9 100644 --- a/compiler/GHC/CmmToAsm/BlockLayout.hs +++ b/compiler/GHC/CmmToAsm/BlockLayout.hs @@ -8,6 +8,7 @@ {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE GeneralizedNewtypeDeriving #-} {-# LANGUAGE FlexibleContexts #-} +{-# LANGUAGE MultiWayIf #-} module GHC.CmmToAsm.BlockLayout ( sequenceTop, backendMaintainsCfg) @@ -16,13 +17,13 @@ where #include "HsVersions.h" import GHC.Prelude -import GHC.Driver.Session (gopt, GeneralFlag(..), DynFlags, targetPlatform) import GHC.Driver.Ppr (pprTrace) import GHC.CmmToAsm.Instr import GHC.CmmToAsm.Monad import GHC.CmmToAsm.CFG import GHC.CmmToAsm.Types +import GHC.CmmToAsm.Config import GHC.Cmm.BlockId import GHC.Cmm @@ -817,30 +818,32 @@ dropJumps info ((BasicBlock lbl ins):todo) sequenceTop :: Instruction instr - => DynFlags -- Determine which layout algo to use - -> NcgImpl statics instr jumpDest + => NcgImpl statics instr jumpDest -> Maybe CFG -- ^ CFG if we have one. -> NatCmmDecl statics instr -- ^ Function to serialize -> NatCmmDecl statics instr -sequenceTop _ _ _ top@(CmmData _ _) = top -sequenceTop dflags ncgImpl edgeWeights - (CmmProc info lbl live (ListGraph blocks)) - | (gopt Opt_CfgBlocklayout dflags) && backendMaintainsCfg (targetPlatform dflags) - --Use chain based algorithm - , Just cfg <- edgeWeights - = CmmProc info lbl live ( ListGraph $ ncgMakeFarBranches ncgImpl info $ - {-# SCC layoutBlocks #-} - sequenceChain info cfg blocks ) - | otherwise - --Use old algorithm - = let cfg = if dontUseCfg then Nothing else edgeWeights - in CmmProc info lbl live ( ListGraph $ ncgMakeFarBranches ncgImpl info $ - {-# SCC layoutBlocks #-} - sequenceBlocks cfg info blocks) - where - dontUseCfg = gopt Opt_WeightlessBlocklayout dflags || - (not $ backendMaintainsCfg (targetPlatform dflags)) +sequenceTop _ _ top@(CmmData _ _) = top +sequenceTop ncgImpl edgeWeights (CmmProc info lbl live (ListGraph blocks)) + = let + config = ncgConfig ncgImpl + platform = ncgPlatform config + + in CmmProc info lbl live $ ListGraph $ ncgMakeFarBranches ncgImpl info $ + if -- Chain based algorithm + | ncgCfgBlockLayout config + , backendMaintainsCfg platform + , Just cfg <- edgeWeights + -> {-# SCC layoutBlocks #-} sequenceChain info cfg blocks + + -- Old algorithm without edge weights + | ncgCfgWeightlessLayout config + || not (backendMaintainsCfg platform) + -> {-# SCC layoutBlocks #-} sequenceBlocks Nothing info blocks + + -- Old algorithm with edge weights (if any) + | otherwise + -> {-# SCC layoutBlocks #-} sequenceBlocks edgeWeights info blocks -- The old algorithm: -- It is very simple (and stupid): We make a graph out of diff --git a/compiler/GHC/CmmToAsm/Config.hs b/compiler/GHC/CmmToAsm/Config.hs index 88cff6a3eb..29d8bcad15 100644 --- a/compiler/GHC/CmmToAsm/Config.hs +++ b/compiler/GHC/CmmToAsm/Config.hs @@ -31,6 +31,8 @@ data NCGConfig = NCGConfig , ncgDumpAsmStats :: !Bool , ncgDumpAsmConflicts :: !Bool , ncgCfgWeights :: !Weights -- ^ CFG edge weights + , ncgCfgBlockLayout :: !Bool -- ^ Use CFG based block layout algorithm + , ncgCfgWeightlessLayout :: !Bool -- ^ Layout based on last instruction per block. } -- | Return Word size |