@@ -42,11 +42,15 @@ import GHC.Fingerprint
4242import GHC.Utils.Logger
4343import GHC.Utils.TmpFs
4444import GHC.Platform
45+ #if defined(HAVE_LLVM_BACKEND)
4546import Data.List (intercalate , isInfixOf )
47+ #endif
4648import GHC.Unit.Env
4749import GHC.Utils.Error
4850import Data.Maybe
51+ #if defined(HAVE_LLVM_BACKEND)
4952import GHC.CmmToLlvm.Mangler
53+ #endif
5054import GHC.SysTools
5155import GHC.SysTools.Cpp
5256import System.Directory
@@ -67,8 +71,10 @@ import GHC.Unit.Finder
6771import Data.IORef
6872import GHC.Types.Name.Env
6973import GHC.Platform.Ways
74+ #if defined(HAVE_LLVM_BACKEND)
7075import GHC.Driver.LlvmConfigCache (readLlvmConfigCache )
7176import GHC.CmmToLlvm.Config (LlvmTarget (.. ), LlvmConfig (.. ))
77+ #endif
7278import {- # SOURCE #-} GHC.Driver.Pipeline (compileForeign , compileEmptyStub )
7379import GHC.Settings
7480import System.IO
@@ -151,6 +157,7 @@ runPhase (T_Cmm pipe_env hsc_env input_fn) = do
151157runPhase (T_Cc phase pipe_env hsc_env location input_fn) = runCcPhase phase pipe_env hsc_env location input_fn
152158runPhase (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)
154161runPhase (T_LlvmOpt pipe_env hsc_env input_fn) =
155162 runLlvmOptPhase pipe_env hsc_env input_fn
156163runPhase (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
160167runPhase (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
162175runPhase (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)
165179runLlvmManglePhase :: PipeEnv -> HscEnv -> FilePath -> IO [Char ]
166180runLlvmManglePhase 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
173188runMergeForeign :: PipeEnv -> HscEnv -> FilePath -> [FilePath ] -> IO FilePath
174189runMergeForeign _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)
188204runLlvmLlcPhase :: PipeEnv -> HscEnv -> FilePath -> IO FilePath
189205runLlvmLlcPhase 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
356374runLlvmAsPhase :: Bool -> PipeEnv -> HscEnv -> Maybe ModLocation -> FilePath -> IO FilePath
357375runLlvmAsPhase =
358376 runGenericAsPhase runLlvmAs [ GHC.SysTools. Option " -Wno-unused-command-line-argument" ]
377+ #endif
359378
360379-- Invoke 'gcc' to assemble a .S file
361380runAsPhase :: 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.
9811001llvmOptions :: 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
10411062hscPostBackendPhase :: HscSource -> Backend -> Phase
0 commit comments