Skip to content

Commit b7fc7be

Browse files
committed
Add additional stage1 module exclusion flags
Add new flags to further reduce stage1 compilation: - -llvm-backend: Exclude LLVM codegen (~17 modules, ~4200 lines). Guard LlvmConfigCache, CodeOutput, Pipeline/Execute LLVM phases. Move CmmToLlvm.Version modules to unconditional section (needed by GHC.Driver.Errors.Ppr and GHC.SysTools). - +host-ncg-only: Restrict NCG to host architecture using Cabal's arch() condition. Saves 8-10 modules per platform. - -hpc: Gate GHC.HsToCore.Coverage behind conditional. Stub out writeMixEntries and hpcInitCode when disabled (~540 lines). - Move GHC.Stg.BcPrep behind interpreter flag (~200 lines). Restore debug RTS default for ghc-bin (accidentally changed when adding -frontend-plugins flag).
1 parent c468457 commit b7fc7be

10 files changed

Lines changed: 122 additions & 28 deletions

File tree

cabal.project.stage1

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,11 @@ package ghc
7575
flags: +bootstrap
7676
+x86-ncg +aarch64-ncg
7777
-ppc-ncg -riscv64-ncg -loongarch64-ncg
78+
+host-ncg-only
7879
-js-backend -wasm-backend
79-
+llvm-backend
80+
-llvm-backend
8081
-interpreter -dynamic-linker
82+
-hpc
8183

8284
package ghc-bin
8385
flags: -frontend-plugins

compiler/GHC/Driver/CodeOutput.hs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
\section{Code output phase}
55
-}
66

7+
{-# LANGUAGE CPP #-}
78
{-# LANGUAGE ScopedTypeVariables #-}
89

910
module GHC.Driver.CodeOutput
@@ -20,7 +21,9 @@ import GHC.ForeignSrcLang
2021
import GHC.Data.FastString
2122

2223
import GHC.CmmToAsm ( nativeCodeGen )
24+
#if defined(HAVE_LLVM_BACKEND)
2325
import GHC.CmmToLlvm ( llvmCodeGen )
26+
#endif
2427

2528
import GHC.CmmToC ( cmmToC )
2629
import GHC.Cmm.Lint ( cmmLint )
@@ -32,7 +35,9 @@ import GHC.StgToCmm.CgUtils (CgStream)
3235
import GHC.Driver.DynFlags
3336
import GHC.Driver.Config.Finder ( initFinderOpts )
3437
import GHC.Driver.Config.CmmToAsm ( initNCGConfig )
38+
#if defined(HAVE_LLVM_BACKEND)
3539
import GHC.Driver.Config.CmmToLlvm ( initLlvmCgConfig )
40+
#endif
3641
import GHC.Driver.LlvmConfigCache (LlvmConfigCache)
3742
import GHC.Driver.Ppr
3843
import GHC.Driver.Backend
@@ -50,7 +55,7 @@ import GHC.Utils.Outputable
5055
import GHC.Utils.Logger
5156
import GHC.Utils.Exception ( bracket )
5257
import GHC.Utils.Ppr (Mode(..))
53-
import GHC.Utils.Panic.Plain ( pgmError )
58+
import GHC.Utils.Panic.Plain ( pgmError, panic )
5459

5560
import GHC.Unit
5661
import GHC.Unit.Finder ( mkStubPaths )
@@ -131,8 +136,16 @@ codeOutput logger tmpfs llvm_config dflags unit_state this_mod filenm location g
131136
NcgCodeOutput -> outputAsm logger dflags this_mod location filenm dus1
132137
final_stream
133138
ViaCCodeOutput -> outputC logger dflags filenm dus1 final_stream pkg_deps
139+
#if defined(HAVE_LLVM_BACKEND)
134140
LlvmCodeOutput -> outputLlvm logger llvm_config dflags filenm dus1 final_stream
141+
#else
142+
LlvmCodeOutput -> panic "codeOutput: LLVM backend not available (HAVE_LLVM_BACKEND not defined)"
143+
#endif
144+
#if defined(HAVE_JS_BACKEND)
135145
JSCodeOutput -> outputJS logger llvm_config dflags filenm final_stream
146+
#else
147+
JSCodeOutput -> panic "codeOutput: JS backend not available (HAVE_JS_BACKEND not defined)"
148+
#endif
136149
; stubs_exist <- outputForeignStubs logger tmpfs dflags unit_state this_mod location stubs
137150
; return (filenm, stubs_exist, foreign_fps, a)
138151
}
@@ -216,6 +229,7 @@ outputAsm logger dflags this_mod location filenm dus cmm_stream = do
216229
runUDSMT dus $ setTagUDSMT 'n' $
217230
nativeCodeGen logger (toolSettings dflags) ncg_config location h cmm_stream
218231

232+
#if defined(HAVE_LLVM_BACKEND)
219233
{-
220234
************************************************************************
221235
* *
@@ -233,7 +247,9 @@ outputLlvm logger llvm_config dflags filenm dus cmm_stream = do
233247
{-# SCC "llvm_output" #-} doOutput filenm $
234248
\f -> {-# SCC "llvm_CodeGen" #-}
235249
llvmCodeGen logger lcg_config f dus cmm_stream
250+
#endif
236251

252+
#if defined(HAVE_JS_BACKEND)
237253
{-
238254
************************************************************************
239255
* *
@@ -245,6 +261,7 @@ outputJS :: Logger -> LlvmConfigCache -> DynFlags -> FilePath -> CgStream RawCmm
245261
outputJS _ _ _ _ _ = pgmError $ "codeOutput: Hit JavaScript case. We should never reach here!"
246262
++ "\nThe JS backend should shortcircuit to StgToJS after Stg."
247263
++ "\nIf you reached this point then you've somehow made it to Cmm!"
264+
#endif
248265

249266
{-
250267
************************************************************************

compiler/GHC/Driver/Config/Stg/Pipeline.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{-# LANGUAGE CPP #-}
12
module GHC.Driver.Config.Stg.Pipeline
23
( initStgPipelineOpts
34
) where
@@ -42,7 +43,9 @@ getStgToDo for_bytecode dflags =
4243
-- See Note [StgCse after unarisation] in GHC.Stg.CSE
4344
, optional Opt_StgCSE StgCSE
4445
, optional Opt_StgLiftLams $ StgLiftLams $ initStgLiftConfig dflags
46+
#if defined(HAVE_INTERPRETER)
4547
, runWhen for_bytecode StgBcPrep
48+
#endif
4649
, optional Opt_StgStats StgStats
4750
] where
4851
optional opt = runWhen (gopt opt dflags)

compiler/GHC/Driver/LlvmConfigCache.hs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
1+
{-# LANGUAGE CPP #-}
2+
13
-- | LLVM config cache
24
module GHC.Driver.LlvmConfigCache
35
( LlvmConfigCache
46
, initLlvmConfigCache
7+
#if defined(HAVE_LLVM_BACKEND)
58
, readLlvmConfigCache
9+
#endif
610
)
711
where
812

913
import GHC.Prelude
10-
import GHC.CmmToLlvm.Config
1114

15+
#if defined(HAVE_LLVM_BACKEND)
16+
import GHC.CmmToLlvm.Config
1217
import System.IO.Unsafe
1318

1419
-- | Cache LLVM configuration read from files in top_dir
@@ -24,3 +29,14 @@ initLlvmConfigCache top_dir = pure $ LlvmConfigCache (unsafePerformIO $ initLlvm
2429

2530
readLlvmConfigCache :: LlvmConfigCache -> IO LlvmConfig
2631
readLlvmConfigCache (LlvmConfigCache !config) = pure config
32+
33+
#else
34+
35+
-- | Stub when LLVM backend is not available. The type must exist because
36+
-- it is a field in HscEnv (GHC.Driver.Env.Types).
37+
data LlvmConfigCache = LlvmConfigCache
38+
39+
initLlvmConfigCache :: FilePath -> IO LlvmConfigCache
40+
initLlvmConfigCache _ = pure LlvmConfigCache
41+
42+
#endif

compiler/GHC/Driver/Pipeline/Execute.hs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,15 @@ import GHC.Fingerprint
4242
import GHC.Utils.Logger
4343
import GHC.Utils.TmpFs
4444
import GHC.Platform
45+
#if defined(HAVE_LLVM_BACKEND)
4546
import Data.List (intercalate, isInfixOf)
47+
#endif
4648
import GHC.Unit.Env
4749
import GHC.Utils.Error
4850
import Data.Maybe
51+
#if defined(HAVE_LLVM_BACKEND)
4952
import GHC.CmmToLlvm.Mangler
53+
#endif
5054
import GHC.SysTools
5155
import GHC.SysTools.Cpp
5256
import System.Directory
@@ -67,8 +71,10 @@ import GHC.Unit.Finder
6771
import Data.IORef
6872
import GHC.Types.Name.Env
6973
import GHC.Platform.Ways
74+
#if defined(HAVE_LLVM_BACKEND)
7075
import GHC.Driver.LlvmConfigCache (readLlvmConfigCache)
7176
import GHC.CmmToLlvm.Config (LlvmTarget (..), LlvmConfig (..))
77+
#endif
7278
import {-# SOURCE #-} GHC.Driver.Pipeline (compileForeign, compileEmptyStub)
7379
import GHC.Settings
7480
import System.IO
@@ -151,6 +157,7 @@ runPhase (T_Cmm pipe_env hsc_env input_fn) = do
151157
runPhase (T_Cc phase pipe_env hsc_env location input_fn) = runCcPhase phase pipe_env hsc_env location input_fn
152158
runPhase (T_As cpp pipe_env hsc_env location input_fn) = do
153159
runAsPhase cpp pipe_env hsc_env location input_fn
160+
#if defined(HAVE_LLVM_BACKEND)
154161
runPhase (T_LlvmOpt pipe_env hsc_env input_fn) =
155162
runLlvmOptPhase pipe_env hsc_env input_fn
156163
runPhase (T_LlvmLlc pipe_env hsc_env input_fn) =
@@ -159,16 +166,24 @@ runPhase (T_LlvmAs cpp pipe_env hsc_env location input_fn) = do
159166
runLlvmAsPhase cpp pipe_env hsc_env location input_fn
160167
runPhase (T_LlvmMangle pipe_env hsc_env input_fn) =
161168
runLlvmManglePhase pipe_env hsc_env input_fn
169+
#else
170+
runPhase T_LlvmOpt{} = panic "runPhase: LLVM backend not available (HAVE_LLVM_BACKEND not defined)"
171+
runPhase T_LlvmLlc{} = panic "runPhase: LLVM backend not available (HAVE_LLVM_BACKEND not defined)"
172+
runPhase T_LlvmAs{} = panic "runPhase: LLVM backend not available (HAVE_LLVM_BACKEND not defined)"
173+
runPhase T_LlvmMangle{} = panic "runPhase: LLVM backend not available (HAVE_LLVM_BACKEND not defined)"
174+
#endif
162175
runPhase (T_MergeForeign pipe_env hsc_env input_fn fos) =
163176
runMergeForeign pipe_env hsc_env input_fn fos
164177

178+
#if defined(HAVE_LLVM_BACKEND)
165179
runLlvmManglePhase :: PipeEnv -> HscEnv -> FilePath -> IO [Char]
166180
runLlvmManglePhase pipe_env hsc_env input_fn = do
167181
let next_phase = As False
168182
output_fn <- phaseOutputFilenameNew next_phase pipe_env hsc_env Nothing
169183
let dflags = hsc_dflags hsc_env
170184
llvmFixupAsm (targetPlatform dflags) input_fn output_fn
171185
return output_fn
186+
#endif
172187

173188
runMergeForeign :: PipeEnv -> HscEnv -> FilePath -> [FilePath] -> IO FilePath
174189
runMergeForeign _pipe_env hsc_env input_fn foreign_os = do
@@ -185,6 +200,7 @@ runMergeForeign _pipe_env hsc_env input_fn foreign_os = do
185200
joinObjectFiles hsc_env (new_o : foreign_os) input_fn
186201
return input_fn
187202

203+
#if defined(HAVE_LLVM_BACKEND)
188204
runLlvmLlcPhase :: PipeEnv -> HscEnv -> FilePath -> IO FilePath
189205
runLlvmLlcPhase pipe_env hsc_env input_fn = do
190206
-- Note [Clamping of llc optimizations]
@@ -292,6 +308,7 @@ runLlvmOptPhase pipe_env hsc_env input_fn = do
292308
)
293309

294310
return output_fn
311+
#endif
295312

296313

297314
-- Run either 'clang' or 'gcc' phases
@@ -352,10 +369,12 @@ runGenericAsPhase run_as extra_opts with_cpp pipe_env hsc_env location input_fn
352369

353370
return output_fn
354371

372+
#if defined(HAVE_LLVM_BACKEND)
355373
-- Invoke `clang` to assemble a .S file produced by LLvm toolchain
356374
runLlvmAsPhase :: Bool -> PipeEnv -> HscEnv -> Maybe ModLocation -> FilePath -> IO FilePath
357375
runLlvmAsPhase =
358376
runGenericAsPhase runLlvmAs [ GHC.SysTools.Option "-Wno-unused-command-line-argument" ]
377+
#endif
359378

360379
-- Invoke 'gcc' to assemble a .S file
361380
runAsPhase :: Bool -> PipeEnv -> HscEnv -> Maybe ModLocation -> FilePath -> IO FilePath
@@ -976,6 +995,7 @@ getOutputFilename logger tmpfs stop_phase output basename dflags next_phase mayb
976995
| otherwise = persistent
977996

978997

998+
#if defined(HAVE_LLVM_BACKEND)
979999
-- | LLVM Options. These are flags to be passed to opt and llc, to ensure
9801000
-- consistency we list them in pairs, so that they form groups.
9811001
llvmOptions :: LlvmConfig
@@ -1036,6 +1056,7 @@ llvmOptions llvm_config dflags =
10361056
ArchRISCV64 -> "lp64d"
10371057
ArchLoongArch64 -> "lp64d"
10381058
_ -> ""
1059+
#endif
10391060

10401061
-- | What phase to run after one of the backend code generators has run
10411062
hscPostBackendPhase :: HscSource -> Backend -> Phase

compiler/GHC/Hs/Instances/Transitions.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
--
2323
-- See #9557 and #18254 for why we use -O0.
2424
{-# OPTIONS_GHC -O0 #-}
25-
{-# DEPRECATED "This module is empty; import the phase-specific GHC.Hs.Instances.* modules instead." #-}
25+
-- DEPRECATED: This module is empty; import the phase-specific
26+
-- GHC.Hs.Instances.* modules instead.
2627

2728
module GHC.Hs.Instances.Transitions where
2829

compiler/GHC/HsToCore.hs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{-# LANGUAGE CPP #-}
12
{-# LANGUAGE MonadComprehensions #-}
23
{-# LANGUAGE TypeFamilies #-}
34

@@ -35,7 +36,9 @@ import GHC.HsToCore.Binds
3536
import GHC.HsToCore.Foreign.Decl
3637
import GHC.HsToCore.Ticks
3738
import GHC.HsToCore.Breakpoints
39+
#if defined(HAVE_HPC)
3840
import GHC.HsToCore.Coverage
41+
#endif
3942
import GHC.HsToCore.Docs
4043

4144
import GHC.Tc.Types
@@ -65,7 +68,9 @@ import GHC.Builtin.Types
6568

6669
import GHC.Data.Maybe ( expectJust )
6770
import GHC.Data.OrdList
71+
#if defined(HAVE_HPC)
6872
import GHC.Data.SizedSeq ( sizeSS )
73+
#endif
6974

7075
import GHC.Utils.Error
7176
import GHC.Utils.Outputable
@@ -169,6 +174,7 @@ deSugar hsc_env
169174
| otherwise
170175
= Nothing
171176

177+
#if defined(HAVE_HPC)
172178
; ds_hpc_info <- case m_tickInfo of
173179
Just (orig_file2, ticks)
174180
| gopt Opt_Hpc $ hsc_dflags hsc_env
@@ -178,6 +184,9 @@ deSugar hsc_env
178184
else return 0 -- dummy hash when none are written
179185
pure $ HpcInfo (fromIntegral $ sizeSS ticks) hashNo
180186
_ -> pure $ emptyHpcInfo
187+
#else
188+
; let ds_hpc_info = emptyHpcInfo
189+
#endif
181190

182191
; (msgs, mb_res) <- initDs hsc_env tcg_env $
183192
do { dsEvBinds ev_binds $ \ ds_ev_binds -> do
@@ -187,7 +196,9 @@ deSugar hsc_env
187196
; (ds_fords, foreign_prs) <- dsForeigns fords
188197
; ds_rules <- mapMaybeM dsRule rules
189198
; let hpc_init
199+
#if defined(HAVE_HPC)
190200
| gopt Opt_Hpc dflags = hpcInitCode (targetPlatform $ hsc_dflags hsc_env) mod ds_hpc_info
201+
#endif
191202
| otherwise = mempty
192203
; return ( ds_ev_binds
193204
, foreign_prs `appOL` core_prs `appOL` spec_prs

compiler/GHC/Stg/Pipeline.hs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
-}
66

77

8+
{-# LANGUAGE CPP #-}
89
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
910
{-# LANGUAGE FlexibleContexts #-}
1011
{-# LANGUAGE TypeFamilies #-}
@@ -26,7 +27,9 @@ import GHC.Stg.Lint ( lintStgTopBindings )
2627
import GHC.Stg.Stats ( showStgStats )
2728
import GHC.Stg.FVs ( depSortWithAnnotStgPgm )
2829
import GHC.Stg.Unarise ( unarise )
30+
#if defined(HAVE_INTERPRETER)
2931
import GHC.Stg.BcPrep ( bcPrep )
32+
#endif
3033
import GHC.Stg.CSE ( stgCse )
3134
import GHC.Stg.Lift ( StgLiftConfig, stgLiftLams )
3235
import GHC.Unit.Module ( Module )
@@ -136,10 +139,12 @@ stg2stg logger extra_vars opts this_mod binds
136139
let binds' = {-# SCC "StgLiftLams" #-} stgLiftLams this_mod cfg us binds
137140
end_pass "StgLiftLams" binds'
138141

142+
#if defined(HAVE_INTERPRETER)
139143
StgBcPrep -> do
140144
us <- getUniqueSupplyM
141145
let binds' = {-# SCC "StgBcPrep" #-} bcPrep us binds
142146
end_pass "StgBcPrep" binds'
147+
#endif
143148

144149
StgUnarise -> do
145150
us <- getUniqueSupplyM
@@ -173,8 +178,10 @@ data StgToDo
173178
| StgStats
174179
| StgUnarise
175180
-- ^ Mandatory unarise pass, desugaring unboxed tuple and sum binders
181+
#if defined(HAVE_INTERPRETER)
176182
| StgBcPrep
177183
-- ^ Mandatory when compiling to bytecode
184+
#endif
178185
| StgDoNothing
179186
-- ^ Useful for building up 'getStgToDo'
180187
deriving (Show, Read, Eq, Ord)

0 commit comments

Comments
 (0)