Occurrrence analysis improvements for NOINLINE functions
[ghc.git] / hadrian / src / Settings / Packages / Rts.hs
1 module Settings.Packages.Rts (
2 rtsContext, rtsBuildPath, rtsConfIn, rtsPackageArgs, rtsLibffiLibrary
3 ) where
4
5 import Base
6 import Expression
7 import Oracles.Flag
8 import Oracles.Setting
9 import Settings
10
11 -- | RTS is considered a Stage1 package. This determines RTS build directory.
12 rtsContext :: Context
13 rtsContext = vanillaContext Stage1 rts
14
15 -- | Path to the RTS build directory.
16 rtsBuildPath :: Action FilePath
17 rtsBuildPath = buildPath rtsContext
18
19 -- | Path to RTS package configuration file, to be processed by HsCpp.
20 rtsConfIn :: FilePath
21 rtsConfIn = pkgPath rts -/- "package.conf.in"
22
23 -- These numbers can be found at:
24 -- https://msdn.microsoft.com/en-us/library/windows/desktop/aa383745(v=vs.85).aspx
25 -- If we're compiling on windows, enforce that we only support Vista SP1+
26 -- Adding this here means it doesn't have to be done in individual .c files
27 -- and also centralizes the versioning.
28 -- | Minimum supported Windows version.
29 windowsVersion :: String
30 windowsVersion = "0x06000100"
31
32 libffiLibraryName :: Action FilePath
33 libffiLibraryName = do
34 useSystemFfi <- flag UseSystemFfi
35 windows <- windowsHost
36 return $ case (useSystemFfi, windows) of
37 (True , False) -> "ffi"
38 (False, False) -> "Cffi"
39 (_ , True ) -> "Cffi-6"
40
41 rtsLibffiLibrary :: Way -> Action FilePath
42 rtsLibffiLibrary way = do
43 name <- libffiLibraryName
44 suf <- libsuf way
45 rtsPath <- rtsBuildPath
46 return $ rtsPath -/- "lib" ++ name ++ suf
47
48 -- Compile various performance-critical pieces *without* -fPIC -dynamic
49 -- even when building a shared library. If we don't do this, then the
50 -- GC runs about 50% slower on x86 due to the overheads of PIC. The
51 -- cost of doing this is a little runtime linking and less sharing, but
52 -- not much.
53 --
54 -- On x86_64 this doesn't work, because all objects in a shared library
55 -- must be compiled with -fPIC (since the 32-bit relocations generated
56 -- by the default small memory can't be resolved at runtime). So we
57 -- only do this on i386.
58 --
59 -- This apparently doesn't work on OS X (Darwin) nor on Solaris.
60 -- On Darwin we get errors of the form
61 --
62 -- ld: absolute addressing (perhaps -mdynamic-no-pic) used in _stg_ap_0_fast from rts/dist/build/Apply.dyn_o not allowed in slidable image
63 --
64 -- and lots of these warnings:
65 --
66 -- ld: warning codegen in _stg_ap_pppv_fast (offset 0x0000005E) prevents image from loading in dyld shared cache
67 --
68 -- On Solaris we get errors like:
69 --
70 -- Text relocation remains referenced
71 -- against symbol offset in file
72 -- .rodata (section) 0x11 rts/dist/build/Apply.dyn_o
73 -- ...
74 -- ld: fatal: relocations remain against allocatable but non-writable sections
75 -- collect2: ld returned 1 exit status
76 speedHack :: Action Bool
77 speedHack = do
78 i386 <- anyTargetArch ["i386"]
79 goodOS <- not <$> anyTargetOs ["darwin", "solaris2"]
80 return $ i386 && goodOS
81
82 rtsPackageArgs :: Args
83 rtsPackageArgs = package rts ? do
84 projectVersion <- getSetting ProjectVersion
85 hostPlatform <- getSetting HostPlatform
86 hostArch <- getSetting HostArch
87 hostOs <- getSetting HostOs
88 hostVendor <- getSetting HostVendor
89 buildPlatform <- getSetting BuildPlatform
90 buildArch <- getSetting BuildArch
91 buildOs <- getSetting BuildOs
92 buildVendor <- getSetting BuildVendor
93 targetPlatform <- getSetting TargetPlatform
94 targetArch <- getSetting TargetArch
95 targetOs <- getSetting TargetOs
96 targetVendor <- getSetting TargetVendor
97 ghcUnreg <- expr $ yesNo <$> flag GhcUnregisterised
98 ghcEnableTNC <- expr $ yesNo <$> ghcEnableTablesNextToCode
99 way <- getWay
100 path <- getBuildPath
101 top <- expr topDirectory
102 libffiName <- expr libffiLibraryName
103 ffiIncludeDir <- getSetting FfiIncludeDir
104 ffiLibraryDir <- getSetting FfiLibDir
105 ghclibDir <- expr installGhcLibDir
106 destDir <- expr getDestDir
107 let cArgs = mconcat
108 [ arg "-Irts"
109 , rtsWarnings
110 , arg $ "-I" ++ path
111 , flag UseSystemFfi ? arg ("-I" ++ ffiIncludeDir)
112 , arg $ "-DRtsWay=\"rts_" ++ show way ++ "\""
113 -- RTS *must* be compiled with optimisations. The INLINE_HEADER macro
114 -- requires that functions are inlined to work as expected. Inlining
115 -- only happens for optimised builds. Otherwise we can assume that
116 -- there is a non-inlined variant to use instead. But RTS does not
117 -- provide non-inlined alternatives and hence needs the function to
118 -- be inlined. See https://github.com/snowleopard/hadrian/issues/90.
119 , arg "-O2"
120
121 , Debug `wayUnit` way ? arg "-DDEBUG"
122 , way `elem` [debug, debugDynamic] ? arg "-DTICKY_TICKY"
123 , Profiling `wayUnit` way ? arg "-DPROFILING"
124 , Threaded `wayUnit` way ? arg "-DTHREADED_RTS"
125
126 , inputs ["//RtsMessages.c", "//Trace.c"] ?
127 arg ("-DProjectVersion=" ++ show projectVersion)
128
129 , input "//RtsUtils.c" ? pure
130 [ "-DProjectVersion=" ++ show projectVersion
131 , "-DHostPlatform=" ++ show hostPlatform
132 , "-DHostArch=" ++ show hostArch
133 , "-DHostOS=" ++ show hostOs
134 , "-DHostVendor=" ++ show hostVendor
135 , "-DBuildPlatform=" ++ show buildPlatform
136 , "-DBuildArch=" ++ show buildArch
137 , "-DBuildOS=" ++ show buildOs
138 , "-DBuildVendor=" ++ show buildVendor
139 , "-DTargetPlatform=" ++ show targetPlatform
140 , "-DTargetArch=" ++ show targetArch
141 , "-DTargetOS=" ++ show targetOs
142 , "-DTargetVendor=" ++ show targetVendor
143 , "-DGhcUnregisterised=" ++ show ghcUnreg
144 , "-DGhcEnableTablesNextToCode=" ++ show ghcEnableTNC ]
145
146 , inputs ["//Evac.c", "//Evac_thr.c"] ? arg "-funroll-loops"
147
148 , speedHack ?
149 inputs [ "//Evac.c", "//Evac_thr.c"
150 , "//Scav.c", "//Scav_thr.c"
151 , "//Compact.c", "//GC.c" ] ? arg "-fno-PIC"
152 -- -static is also necessary for these bits, otherwise the NCG
153 -- generates dynamic references:
154 , speedHack ?
155 inputs [ "//Updates.c", "//StgMiscClosures.c"
156 , "//PrimOps.c", "//Apply.c"
157 , "//AutoApply.c" ] ? pure ["-fno-PIC", "-static"]
158
159 -- inlining warnings happen in Compact
160 , inputs ["//Compact.c"] ? arg "-Wno-inline"
161
162 -- emits warnings about call-clobbered registers on x86_64
163 , inputs [ "//RetainerProfile.c", "//StgCRun.c"
164 , "//win32/ConsoleHandler.c", "//win32/ThrIOManager.c"] ? arg "-w"
165 , inputs ["//RetainerSet.c"] ? arg "-Wno-format"
166 -- The above warning suppression flags are a temporary kludge.
167 -- While working on this module you are encouraged to remove it and fix
168 -- any warnings in the module. See:
169 -- http://ghc.haskell.org/trac/ghc/wiki/WorkingConventions#Warnings
170
171 , (not <$> flag GccIsClang) ?
172 inputs ["//Compact.c"] ? arg "-finline-limit=2500"
173
174 , inputs ["//Evac_thr.c", "//Scav_thr.c"] ?
175 pure ["-DPARALLEL_GC", "-Irts/sm"]
176
177 , input "//StgCRun.c" ? windowsHost ? arg "-Wno-return-local-addr"
178 , input "//RetainerProfile.c" ? flag GccIsClang ?
179 arg "-Wno-incompatible-pointer-types"
180 , windowsHost ? arg ("-DWINVER=" ++ windowsVersion)
181
182 -- libffi's ffi.h triggers various warnings
183 , inputs [ "//Interpreter.c", "//Storage.c", "//Adjustor.c" ] ?
184 arg "-Wno-strict-prototypes"
185 , inputs ["//Interpreter.c", "//Adjustor.c", "//sm/Storage.c"] ?
186 anyTargetArch ["powerpc"] ? arg "-Wno-undef"
187 ]
188
189 mconcat
190 [ builder (Cc FindCDependencies) ? cArgs
191 , builder (Ghc CompileCWithGhc) ? map ("-optc" ++) <$> cArgs
192 , builder Ghc ? arg "-Irts"
193
194 , builder HsCpp ? pure
195 [ "-DTOP=" ++ show top
196 , "-DFFI_INCLUDE_DIR=" ++ show ffiIncludeDir
197 , "-DFFI_LIB_DIR=" ++ show ffiLibraryDir
198 , "-DFFI_LIB=" ++ show libffiName ]
199
200 , builder HsCpp ?
201 input "//package.conf.in" ?
202 output "//package.conf.install.raw" ?
203 pure [ "-DINSTALLING"
204 , "-DLIB_DIR=\"" ++ destDir ++ ghclibDir ++ "\""
205 , "-DINCLUDE_DIR=\"" ++ destDir ++ ghclibDir -/- "include\"" ]
206
207 , builder HsCpp ? flag HaveLibMingwEx ? arg "-DHAVE_LIBMINGWEX" ]
208
209 -- See @rts/ghc.mk@.
210 rtsWarnings :: Args
211 rtsWarnings = mconcat
212 [ pure ["-Wall", "-Werror"]
213 , arg "-Wextra"
214 , arg "-Wstrict-prototypes"
215 , arg "-Wmissing-prototypes"
216 , arg "-Wmissing-declarations"
217 , arg "-Winline"
218 , arg "-Waggregate-return"
219 , arg "-Wpointer-arith"
220 , arg "-Wmissing-noreturn"
221 , arg "-Wnested-externs"
222 , arg "-Wredundant-decls"
223 , arg "-Wundef"
224 , arg "-fno-strict-aliasing" ]