1 {-# OPTIONS -fno-cse #-}
2 -- -fno-cse is needed for GLOBAL_VAR's to behave properly
4 -----------------------------------------------------------------------------
8 -- Static flags can only be set once, on the command-line. Inside GHC,
9 -- each static flag corresponds to a top-level value, usually of type Bool.
11 -- (c) The University of Glasgow 2005
13 -----------------------------------------------------------------------------
20 WayName(..), Way(..), v_Ways, isRTSWay, mkBuildTag,
22 -- Output style options
25 opt_SuppressCoercions,
37 opt_IrrefutableTuples,
43 opt_SimpleListLiterals,
44 opt_SpecInlineJoinPoints,
46 opt_SimplNoPreInlining,
47 opt_SimplExcessPrecision,
51 opt_UF_CreationThreshold,
53 opt_UF_FunAppDiscount,
58 -- Optimization fuel controls
78 addOpt, removeOpt, addWay, getWayFlags, v_opt_C_ready
81 #include "HsVersions.h"
86 import Maybes ( firstJust )
89 import Data.Maybe ( listToMaybe )
91 import System.IO.Unsafe ( unsafePerformIO )
94 -----------------------------------------------------------------------------
97 initStaticOpts :: IO ()
98 initStaticOpts = writeIORef v_opt_C_ready True
100 addOpt :: String -> IO ()
101 addOpt = consIORef v_opt_C
103 addWay :: WayName -> IO ()
104 addWay = consIORef v_Ways . lkupWay
106 removeOpt :: String -> IO ()
108 fs <- readIORef v_opt_C
109 writeIORef v_opt_C $! filter (/= f) fs
111 lookUp :: FastString -> Bool
112 lookup_def_int :: String -> Int -> Int
113 lookup_def_float :: String -> Float -> Float
114 lookup_str :: String -> Maybe String
116 -- holds the static opts while they're being collected, before
117 -- being unsafely read by unpacked_static_opts below.
118 GLOBAL_VAR(v_opt_C, defaultStaticOpts, [String])
119 GLOBAL_VAR(v_opt_C_ready, False, Bool)
121 staticFlags :: [String]
122 staticFlags = unsafePerformIO $ do
123 ready <- readIORef v_opt_C_ready
125 then panic "Static flags have not been initialised!\n Please call GHC.newSession or GHC.parseStaticFlags early enough."
126 else readIORef v_opt_C
128 -- -static is the default
129 defaultStaticOpts :: [String]
130 defaultStaticOpts = ["-static"]
132 packed_static_opts :: [FastString]
133 packed_static_opts = map mkFastString staticFlags
135 lookUp sw = sw `elem` packed_static_opts
137 -- (lookup_str "foo") looks for the flag -foo=X or -fooX,
138 -- and returns the string X
140 = case firstJust (map (stripPrefix sw) staticFlags) of
141 Just ('=' : str) -> Just str
145 lookup_def_int sw def = case (lookup_str sw) of
146 Nothing -> def -- Use default
147 Just xx -> try_read sw xx
149 lookup_def_float sw def = case (lookup_str sw) of
150 Nothing -> def -- Use default
151 Just xx -> try_read sw xx
154 try_read :: Read a => String -> String -> a
155 -- (try_read sw str) tries to read s; if it fails, it
156 -- bleats about flag sw
159 ((x,_):_) -> x -- Be forgiving: ignore trailing goop, and alternative parses
160 [] -> ghcError (UsageError ("Malformed argument " ++ str ++ " for flag " ++ sw))
161 -- ToDo: hack alert. We should really parse the arugments
162 -- and announce errors in a more civilised way.
166 Putting the compiler options into temporary at-files
167 may turn out to be necessary later on if we turn hsc into
168 a pure Win32 application where I think there's a command-line
169 length limit of 255. unpacked_opts understands the @ option.
171 unpacked_opts :: [String]
175 map unpackFS argv -- NOT ARGV any more: v_Static_hsc_opts
177 expandAts ('@':fname) = words (unsafePerformIO (readFile fname))
181 opt_IgnoreDotGhci :: Bool
182 opt_IgnoreDotGhci = lookUp (fsLit "-ignore-dot-ghci")
185 opt_SuppressUniques :: Bool
186 opt_SuppressUniques = lookUp (fsLit "-dsuppress-uniques")
187 opt_SuppressCoercions :: Bool
188 opt_SuppressCoercions = lookUp (fsLit "-dsuppress-coercions")
189 opt_PprStyle_Debug :: Bool
190 opt_PprStyle_Debug = lookUp (fsLit "-dppr-debug")
191 opt_PprUserLength :: Int
192 opt_PprUserLength = lookup_def_int "-dppr-user-length" 5 --ToDo: give this a name
194 opt_Fuel = lookup_def_int "-dopt-fuel" maxBound
195 opt_NoDebugOutput :: Bool
196 opt_NoDebugOutput = lookUp (fsLit "-dno-debug-output")
200 opt_SccProfilingOn :: Bool
201 opt_SccProfilingOn = lookUp (fsLit "-fscc-profiling")
205 opt_Hpc = lookUp (fsLit "-fhpc")
208 opt_DictsStrict :: Bool
209 opt_DictsStrict = lookUp (fsLit "-fdicts-strict")
210 opt_IrrefutableTuples :: Bool
211 opt_IrrefutableTuples = lookUp (fsLit "-firrefutable-tuples")
213 opt_Parallel = lookUp (fsLit "-fparallel")
216 opt_DsMultiTyVar :: Bool
217 opt_DsMultiTyVar = not (lookUp (fsLit "-fno-ds-multi-tyvar"))
220 opt_SpecInlineJoinPoints :: Bool
221 opt_SpecInlineJoinPoints = lookUp (fsLit "-fspec-inline-join-points")
223 opt_SimpleListLiterals :: Bool
224 opt_SimpleListLiterals = lookUp (fsLit "-fsimple-list-literals")
226 opt_NoStateHack :: Bool
227 opt_NoStateHack = lookUp (fsLit "-fno-state-hack")
230 opt_CprOff = lookUp (fsLit "-fcpr-off")
231 -- Switch off CPR analysis in the new demand analyser
232 opt_MaxWorkerArgs :: Int
233 opt_MaxWorkerArgs = lookup_def_int "-fmax-worker-args" (10::Int)
235 opt_GranMacros :: Bool
236 opt_GranMacros = lookUp (fsLit "-fgransim")
237 opt_HiVersion :: Integer
238 opt_HiVersion = read (cProjectVersionInt ++ cProjectPatchLevel) :: Integer
239 opt_HistorySize :: Int
240 opt_HistorySize = lookup_def_int "-fhistory-size" 20
241 opt_OmitBlackHoling :: Bool
242 opt_OmitBlackHoling = lookUp (fsLit "-dno-black-holing")
243 opt_StubDeadValues :: Bool
244 opt_StubDeadValues = lookUp (fsLit "-dstub-dead-values")
246 -- Simplifier switches
247 opt_SimplNoPreInlining :: Bool
248 opt_SimplNoPreInlining = lookUp (fsLit "-fno-pre-inlining")
249 -- NoPreInlining is there just to see how bad things
250 -- get if you don't do it!
251 opt_SimplExcessPrecision :: Bool
252 opt_SimplExcessPrecision = lookUp (fsLit "-fexcess-precision")
255 -- See Note [Discounts and thresholds] in CoreUnfold
257 opt_UF_CreationThreshold, opt_UF_UseThreshold :: Int
258 opt_UF_DearOp, opt_UF_FunAppDiscount, opt_UF_DictDiscount :: Int
259 opt_UF_KeenessFactor :: Float
261 opt_UF_CreationThreshold = lookup_def_int "-funfolding-creation-threshold" (45::Int)
262 opt_UF_UseThreshold = lookup_def_int "-funfolding-use-threshold" (6::Int)
263 opt_UF_FunAppDiscount = lookup_def_int "-funfolding-fun-discount" (6::Int)
264 opt_UF_DictDiscount = lookup_def_int "-funfolding-dict-discount" (1::Int)
265 opt_UF_KeenessFactor = lookup_def_float "-funfolding-keeness-factor" (1.5::Float)
266 opt_UF_DearOp = ( 4 :: Int)
269 -- Related to linking
271 #if darwin_TARGET_OS && x86_64_TARGET_ARCH
274 opt_PIC = lookUp (fsLit "-fPIC")
277 opt_Static = lookUp (fsLit "-static")
278 opt_Unregisterised :: Bool
279 opt_Unregisterised = lookUp (fsLit "-funregisterised")
281 -- Derived, not a real option. Determines whether we will be compiling
282 -- info tables that reside just before the entry code, or with an
283 -- indirection to the entry code. See TABLES_NEXT_TO_CODE in
284 -- includes/rts/storage/InfoTables.h.
285 tablesNextToCode :: Bool
286 tablesNextToCode = not opt_Unregisterised
287 && cGhcEnableTablesNextToCode == "YES"
289 -- Include full span info in error messages, instead of just the start position.
290 opt_ErrorSpans :: Bool
291 opt_ErrorSpans = lookUp (fsLit "-ferror-spans")
294 -- object files and libraries to be linked in are collected here.
295 -- ToDo: perhaps this could be done without a global, it wasn't obvious
296 -- how to do it though --SDM.
297 GLOBAL_VAR(v_Ld_inputs, [], [String])
299 -----------------------------------------------------------------------------
302 -- The central concept of a "way" is that all objects in a given
303 -- program must be compiled in the same "way". Certain options change
304 -- parameters of the virtual machine, eg. profiling adds an extra word
305 -- to the object header, so profiling objects cannot be linked with
306 -- non-profiling objects.
308 -- After parsing the command-line options, we determine which "way" we
309 -- are building - this might be a combination way, eg. profiling+ticky-ticky.
311 -- We then find the "build-tag" associated with this way, and this
312 -- becomes the suffix used to find .hi files and libraries used in
327 GLOBAL_VAR(v_Ways, [] ,[Way])
329 allowed_combination :: [WayName] -> Bool
330 allowed_combination way = and [ x `allowedWith` y
331 | x <- way, y <- way, x < y ]
333 -- Note ordering in these tests: the left argument is
334 -- <= the right argument, according to the Ord instance
337 -- dyn is allowed with everything
338 _ `allowedWith` WayDyn = True
339 WayDyn `allowedWith` _ = True
341 -- ticky is (now) allowed with everything
342 -- Indeed, ticky should no longer be a 'way' at all
343 _ `allowedWith` WayTicky = True
344 WayTicky `allowedWith` _ = True
346 -- debug is allowed with everything
347 _ `allowedWith` WayDebug = True
348 WayDebug `allowedWith` _ = True
350 WayProf `allowedWith` WayNDP = True
351 WayThreaded `allowedWith` WayProf = True
352 WayThreaded `allowedWith` WayEventLog = True
353 _ `allowedWith` _ = False
356 getWayFlags :: IO [String] -- new options
358 unsorted <- readIORef v_Ways
359 let ways = sortBy (compare `on` wayName) $
360 nubBy ((==) `on` wayName) $ unsorted
361 writeIORef v_Ways ways
363 if not (allowed_combination (map wayName ways))
364 then ghcError (CmdLineError $
365 "combination not supported: " ++
366 foldr1 (\a b -> a ++ '/':b)
369 return (concatMap wayOpts ways)
371 mkBuildTag :: [Way] -> String
372 mkBuildTag ways = concat (intersperse "_" (map wayTag ways))
374 lkupWay :: WayName -> Way
376 case listToMaybe (filter ((==) w . wayName) way_details) of
377 Nothing -> error "findBuildTag"
378 Just details -> details
380 isRTSWay :: WayName -> Bool
381 isRTSWay = wayRTSOnly . lkupWay
391 way_details :: [ Way ]
393 [ Way WayThreaded "thr" True "Threaded" [
394 #if defined(freebsd_TARGET_OS)
397 -- FreeBSD's default threading library is the KSE-based M:N libpthread,
398 -- which GHC has some problems with. It's currently not clear whether
399 -- the problems are our fault or theirs, but it seems that using the
400 -- alternative 1:1 threading library libthr works around it:
402 #elif defined(solaris2_TARGET_OS)
407 Way WayDebug "debug" True "Debug" [],
409 Way WayDyn "dyn" False "Dynamic"
411 , "-optc-DDYNAMIC" ],
413 Way WayProf "p" False "Profiling"
416 , "-optc-DPROFILING" ],
418 Way WayEventLog "l" True "RTS Event Logging"
420 , "-optc-DTRACING" ],
422 Way WayTicky "t" True "Ticky-ticky Profiling"
424 , "-optc-DTICKY_TICKY" ],
426 Way WayPar "mp" False "Parallel"
428 , "-D__PARALLEL_HASKELL__"
430 , "-package concurrent"
432 , "-optl-L${PVM_ROOT}/lib/${PVM_ARCH}"
436 -- at the moment we only change the RTS and could share compiler and libs!
437 Way WayPar "mt" False "Parallel ticky profiling"
439 , "-D__PARALLEL_HASKELL__"
442 , "-package concurrent"
444 , "-optl-L${PVM_ROOT}/lib/${PVM_ARCH}"
448 Way WayPar "md" False "Distributed"
450 , "-D__PARALLEL_HASKELL__"
451 , "-D__DISTRIBUTED_HASKELL__"
454 , "-package concurrent"
456 , "-optl-L${PVM_ROOT}/lib/${PVM_ARCH}"
460 Way WayGran "mg" False "GranSim"
464 , "-package concurrent" ],
466 Way WayNDP "ndp" False "Nested data parallelism"