summaryrefslogtreecommitdiff
path: root/compiler/GHC/Driver/Config
diff options
context:
space:
mode:
authorJohn Ericson <John.Ericson@Obsidian.Systems>2022-02-04 03:00:12 +0000
committerMarge Bot <ben+marge-bot@smart-cactus.org>2022-02-06 01:44:32 -0500
commit37d435d263832ffb2808dad0ccd50110c9f0c430 (patch)
tree0c3d046be6575f184cb4e768e2611b31db4d355a /compiler/GHC/Driver/Config
parent633296bca950f0ef17313f8487d2f5ddd369bc4f (diff)
downloadhaskell-37d435d263832ffb2808dad0ccd50110c9f0c430.tar.gz
Purge DynFlags from GHC.Stg
Also derive some more instances. GHC doesn't need them, but downstream consumers may need to e.g. put stuff in maps.
Diffstat (limited to 'compiler/GHC/Driver/Config')
-rw-r--r--compiler/GHC/Driver/Config/Stg/Debug.hs14
-rw-r--r--compiler/GHC/Driver/Config/Stg/Lift.hs15
-rw-r--r--compiler/GHC/Driver/Config/Stg/Pipeline.hs46
-rw-r--r--compiler/GHC/Driver/Config/Stg/Ppr.hs13
4 files changed, 88 insertions, 0 deletions
diff --git a/compiler/GHC/Driver/Config/Stg/Debug.hs b/compiler/GHC/Driver/Config/Stg/Debug.hs
new file mode 100644
index 0000000000..b680dc148f
--- /dev/null
+++ b/compiler/GHC/Driver/Config/Stg/Debug.hs
@@ -0,0 +1,14 @@
+module GHC.Driver.Config.Stg.Debug
+ ( initStgDebugOpts
+ ) where
+
+import GHC.Stg.Debug
+
+import GHC.Driver.Session
+
+-- | Initialize STG pretty-printing options from DynFlags
+initStgDebugOpts :: DynFlags -> StgDebugOpts
+initStgDebugOpts dflags = StgDebugOpts
+ { stgDebug_infoTableMap = gopt Opt_InfoTableMap dflags
+ , stgDebug_distinctConstructorTables = gopt Opt_DistinctConstructorTables dflags
+ }
diff --git a/compiler/GHC/Driver/Config/Stg/Lift.hs b/compiler/GHC/Driver/Config/Stg/Lift.hs
new file mode 100644
index 0000000000..04155a27d1
--- /dev/null
+++ b/compiler/GHC/Driver/Config/Stg/Lift.hs
@@ -0,0 +1,15 @@
+module GHC.Driver.Config.Stg.Lift
+ ( initStgLiftConfig
+ ) where
+
+import GHC.Stg.Lift.Config
+
+import GHC.Driver.Session
+
+initStgLiftConfig :: DynFlags -> StgLiftConfig
+initStgLiftConfig dflags = StgLiftConfig
+ { c_targetProfile = targetProfile dflags
+ , c_liftLamsRecArgs = liftLamsRecArgs dflags
+ , c_liftLamsNonRecArgs = liftLamsNonRecArgs dflags
+ , c_liftLamsKnown = liftLamsKnown dflags
+ }
diff --git a/compiler/GHC/Driver/Config/Stg/Pipeline.hs b/compiler/GHC/Driver/Config/Stg/Pipeline.hs
new file mode 100644
index 0000000000..5ab9548786
--- /dev/null
+++ b/compiler/GHC/Driver/Config/Stg/Pipeline.hs
@@ -0,0 +1,46 @@
+module GHC.Driver.Config.Stg.Pipeline
+ ( initStgPipelineOpts
+ ) where
+
+import GHC.Prelude
+
+import Control.Monad (guard)
+
+import GHC.Stg.Pipeline
+
+import GHC.Driver.Config.Diagnostic
+import GHC.Driver.Config.Stg.Lift
+import GHC.Driver.Config.Stg.Ppr
+import GHC.Driver.Session
+
+-- | Initialize STG pretty-printing options from DynFlags
+initStgPipelineOpts :: DynFlags -> Bool -> StgPipelineOpts
+initStgPipelineOpts dflags for_bytecode = StgPipelineOpts
+ { stgPipeline_lint = do
+ guard $ gopt Opt_DoStgLinting dflags
+ Just $ initDiagOpts dflags
+ , stgPipeline_pprOpts = initStgPprOpts dflags
+ , stgPipeline_phases = getStgToDo for_bytecode dflags
+ }
+
+-- | Which Stg-to-Stg passes to run. Depends on flags, ways etc.
+getStgToDo
+ :: Bool -- ^ Are we preparing for bytecode?
+ -> DynFlags
+ -> [StgToDo]
+getStgToDo for_bytecode dflags =
+ filter (/= StgDoNothing)
+ [ mandatory StgUnarise
+ -- Important that unarisation comes first
+ -- See Note [StgCse after unarisation] in GHC.Stg.CSE
+ , optional Opt_StgCSE StgCSE
+ , optional Opt_StgLiftLams $ StgLiftLams $ initStgLiftConfig dflags
+ , runWhen for_bytecode StgBcPrep
+ , optional Opt_StgStats StgStats
+ ] where
+ optional opt = runWhen (gopt opt dflags)
+ mandatory = id
+
+runWhen :: Bool -> StgToDo -> StgToDo
+runWhen True todo = todo
+runWhen _ _ = StgDoNothing
diff --git a/compiler/GHC/Driver/Config/Stg/Ppr.hs b/compiler/GHC/Driver/Config/Stg/Ppr.hs
new file mode 100644
index 0000000000..6f044afdf4
--- /dev/null
+++ b/compiler/GHC/Driver/Config/Stg/Ppr.hs
@@ -0,0 +1,13 @@
+module GHC.Driver.Config.Stg.Ppr
+ ( initStgPprOpts
+ ) where
+
+import GHC.Stg.Syntax
+
+import GHC.Driver.Session
+
+-- | Initialize STG pretty-printing options from DynFlags
+initStgPprOpts :: DynFlags -> StgPprOpts
+initStgPprOpts dflags = StgPprOpts
+ { stgSccEnabled = sccProfilingEnabled dflags
+ }