Commit 50eb4460 authored by Sylvain Henry's avatar Sylvain Henry Committed by Marge Bot
Browse files

Don't use DynFlags in CmmToAsm.BlockLayout (#17957)

parent 293c7fba
......@@ -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.
......
......@@ -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
......
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment