diff options
author | Sylvain Henry <sylvain@haskus.fr> | 2020-08-12 15:36:52 +0200 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2020-08-21 09:36:38 -0400 |
commit | 293c7fba6cde31151baaf2a92c723605ed458ade (patch) | |
tree | f1ceb825c27bd10a8fc6c0becd9cfa346b421afb /compiler/GHC/Driver | |
parent | eb9bdaef6024558696e1e50b12d7fefb70483a9f (diff) | |
download | haskell-293c7fba6cde31151baaf2a92c723605ed458ade.tar.gz |
Put CFG weights into their own module (#17957)
It avoids having to query DynFlags to get them
Diffstat (limited to 'compiler/GHC/Driver')
-rw-r--r-- | compiler/GHC/Driver/Session.hs | 81 |
1 files changed, 5 insertions, 76 deletions
diff --git a/compiler/GHC/Driver/Session.hs b/compiler/GHC/Driver/Session.hs index fea01278ef..40ccb400bc 100644 --- a/compiler/GHC/Driver/Session.hs +++ b/compiler/GHC/Driver/Session.hs @@ -226,9 +226,6 @@ module GHC.Driver.Session ( -- * SDoc initSDocContext, initDefaultSDocContext, - - -- * Make use of the Cmm CFG - CfgWeights(..) ) where #include "HsVersions.h" @@ -268,6 +265,7 @@ import GHC.Data.FastString import GHC.Utils.Fingerprint import GHC.Utils.Outputable import GHC.Settings +import GHC.CmmToAsm.CFG.Weight import {-# SOURCE #-} GHC.Utils.Error ( Severity(..), MsgDoc, mkLocMessageAnn @@ -777,78 +775,9 @@ data DynFlags = DynFlags { uniqueIncrement :: Int, -- | Temporary: CFG Edge weights for fast iterations - cfgWeightInfo :: CfgWeights + cfgWeights :: Weights } --- | Edge weights to use when generating a CFG from CMM -data CfgWeights - = CFGWeights - { uncondWeight :: Int - , condBranchWeight :: Int - , switchWeight :: Int - , callWeight :: Int - , likelyCondWeight :: Int - , unlikelyCondWeight :: Int - , infoTablePenalty :: Int - , backEdgeBonus :: Int - } - -defaultCfgWeights :: CfgWeights -defaultCfgWeights - = CFGWeights - { uncondWeight = 1000 - , condBranchWeight = 800 - , switchWeight = 1 - , callWeight = -10 - , likelyCondWeight = 900 - , unlikelyCondWeight = 300 - , infoTablePenalty = 300 - , backEdgeBonus = 400 - } - -parseCfgWeights :: String -> CfgWeights -> CfgWeights -parseCfgWeights s oldWeights = - foldl' (\cfg (n,v) -> update n v cfg) oldWeights assignments - where - assignments = map assignment $ settings s - update "uncondWeight" n w = - w {uncondWeight = n} - update "condBranchWeight" n w = - w {condBranchWeight = n} - update "switchWeight" n w = - w {switchWeight = n} - update "callWeight" n w = - w {callWeight = n} - update "likelyCondWeight" n w = - w {likelyCondWeight = n} - update "unlikelyCondWeight" n w = - w {unlikelyCondWeight = n} - update "infoTablePenalty" n w = - w {infoTablePenalty = n} - update "backEdgeBonus" n w = - w {backEdgeBonus = n} - update other _ _ - = panic $ other ++ - " is not a cfg weight parameter. " ++ - exampleString - settings s - | (s1,rest) <- break (== ',') s - , null rest - = [s1] - | (s1,rest) <- break (== ',') s - = s1 : settings (drop 1 rest) - - assignment as - | (name, _:val) <- break (== '=') as - = (name,read val) - | otherwise - = panic $ "Invalid cfg parameters." ++ exampleString - - exampleString = "Example parameters: uncondWeight=1000," ++ - "condBranchWeight=800,switchWeight=0,callWeight=300" ++ - ",likelyCondWeight=900,unlikelyCondWeight=300" ++ - ",infoTablePenalty=300,backEdgeBonus=400" - class HasDynFlags m where getDynFlags :: m DynFlags @@ -1430,7 +1359,7 @@ defaultDynFlags mySettings llvmConfig = reverseErrors = False, maxErrors = Nothing, - cfgWeightInfo = defaultCfgWeights + cfgWeights = defaultWeights } defaultWays :: Settings -> Ways @@ -2949,8 +2878,8 @@ dynamic_flags_deps = [ (intSuffix (\n d -> d { cmmProcAlignment = Just n })) , make_ord_flag defFlag "fblock-layout-weights" (HasArg (\s -> - upd (\d -> d { cfgWeightInfo = - parseCfgWeights s (cfgWeightInfo d)}))) + upd (\d -> d { cfgWeights = + parseWeights s (cfgWeights d)}))) , make_ord_flag defFlag "fhistory-size" (intSuffix (\n d -> d { historySize = n })) , make_ord_flag defFlag "funfolding-creation-threshold" |