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
26 opt_PprStyle_Debug, opt_TraceLevel,
29 -- Suppressing boring aspects of core dumps
32 opt_SuppressCoercions,
33 opt_SuppressModulePrefixes,
34 opt_SuppressTypeApplications,
36 opt_SuppressTypeSignatures,
46 opt_IrrefutableTuples,
51 opt_SimpleListLiterals,
53 opt_SimplNoPreInlining,
54 opt_SimplExcessPrecision,
59 opt_UF_CreationThreshold,
61 opt_UF_FunAppDiscount,
66 -- Optimization fuel controls
87 addOpt, removeOpt, addWay, getWayFlags, v_opt_C_ready
90 #include "HsVersions.h"
95 import Maybes ( firstJusts )
98 import Data.Maybe ( listToMaybe )
100 import System.IO.Unsafe ( unsafePerformIO )
103 -----------------------------------------------------------------------------
106 initStaticOpts :: IO ()
107 initStaticOpts = writeIORef v_opt_C_ready True
109 addOpt :: String -> IO ()
110 addOpt = consIORef v_opt_C
112 addWay :: WayName -> IO ()
113 addWay = consIORef v_Ways . lkupWay
115 removeOpt :: String -> IO ()
117 fs <- readIORef v_opt_C
118 writeIORef v_opt_C $! filter (/= f) fs
120 lookUp :: FastString -> Bool
121 lookup_def_int :: String -> Int -> Int
122 lookup_def_float :: String -> Float -> Float
123 lookup_str :: String -> Maybe String
125 -- holds the static opts while they're being collected, before
126 -- being unsafely read by unpacked_static_opts below.
127 GLOBAL_VAR(v_opt_C, defaultStaticOpts, [String])
128 GLOBAL_VAR(v_opt_C_ready, False, Bool)
130 staticFlags :: [String]
131 staticFlags = unsafePerformIO $ do
132 ready <- readIORef v_opt_C_ready
134 then panic "Static flags have not been initialised!\n Please call GHC.newSession or GHC.parseStaticFlags early enough."
135 else readIORef v_opt_C
137 -- -static is the default
138 defaultStaticOpts :: [String]
139 defaultStaticOpts = ["-static"]
141 packed_static_opts :: [FastString]
142 packed_static_opts = map mkFastString staticFlags
144 lookUp sw = sw `elem` packed_static_opts
146 -- (lookup_str "foo") looks for the flag -foo=X or -fooX,
147 -- and returns the string X
149 = case firstJusts (map (stripPrefix sw) staticFlags) of
150 Just ('=' : str) -> Just str
154 lookup_def_int sw def = case (lookup_str sw) of
155 Nothing -> def -- Use default
156 Just xx -> try_read sw xx
158 lookup_def_float sw def = case (lookup_str sw) of
159 Nothing -> def -- Use default
160 Just xx -> try_read sw xx
163 try_read :: Read a => String -> String -> a
164 -- (try_read sw str) tries to read s; if it fails, it
165 -- bleats about flag sw
168 ((x,_):_) -> x -- Be forgiving: ignore trailing goop, and alternative parses
169 [] -> ghcError (UsageError ("Malformed argument " ++ str ++ " for flag " ++ sw))
170 -- ToDo: hack alert. We should really parse the arguments
171 -- and announce errors in a more civilised way.
175 Putting the compiler options into temporary at-files
176 may turn out to be necessary later on if we turn hsc into
177 a pure Win32 application where I think there's a command-line
178 length limit of 255. unpacked_opts understands the @ option.
180 unpacked_opts :: [String]
184 map unpackFS argv -- NOT ARGV any more: v_Static_hsc_opts
186 expandAts ('@':fname) = words (unsafePerformIO (readFile fname))
190 opt_IgnoreDotGhci :: Bool
191 opt_IgnoreDotGhci = lookUp (fsLit "-ignore-dot-ghci")
194 -- | Suppress all that is suppressable in core dumps.
195 -- Except for uniques, as some simplifier phases introduce new varibles that
196 -- have otherwise identical names.
197 opt_SuppressAll :: Bool
199 = lookUp (fsLit "-dsuppress-all")
201 -- | Suppress all coercions, them replacing with '...'
202 opt_SuppressCoercions :: Bool
203 opt_SuppressCoercions
204 = lookUp (fsLit "-dsuppress-all")
205 || lookUp (fsLit "-dsuppress-coercions")
207 -- | Suppress module id prefixes on variables.
208 opt_SuppressModulePrefixes :: Bool
209 opt_SuppressModulePrefixes
210 = lookUp (fsLit "-dsuppress-all")
211 || lookUp (fsLit "-dsuppress-module-prefixes")
213 -- | Suppress type applications.
214 opt_SuppressTypeApplications :: Bool
215 opt_SuppressTypeApplications
216 = lookUp (fsLit "-dsuppress-all")
217 || lookUp (fsLit "-dsuppress-type-applications")
219 -- | Suppress info such as arity and unfoldings on identifiers.
220 opt_SuppressIdInfo :: Bool
222 = lookUp (fsLit "-dsuppress-all")
223 || lookUp (fsLit "-dsuppress-idinfo")
225 -- | Suppress seprate type signatures in core, but leave types on lambda bound vars
226 opt_SuppressTypeSignatures :: Bool
227 opt_SuppressTypeSignatures
228 = lookUp (fsLit "-dsuppress-all")
229 || lookUp (fsLit "-dsuppress-type-signatures")
231 -- | Suppress unique ids on variables.
232 -- Except for uniques, as some simplifier phases introduce new variables that
233 -- have otherwise identical names.
234 opt_SuppressUniques :: Bool
236 = lookUp (fsLit "-dsuppress-uniques")
238 -- | Display case expressions with a single alternative as strict let bindings
239 opt_PprCaseAsLet :: Bool
240 opt_PprCaseAsLet = lookUp (fsLit "-dppr-case-as-let")
242 -- | Set the maximum width of the dumps
243 -- If GHC's command line options are bad then the options parser uses the
244 -- pretty printer display the error message. In this case the staticFlags
245 -- won't be initialized yet, so we must check for this case explicitly
246 -- and return the default value.
250 $ do ready <- readIORef v_opt_C_ready
253 else return $ lookup_def_int "-dppr-cols" 100
256 opt_PprStyle_Debug :: Bool
257 opt_PprStyle_Debug = lookUp (fsLit "-dppr-debug")
259 opt_TraceLevel :: Int
260 opt_TraceLevel = lookup_def_int "-dtrace-level" 1 -- Standard level is 1
263 opt_PprUserLength :: Int
264 opt_PprUserLength = lookup_def_int "-dppr-user-length" 5 --ToDo: give this a name
267 opt_Fuel = lookup_def_int "-dopt-fuel" maxBound
269 opt_NoDebugOutput :: Bool
270 opt_NoDebugOutput = lookUp (fsLit "-dno-debug-output")
273 opt_SccProfilingOn :: Bool
274 opt_SccProfilingOn = lookUp (fsLit "-fscc-profiling")
278 opt_Hpc = lookUp (fsLit "-fhpc")
281 opt_DictsStrict :: Bool
282 opt_DictsStrict = lookUp (fsLit "-fdicts-strict")
284 opt_IrrefutableTuples :: Bool
285 opt_IrrefutableTuples = lookUp (fsLit "-firrefutable-tuples")
288 opt_Parallel = lookUp (fsLit "-fparallel")
290 opt_SimpleListLiterals :: Bool
291 opt_SimpleListLiterals = lookUp (fsLit "-fsimple-list-literals")
293 opt_NoStateHack :: Bool
294 opt_NoStateHack = lookUp (fsLit "-fno-state-hack")
297 opt_CprOff = lookUp (fsLit "-fcpr-off")
298 -- Switch off CPR analysis in the new demand analyser
299 opt_MaxWorkerArgs :: Int
300 opt_MaxWorkerArgs = lookup_def_int "-fmax-worker-args" (10::Int)
302 opt_GranMacros :: Bool
303 opt_GranMacros = lookUp (fsLit "-fgransim")
305 opt_HiVersion :: Integer
306 opt_HiVersion = read (cProjectVersionInt ++ cProjectPatchLevel) :: Integer
308 opt_HistorySize :: Int
309 opt_HistorySize = lookup_def_int "-fhistory-size" 20
311 opt_OmitBlackHoling :: Bool
312 opt_OmitBlackHoling = lookUp (fsLit "-dno-black-holing")
314 opt_StubDeadValues :: Bool
315 opt_StubDeadValues = lookUp (fsLit "-dstub-dead-values")
317 -- Simplifier switches
318 opt_SimplNoPreInlining :: Bool
319 opt_SimplNoPreInlining = lookUp (fsLit "-fno-pre-inlining")
320 -- NoPreInlining is there just to see how bad things
321 -- get if you don't do it!
322 opt_SimplExcessPrecision :: Bool
323 opt_SimplExcessPrecision = lookUp (fsLit "-fexcess-precision")
325 opt_NoOptCoercion :: Bool
326 opt_NoOptCoercion = lookUp (fsLit "-fno-opt-coercion")
329 -- See Note [Discounts and thresholds] in CoreUnfold
331 opt_UF_CreationThreshold, opt_UF_UseThreshold :: Int
332 opt_UF_DearOp, opt_UF_FunAppDiscount, opt_UF_DictDiscount :: Int
333 opt_UF_KeenessFactor :: Float
335 opt_UF_CreationThreshold = lookup_def_int "-funfolding-creation-threshold" (450::Int)
336 opt_UF_UseThreshold = lookup_def_int "-funfolding-use-threshold" (60::Int)
337 opt_UF_FunAppDiscount = lookup_def_int "-funfolding-fun-discount" (60::Int)
339 opt_UF_DictDiscount = lookup_def_int "-funfolding-dict-discount" (30::Int)
340 -- Be fairly keen to inline a fuction if that means
341 -- we'll be able to pick the right method from a dictionary
343 opt_UF_KeenessFactor = lookup_def_float "-funfolding-keeness-factor" (1.5::Float)
344 opt_UF_DearOp = ( 40 :: Int)
347 -- Related to linking
349 #if darwin_TARGET_OS && x86_64_TARGET_ARCH
351 #elif darwin_TARGET_OS
352 opt_PIC = lookUp (fsLit "-fPIC") || not opt_Static
354 opt_PIC = lookUp (fsLit "-fPIC")
357 opt_Static = lookUp (fsLit "-static")
358 opt_Unregisterised :: Bool
359 opt_Unregisterised = lookUp (fsLit "-funregisterised")
361 -- Derived, not a real option. Determines whether we will be compiling
362 -- info tables that reside just before the entry code, or with an
363 -- indirection to the entry code. See TABLES_NEXT_TO_CODE in
364 -- includes/rts/storage/InfoTables.h.
365 tablesNextToCode :: Bool
366 tablesNextToCode = not opt_Unregisterised
367 && cGhcEnableTablesNextToCode == "YES"
369 -- Include full span info in error messages, instead of just the start position.
370 opt_ErrorSpans :: Bool
371 opt_ErrorSpans = lookUp (fsLit "-ferror-spans")
374 opt_Ticky = lookUp (fsLit "-ticky")
376 -- object files and libraries to be linked in are collected here.
377 -- ToDo: perhaps this could be done without a global, it wasn't obvious
378 -- how to do it though --SDM.
379 GLOBAL_VAR(v_Ld_inputs, [], [String])
381 -----------------------------------------------------------------------------
384 -- The central concept of a "way" is that all objects in a given
385 -- program must be compiled in the same "way". Certain options change
386 -- parameters of the virtual machine, eg. profiling adds an extra word
387 -- to the object header, so profiling objects cannot be linked with
388 -- non-profiling objects.
390 -- After parsing the command-line options, we determine which "way" we
391 -- are building - this might be a combination way, eg. profiling+threaded.
393 -- We then find the "build-tag" associated with this way, and this
394 -- becomes the suffix used to find .hi files and libraries used in
408 GLOBAL_VAR(v_Ways, [] ,[Way])
410 allowed_combination :: [WayName] -> Bool
411 allowed_combination way = and [ x `allowedWith` y
412 | x <- way, y <- way, x < y ]
414 -- Note ordering in these tests: the left argument is
415 -- <= the right argument, according to the Ord instance
418 -- dyn is allowed with everything
419 _ `allowedWith` WayDyn = True
420 WayDyn `allowedWith` _ = True
422 -- debug is allowed with everything
423 _ `allowedWith` WayDebug = True
424 WayDebug `allowedWith` _ = True
426 WayProf `allowedWith` WayNDP = True
427 WayThreaded `allowedWith` WayProf = True
428 WayThreaded `allowedWith` WayEventLog = True
429 _ `allowedWith` _ = False
432 getWayFlags :: IO [String] -- new options
434 unsorted <- readIORef v_Ways
435 let ways = sortBy (compare `on` wayName) $
436 nubBy ((==) `on` wayName) $ unsorted
437 writeIORef v_Ways ways
439 if not (allowed_combination (map wayName ways))
440 then ghcError (CmdLineError $
441 "combination not supported: " ++
442 foldr1 (\a b -> a ++ '/':b)
445 return (concatMap wayOpts ways)
447 mkBuildTag :: [Way] -> String
448 mkBuildTag ways = concat (intersperse "_" (map wayTag ways))
450 lkupWay :: WayName -> Way
452 case listToMaybe (filter ((==) w . wayName) way_details) of
453 Nothing -> error "findBuildTag"
454 Just details -> details
456 isRTSWay :: WayName -> Bool
457 isRTSWay = wayRTSOnly . lkupWay
467 way_details :: [ Way ]
469 [ Way WayThreaded "thr" True "Threaded" [
470 #if defined(freebsd_TARGET_OS)
473 -- FreeBSD's default threading library is the KSE-based M:N libpthread,
474 -- which GHC has some problems with. It's currently not clear whether
475 -- the problems are our fault or theirs, but it seems that using the
476 -- alternative 1:1 threading library libthr works around it:
478 #elif defined(openbsd_TARGET_OS)
481 #elif defined(solaris2_TARGET_OS)
486 Way WayDebug "debug" True "Debug" [],
488 Way WayDyn "dyn" False "Dynamic"
491 #if defined(mingw32_TARGET_OS)
492 -- On Windows, code that is to be linked into a dynamic library must be compiled
493 -- with -fPIC. Labels not in the current package are assumed to be in a DLL
494 -- different from the current one.
496 #elif defined(openbsd_TARGET_OS)
497 -- Without this, linking the shared libHSffi fails because
498 -- it uses pthread mutexes.
503 Way WayProf "p" False "Profiling"
506 , "-optc-DPROFILING" ],
508 Way WayEventLog "l" True "RTS Event Logging"
510 , "-optc-DTRACING" ],
512 Way WayPar "mp" False "Parallel"
514 , "-D__PARALLEL_HASKELL__"
516 , "-package concurrent"
518 , "-optl-L${PVM_ROOT}/lib/${PVM_ARCH}"
522 -- at the moment we only change the RTS and could share compiler and libs!
523 Way WayPar "mt" False "Parallel ticky profiling"
525 , "-D__PARALLEL_HASKELL__"
528 , "-package concurrent"
530 , "-optl-L${PVM_ROOT}/lib/${PVM_ARCH}"
534 Way WayPar "md" False "Distributed"
536 , "-D__PARALLEL_HASKELL__"
537 , "-D__DISTRIBUTED_HASKELL__"
540 , "-package concurrent"
542 , "-optl-L${PVM_ROOT}/lib/${PVM_ARCH}"
546 Way WayGran "mg" False "GranSim"
550 , "-package concurrent" ],
552 Way WayNDP "ndp" False "Nested data parallelism"