Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # Copyright (c) 2012 The Native Client Authors. All rights reserved. | 2 # Copyright (c) 2012 The Native Client Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 import driver_tools | 6 import driver_tools |
| 7 import filetype | 7 import filetype |
| 8 import ldtools | 8 import ldtools |
| 9 import multiprocessing | 9 import multiprocessing |
| 10 import os | 10 import os |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 102 'LLC_FLAGS_TARGET' : '-mtriple=${TRIPLE} -filetype=${outfiletype}', | 102 'LLC_FLAGS_TARGET' : '-mtriple=${TRIPLE} -filetype=${outfiletype}', |
| 103 | 103 |
| 104 # Append additional non-default flags here. | 104 # Append additional non-default flags here. |
| 105 # BE CAREFUL: anything added here can introduce skew between | 105 # BE CAREFUL: anything added here can introduce skew between |
| 106 # the pnacl-translate commandline tool and the in-browser translator. | 106 # the pnacl-translate commandline tool and the in-browser translator. |
| 107 # See: llvm/tools/pnacl-llc/srpc_main.cpp and | 107 # See: llvm/tools/pnacl-llc/srpc_main.cpp and |
| 108 # Chromium's plugin/pnacl_translate_thread.cc | 108 # Chromium's plugin/pnacl_translate_thread.cc |
| 109 'LLC_FLAGS_EXTRA' : '${FAST_TRANSLATION ? ${LLC_FLAGS_FAST}} ' + | 109 'LLC_FLAGS_EXTRA' : '${FAST_TRANSLATION ? ${LLC_FLAGS_FAST}} ' + |
| 110 '${#OPT_LEVEL ? -O${OPT_LEVEL}} ' + | 110 '${#OPT_LEVEL ? -O${OPT_LEVEL}} ' + |
| 111 '${OPT_LEVEL == 0 ? -disable-fp-elim}', | 111 '${OPT_LEVEL == 0 ? -disable-fp-elim}', |
| 112 'SZ_FLAGS_EXTRA' : '--filetype=${outfiletype}', | |
| 112 | 113 |
| 113 # Opt level from command line (if any) | 114 # Opt level from command line (if any) |
| 114 'OPT_LEVEL' : '', | 115 'OPT_LEVEL' : '', |
| 115 | 116 |
| 116 # faster translation == slower code | 117 # faster translation == slower code |
| 117 'LLC_FLAGS_FAST' : '-O0' | 118 'LLC_FLAGS_FAST' : '-O0' |
| 118 # This, surprisingly, makes a measurable difference | 119 # This, surprisingly, makes a measurable difference |
| 119 ' -tail-merge-threshold=20', | 120 ' -tail-merge-threshold=20', |
| 120 | 121 |
| 121 'LLC_FLAGS': '${LLC_FLAGS_TARGET} ${LLC_FLAGS_COMMON} ${LLC_FLAGS_ARCH} ' + | 122 'LLC_FLAGS': '${LLC_FLAGS_TARGET} ${LLC_FLAGS_COMMON} ${LLC_FLAGS_ARCH} ' + |
| 122 '${LLC_FLAGS_EXTRA}', | 123 '${LLC_FLAGS_EXTRA}', |
| 123 | 124 |
| 124 # Note: this is only used in the unsandboxed case | 125 # Note: this is only used in the unsandboxed case |
| 125 'RUN_LLC' : '${LLVM_PNACL_LLC} ${LLC_FLAGS} ${LLC_MCPU} ' | 126 'RUN_LLC' : '${LLVM_PNACL_LLC} ${LLC_FLAGS} ${LLC_MCPU} ' |
| 126 '${input} -o ${output} ', | 127 '${input} -o ${output} ', |
| 128 'RUN_SZ': '${LLVM_PNACL_SZ} ${SZ_FLAGS_ARCH} ${SZ_FLAGS_EXTRA} ' | |
| 129 '${input} -o ${output}', | |
| 127 # Whether to stream the bitcode from a single FD in unsandboxed mode | 130 # Whether to stream the bitcode from a single FD in unsandboxed mode |
| 128 # (otherwise it will use concurrent file reads when using multithreaded module | 131 # (otherwise it will use concurrent file reads when using multithreaded module |
| 129 # splitting) | 132 # splitting) |
| 130 'STREAM_BITCODE' : '1', | 133 'STREAM_BITCODE' : '1', |
| 131 # Rate in bits/sec to stream the bitcode from sel_universal over SRPC | 134 # Rate in bits/sec to stream the bitcode from sel_universal over SRPC |
| 132 # for testing. Defaults to 1Gbps (effectively unlimited). | 135 # for testing. Defaults to 1Gbps (effectively unlimited). |
| 133 'BITCODE_STREAM_RATE' : '1000000000', | 136 'BITCODE_STREAM_RATE' : '1000000000', |
| 134 # Default to 0, which means unset by the user. In this cases the driver will | 137 # Default to 0, which means unset by the user. In this cases the driver will |
| 135 # use up to 4 modules if there are enough cores. If the user overrides, | 138 # use up to 4 modules if there are enough cores. If the user overrides, |
| 136 # use as many modules as specified (which could be only 1). | 139 # use as many modules as specified (which could be only 1). |
| 137 'SPLIT_MODULE' : '0', | 140 'SPLIT_MODULE' : '0', |
| 138 # Module split scheduling. 'dynamic' will produce non-deterministic results | 141 # Module split scheduling. 'dynamic' will produce non-deterministic results |
| 139 # with faster compilation, whereas 'static' will still use multiple cores but | 142 # with faster compilation, whereas 'static' will still use multiple cores but |
| 140 # will be deterministic and slightly slower. | 143 # will be deterministic and slightly slower. |
| 141 'SPLIT_MODULE_SCHED' : '${SANDBOXED ? dynamic : static}', | 144 'SPLIT_MODULE_SCHED' : '${SANDBOXED ? dynamic : static}', |
| 145 # Whether to (try to) use pnacl-sz for translation instead of pnacl-llc. | |
| 146 'USE_SZ' : '1', | |
|
Jim Stichnoth
2015/03/21 17:33:19
Oops this needs to default to '0'
| |
| 147 # Whether an option has been specified that Subzero can't (yet) handle. | |
| 148 'SZ_UNSUPPORTED' : '0', | |
| 149 # Subzero equivalent of SPLIT_MODULE, i.e. default # of translation threads. | |
| 150 'SZ_THREADS' : '0', | |
|
JF
2015/03/21 04:41:27
Can you use SPLIT_MODULE directly?
Jim Stichnoth
2015/03/21 17:33:19
The problem is that SPLIT_MODULE is used for sever
| |
| 142 } | 151 } |
| 143 | 152 |
| 144 | 153 |
| 145 TranslatorPatterns = [ | 154 TranslatorPatterns = [ |
| 146 ( '-o(.+)', "env.set('OUTPUT', pathtools.normalize($0))"), | 155 ( '-o(.+)', "env.set('OUTPUT', pathtools.normalize($0))"), |
| 147 ( ('-o', '(.+)'), "env.set('OUTPUT', pathtools.normalize($0))"), | 156 ( ('-o', '(.+)'), "env.set('OUTPUT', pathtools.normalize($0))"), |
| 148 | 157 |
| 149 ( '-pso', "env.set('TRANSLATE_PSO', '1')"), | 158 ( '-pso', "env.set('TRANSLATE_PSO', '1')"), |
| 150 | 159 |
| 151 ( '-S', "env.set('OUTPUT_TYPE', 's')"), # Stop at .s | 160 ( '-S', "env.set('OUTPUT_TYPE', 's')"), # Stop at .s |
| 152 ( '-c', "env.set('OUTPUT_TYPE', 'o')"), # Stop at .o | 161 ( '-c', "env.set('OUTPUT_TYPE', 'o')"), # Stop at .o |
| 153 | 162 |
| 154 # Expose a very limited set of llc flags. | 163 # Expose a very limited set of llc flags. |
| 155 # BE CAREFUL: anything added here can introduce skew between | 164 # BE CAREFUL: anything added here can introduce skew between |
| 156 # the pnacl-translate commandline tool and the in-browser translator. | 165 # the pnacl-translate commandline tool and the in-browser translator. |
| 157 # See: llvm/tools/pnacl-llc/srpc_main.cpp and | 166 # See: llvm/tools/pnacl-llc/srpc_main.cpp and |
| 158 # Chromium's plugin/pnacl_translate_thread.cc | 167 # Chromium's plugin/pnacl_translate_thread.cc |
| 159 ( '(-sfi-.+)', "env.append('LLC_FLAGS_EXTRA', $0)"), | 168 ( '(-sfi-.+)', "env.append('LLC_FLAGS_EXTRA', $0)\n" |
| 169 "env.set('SZ_UNSUPPORTED', '1')"), | |
| 160 ( '(-mtls-use-call)', "env.append('LLC_FLAGS_EXTRA', $0)"), | 170 ( '(-mtls-use-call)', "env.append('LLC_FLAGS_EXTRA', $0)"), |
| 161 ( '(-force-align-stack)', "env.append('LLC_FLAGS_EXTRA', $0)"), | 171 ( '(-force-align-stack)', "env.append('LLC_FLAGS_EXTRA', $0)"), |
| 162 # These flags are usually used for linktime dead code/data | 172 # These flags are usually used for linktime dead code/data |
| 163 # removal but also help with reloc overflows on ARM | 173 # removal but also help with reloc overflows on ARM |
| 164 ( '(-fdata-sections)', "env.append('LLC_FLAGS_EXTRA', '-data-sections')"), | 174 ( '(-fdata-sections)', "env.append('LLC_FLAGS_EXTRA', '-data-sections')\n" |
| 175 "env.append('SZ_FLAGS_EXTRA', $0)"), | |
|
JF
2015/03/21 04:41:27
Use LLC_FLAGS_EXTRA and teach subzero to accept th
Jim Stichnoth
2015/03/21 17:33:19
Well, it's more than LLC_FLAGS_EXTRA. There's LLC
jvoung (off chromium)
2015/03/21 18:06:29
Or -force-align-stack should also cause SZ_UNSUPPO
Jim Stichnoth
2015/03/22 04:20:42
We could also implement -force-align-stack in Subz
| |
| 165 ( '(-ffunction-sections)', | 176 ( '(-ffunction-sections)', |
| 166 "env.append('LLC_FLAGS_EXTRA', '-function-sections')"), | 177 "env.append('LLC_FLAGS_EXTRA', '-function-sections')\n" |
| 178 "env.append('SZ_FLAGS_EXTRA', $0)"), | |
| 167 ( '(--gc-sections)', "env.append('LD_FLAGS', $0)"), | 179 ( '(--gc-sections)', "env.append('LD_FLAGS', $0)"), |
| 168 ( '(-mattr=.*)', "env.append('LLC_FLAGS_EXTRA', $0)"), | 180 ( '(-mattr=.*)', "env.append('LLC_FLAGS_EXTRA', $0)\n" |
| 181 "env.append('SZ_FLAGS_EXTRA', $0)"), | |
|
jvoung (off chromium)
2015/03/21 18:06:30
The way mattr works is a bit different between LLC
Jim Stichnoth
2015/03/22 04:20:43
Ah, thanks. I added a Subzero issue for that.
htt
| |
| 169 ( '(-mcpu=.*)', "env.set('LLC_MCPU', '')\n" | 182 ( '(-mcpu=.*)', "env.set('LLC_MCPU', '')\n" |
| 170 "env.append('LLC_FLAGS_EXTRA', $0)"), | 183 "env.append('LLC_FLAGS_EXTRA', $0)"), |
| 171 ( '(-pnaclabi-verify=.*)', "env.append('LLC_FLAGS_EXTRA', $0)"), | 184 ( '(-pnaclabi-verify=.*)', "env.append('LLC_FLAGS_EXTRA', $0)"), |
| 172 ( '(-pnaclabi-verify-fatal-errors=.*)', "env.append('LLC_FLAGS_EXTRA', $0)"), | 185 ( '(-pnaclabi-verify-fatal-errors=.*)', "env.append('LLC_FLAGS_EXTRA', $0)"), |
| 173 # Allow overriding the -O level. | 186 # Allow overriding the -O level. |
| 174 ( '-O([0-3])', "env.set('OPT_LEVEL', $0)"), | 187 ( '-O([0-3])', "env.set('OPT_LEVEL', $0)"), |
| 175 | 188 |
| 176 # This adds arch specific flags to the llc invocation aimed at | 189 # This adds arch specific flags to the llc invocation aimed at |
| 177 # improving translation speed at the expense of code quality. | 190 # improving translation speed at the expense of code quality. |
| 178 ( '-translate-fast', "env.set('FAST_TRANSLATION', '1')"), | 191 ( '-translate-fast', "env.set('FAST_TRANSLATION', '1')"), |
| 192 # Allow Subzero. | |
| 193 ( '--sz', "env.set('USE_SZ', '1')"), | |
| 179 | 194 |
| 180 ( '-nostdlib', "env.set('USE_STDLIB', '0')"), | 195 ( '-nostdlib', "env.set('USE_STDLIB', '0')"), |
| 181 | 196 |
| 182 # Disables the default libraries. | 197 # Disables the default libraries. |
| 183 # This flag is needed for building libgcc_s.so. | 198 # This flag is needed for building libgcc_s.so. |
| 184 ( '-nodefaultlibs', "env.set('USE_DEFAULTLIBS', '0')"), | 199 ( '-nodefaultlibs', "env.set('USE_DEFAULTLIBS', '0')"), |
| 185 | 200 |
| 186 ( '--noirt', "env.set('USE_IRT', '0')"), | 201 ( '--noirt', "env.set('USE_IRT', '0')"), |
| 187 ( '--noirtshim', "env.set('USE_IRT_SHIM', '0')"), | 202 ( '--noirtshim', "env.set('USE_IRT_SHIM', '0')"), |
| 188 | 203 |
| 189 # Allowing zero-cost C++ exception handling causes a specific set of | 204 # Allowing zero-cost C++ exception handling causes a specific set of |
| 190 # native objects to get linked into the nexe. | 205 # native objects to get linked into the nexe. |
| 191 ( '--pnacl-allow-zerocost-eh', "env.set('ALLOW_ZEROCOST_CXX_EH', '1')"), | 206 ( '--pnacl-allow-zerocost-eh', "env.set('ALLOW_ZEROCOST_CXX_EH', '1')"), |
| 192 # TODO(mseaborn): Remove "--pnacl-allow-exceptions", replaced by | 207 # TODO(mseaborn): Remove "--pnacl-allow-exceptions", replaced by |
| 193 # "--pnacl-allow-zerocost-eh". | 208 # "--pnacl-allow-zerocost-eh". |
| 194 ( '--pnacl-allow-exceptions', "env.set('ALLOW_ZEROCOST_CXX_EH', '1')"), | 209 ( '--pnacl-allow-exceptions', "env.set('ALLOW_ZEROCOST_CXX_EH', '1')"), |
| 195 | 210 |
| 196 ( '--allow-llvm-bitcode-input', "env.set('ALLOW_LLVM_BITCODE_INPUT', '1')"), | 211 ( '--allow-llvm-bitcode-input', |
| 212 "env.set('ALLOW_LLVM_BITCODE_INPUT', '1')\n" | |
| 213 "env.set('SZ_UNSUPPORTED', '1')\n" | |
| 214 "env.append('SZ_FLAGS_EXTRA', '--bitcode-format=llvm')\n" | |
| 215 "env.append('SZ_FLAGS_EXTRA', '--build-on-read=0')"), | |
|
JF
2015/03/21 04:41:27
I don't understand why add SZ flags when it's unsu
Jim Stichnoth
2015/03/21 17:33:19
Whoops, that was left over from a trip down the --
| |
| 197 | 216 |
| 198 ( '-fPIC', "env.set('PIC', '1')"), | 217 ( '-fPIC', "env.set('PIC', '1')\n" |
| 218 "env.set('SZ_UNSUPPORTED', '1')"), | |
| 199 | 219 |
| 200 ( '(--build-id)', "env.append('LD_FLAGS', $0)"), | 220 ( '(--build-id)', "env.append('LD_FLAGS', $0)"), |
| 201 ( '-bitcode-stream-rate=([0-9]+)', "env.set('BITCODE_STREAM_RATE', $0)"), | 221 ( '-bitcode-stream-rate=([0-9]+)', "env.set('BITCODE_STREAM_RATE', $0)"), |
| 202 ( '-split-module=([0-9]+)', "env.set('SPLIT_MODULE', $0)"), | 222 ( '-split-module=([0-9]+)', "env.set('SPLIT_MODULE', $0)\n" |
| 223 "env.set('SZ_THREADS', $0)"), | |
| 203 ( '-split-module-sched=(.*)', "env.set('SPLIT_MODULE_SCHED', $0)"), | 224 ( '-split-module-sched=(.*)', "env.set('SPLIT_MODULE_SCHED', $0)"), |
| 204 ( '-no-stream-bitcode', "env.set('STREAM_BITCODE', '0')"), | 225 ( '-no-stream-bitcode', "env.set('STREAM_BITCODE', '0')"), |
| 205 | 226 |
| 206 # Treat general linker flags as inputs so they don't get re-ordered | 227 # Treat general linker flags as inputs so they don't get re-ordered |
| 207 ( '-Wl,(.*)', "env.append('INPUTS', *($0).split(','))"), | 228 ( '-Wl,(.*)', "env.append('INPUTS', *($0).split(','))"), |
| 208 | 229 |
| 209 ( '(-.*)', driver_tools.UnrecognizedOption), | 230 ( '(-.*)', driver_tools.UnrecognizedOption), |
| 210 ( '(.*)', "env.append('INPUTS', pathtools.normalize($0))"), | 231 ( '(.*)', "env.append('INPUTS', pathtools.normalize($0))"), |
| 211 ] | 232 ] |
| 212 | 233 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 259 # To translate x86-32 binary, we set -malign-double option so that the | 280 # To translate x86-32 binary, we set -malign-double option so that the |
| 260 # backend's datalayout matches the datalayout for "le32" used by the | 281 # backend's datalayout matches the datalayout for "le32" used by the |
| 261 # frontend. The le32 datalayout uses 8-byte alignment for the types i64 | 282 # frontend. The le32 datalayout uses 8-byte alignment for the types i64 |
| 262 # and double. i386's datalayout usually uses only 4-byte alignment for | 283 # and double. i386's datalayout usually uses only 4-byte alignment for |
| 263 # these types, but -malign-double changes that to 8-byte alignment. | 284 # these types, but -malign-double changes that to 8-byte alignment. |
| 264 # This is only needed when translating LLVM IR that hasn't had PNaCl's IR | 285 # This is only needed when translating LLVM IR that hasn't had PNaCl's IR |
| 265 # simplification passes applied to it. | 286 # simplification passes applied to it. |
| 266 'X8632_NONSFI': ['-malign-double'], | 287 'X8632_NONSFI': ['-malign-double'], |
| 267 } | 288 } |
| 268 env.set('LLC_FLAGS_ARCH', *llc_flags_map.get(env.getone('ARCH'), [])) | 289 env.set('LLC_FLAGS_ARCH', *llc_flags_map.get(env.getone('ARCH'), [])) |
| 290 env.set('SZ_FLAGS_ARCH', '') | |
| 269 # When linking against a host OS's libc (such as Linux glibc), don't | 291 # When linking against a host OS's libc (such as Linux glibc), don't |
| 270 # use %gs:0 to read the thread pointer because that won't be | 292 # use %gs:0 to read the thread pointer because that won't be |
| 271 # compatible with the libc's use of %gs:0. Similarly, Non-SFI Mode | 293 # compatible with the libc's use of %gs:0. Similarly, Non-SFI Mode |
| 272 # currently offers no optimized path for reading the thread pointer. | 294 # currently offers no optimized path for reading the thread pointer. |
| 273 if env.getone('TARGET_OS') != 'nacl' or env.getbool('NONSFI_NACL'): | 295 if env.getone('TARGET_OS') != 'nacl' or env.getbool('NONSFI_NACL'): |
| 274 env.append('LLC_FLAGS_ARCH', '-mtls-use-call') | 296 env.append('LLC_FLAGS_ARCH', '-mtls-use-call') |
| 297 # For Subzero, determine -target and -sandbox options. | |
| 298 env.append('SZ_FLAGS_ARCH', '--sandbox=' + | |
| 299 ('1' if env.getone('TARGET_OS') == 'nacl' else '0')) | |
| 300 env.append('SZ_FLAGS_ARCH', '--target=' + base_arch.lower()) | |
| 301 if base_arch != 'X8632': | |
| 302 env.set('SZ_UNSUPPORTED', '1') | |
|
jvoung (off chromium)
2015/03/21 18:06:29
The fallbacks are nice when, within the supported
Jim Stichnoth
2015/03/22 04:20:43
Sounds good, done.
| |
| 303 # This is a fine place to map OPT_LEVEL to the Subzero equivalent, with | |
| 304 # default of -O2. | |
| 305 sz_opt_map = { | |
| 306 '0': '-Om1', | |
| 307 '1': '-O2', | |
| 308 '2': '-O2', | |
| 309 } | |
| 310 env.append('SZ_FLAGS_ARCH', sz_opt_map.get(env.getone('OPT_LEVEL'), '-O2')) | |
| 311 # At this point, the only Subzero options left to set are -o, -filetype, and | |
| 312 # -threads. | |
| 275 | 313 |
| 276 | 314 |
| 277 def SetUpLinkOptions(): | 315 def SetUpLinkOptions(): |
| 278 if env.getbool('TRANSLATE_PSO'): | 316 if env.getbool('TRANSLATE_PSO'): |
| 279 # Using "-pie" rather than "-shared" has the effect of suppressing the | 317 # Using "-pie" rather than "-shared" has the effect of suppressing the |
| 280 # creation of a PLT and R_*_JUMP_SLOT relocations, which come from the | 318 # creation of a PLT and R_*_JUMP_SLOT relocations, which come from the |
| 281 # external symbol references that multi-threaded translation produces. | 319 # external symbol references that multi-threaded translation produces. |
| 282 env.append('LD_FLAGS', '-pie') | 320 env.append('LD_FLAGS', '-pie') |
| 283 return | 321 return |
| 284 | 322 |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 296 env.append('LD_FLAGS', '--rosegment-gap=0xc00000') | 334 env.append('LD_FLAGS', '--rosegment-gap=0xc00000') |
| 297 | 335 |
| 298 | 336 |
| 299 def main(argv): | 337 def main(argv): |
| 300 env.update(EXTRA_ENV) | 338 env.update(EXTRA_ENV) |
| 301 driver_tools.ParseArgs(argv, TranslatorPatterns) | 339 driver_tools.ParseArgs(argv, TranslatorPatterns) |
| 302 driver_tools.GetArch(required = True) | 340 driver_tools.GetArch(required = True) |
| 303 SetUpArch() | 341 SetUpArch() |
| 304 SetUpLinkOptions() | 342 SetUpLinkOptions() |
| 305 | 343 |
| 344 # Now commit to whether or not Subzero is used. | |
| 345 use_sz = env.getbool('USE_SZ') and not env.getbool('SZ_UNSUPPORTED') | |
| 346 | |
| 306 inputs = env.get('INPUTS') | 347 inputs = env.get('INPUTS') |
| 307 output = env.getone('OUTPUT') | 348 output = env.getone('OUTPUT') |
| 308 | 349 |
| 309 if len(inputs) == 0: | 350 if len(inputs) == 0: |
| 310 Log.Fatal("No input files") | 351 Log.Fatal("No input files") |
| 311 for path in inputs: | 352 for path in inputs: |
| 312 driver_tools.CheckPathLength(path) | 353 driver_tools.CheckPathLength(path) |
| 313 | 354 |
| 314 if output == '': | 355 if output == '': |
| 315 Log.Fatal("Please specify output file with -o") | 356 Log.Fatal("Please specify output file with -o") |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 348 # The x86->arm emulator is very flaky when threading is used, so don't | 389 # The x86->arm emulator is very flaky when threading is used, so don't |
| 349 # do module splitting when using it. | 390 # do module splitting when using it. |
| 350 env.set('SPLIT_MODULE', '1') | 391 env.set('SPLIT_MODULE', '1') |
| 351 else: | 392 else: |
| 352 # Do not set -streaming-bitcode for sandboxed mode, because it is already | 393 # Do not set -streaming-bitcode for sandboxed mode, because it is already |
| 353 # in the default command line. | 394 # in the default command line. |
| 354 if not env.getbool('SANDBOXED') and env.getbool('STREAM_BITCODE'): | 395 if not env.getbool('SANDBOXED') and env.getbool('STREAM_BITCODE'): |
| 355 env.append('LLC_FLAGS_EXTRA', '-streaming-bitcode') | 396 env.append('LLC_FLAGS_EXTRA', '-streaming-bitcode') |
| 356 modules = env.getone('SPLIT_MODULE') | 397 modules = env.getone('SPLIT_MODULE') |
| 357 module_sched = env.getone('SPLIT_MODULE_SCHED') | 398 module_sched = env.getone('SPLIT_MODULE_SCHED') |
| 399 sz_threads = env.getone('SZ_THREADS') | |
| 358 env.append('LLC_FLAGS_EXTRA', '-split-module=' + modules) | 400 env.append('LLC_FLAGS_EXTRA', '-split-module=' + modules) |
| 359 env.append('LD_FLAGS', '-split-module=' + modules) | 401 env.append('LD_FLAGS', '-split-module=' + ('1' if use_sz else modules)) |
| 360 env.append('LLC_FLAGS_EXTRA', '-split-module-sched=' + module_sched) | 402 env.append('LLC_FLAGS_EXTRA', '-split-module-sched=' + module_sched) |
| 403 env.append('SZ_FLAGS_EXTRA', '--threads=' + sz_threads) | |
| 361 | 404 |
| 362 # If there's a bitcode file, translate it now. | 405 # If there's a bitcode file, translate it now. |
| 363 tng = driver_tools.TempNameGen(inputs + bcfiles, output) | 406 tng = driver_tools.TempNameGen(inputs + bcfiles, output) |
| 364 output_type = env.getone('OUTPUT_TYPE') | 407 output_type = env.getone('OUTPUT_TYPE') |
| 365 if bcfile: | 408 if bcfile: |
| 366 sfile = None | 409 sfile = None |
| 367 if output_type == 's': | 410 if output_type == 's': |
| 368 sfile = output | 411 sfile = output |
| 369 | 412 |
| 370 ofile = None | 413 ofile = None |
| 371 if output_type == 'o': | 414 if output_type == 'o': |
| 372 ofile = output | 415 ofile = output |
| 373 elif output_type != 's': | 416 elif output_type != 's': |
| 374 ofile = tng.TempNameForInput(bcfile, 'o') | 417 ofile = tng.TempNameForInput(bcfile, 'o') |
| 375 | 418 |
| 376 if sfile: | 419 if sfile: |
| 377 RunLLC(bcfile, sfile, outfiletype='asm') | 420 RunLLC(bcfile, sfile, outfiletype='asm', use_sz=use_sz) |
| 378 if ofile: | 421 if ofile: |
| 379 RunAS(sfile, ofile) | 422 RunAS(sfile, ofile) |
| 380 else: | 423 else: |
| 381 RunLLC(bcfile, ofile, outfiletype='obj') | 424 RunLLC(bcfile, ofile, outfiletype='obj', use_sz=use_sz) |
| 382 else: | 425 else: |
| 383 ofile = None | 426 ofile = None |
| 384 | 427 |
| 385 # If we've been told to stop after translation, stop now. | 428 # If we've been told to stop after translation, stop now. |
| 386 if output_type in ('o','s'): | 429 if output_type in ('o','s'): |
| 387 return 0 | 430 return 0 |
| 388 | 431 |
| 432 if use_sz: | |
| 433 # Reset SPLIT_MODULE to 1 to fall back to normal linking behavior. | |
| 434 env.set('SPLIT_MODULE', '1') | |
| 435 | |
| 389 # Replace the bitcode file with __BITCODE__ in the input list | 436 # Replace the bitcode file with __BITCODE__ in the input list |
| 390 if bcfile: | 437 if bcfile: |
| 391 inputs = ListReplace(inputs, bcfile, '__BITCODE__') | 438 inputs = ListReplace(inputs, bcfile, '__BITCODE__') |
| 392 env.set('INPUTS', *inputs) | 439 env.set('INPUTS', *inputs) |
| 393 if int(env.getone('SPLIT_MODULE')) > 1: | 440 if int(env.getone('SPLIT_MODULE')) > 1: |
| 394 modules = int(env.getone('SPLIT_MODULE')) | 441 modules = int(env.getone('SPLIT_MODULE')) |
| 395 for i in range(1, modules): | 442 for i in range(1, modules): |
| 396 filename = ofile + '.module%d' % i | 443 filename = ofile + '.module%d' % i |
| 397 TempFiles.add(filename) | 444 TempFiles.add(filename) |
| 398 env.append('INPUTS', filename) | 445 env.append('INPUTS', filename) |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 439 + 'x86-32-%s/lib' % env.getone('TARGET_OS')) | 486 + 'x86-32-%s/lib' % env.getone('TARGET_OS')) |
| 440 args = ['gcc', '-m32', infile, '-o', outfile, | 487 args = ['gcc', '-m32', infile, '-o', outfile, |
| 441 os.path.join(lib_dir, 'unsandboxed_irt.o'), | 488 os.path.join(lib_dir, 'unsandboxed_irt.o'), |
| 442 os.path.join(lib_dir, 'irt_random.o'), | 489 os.path.join(lib_dir, 'irt_random.o'), |
| 443 os.path.join(lib_dir, 'irt_query_list.o'), | 490 os.path.join(lib_dir, 'irt_query_list.o'), |
| 444 '-lpthread'] | 491 '-lpthread'] |
| 445 if env.getone('TARGET_OS') == 'linux': | 492 if env.getone('TARGET_OS') == 'linux': |
| 446 args.append('-lrt') # For clock_gettime() | 493 args.append('-lrt') # For clock_gettime() |
| 447 driver_tools.Run(args) | 494 driver_tools.Run(args) |
| 448 | 495 |
| 449 def RunLLC(infile, outfile, outfiletype): | 496 def RunLLC(infile, outfile, outfiletype, use_sz): |
| 450 env.push() | 497 env.push() |
| 451 env.setmany(input=infile, output=outfile, outfiletype=outfiletype) | 498 env.setmany(input=infile, output=outfile, outfiletype=outfiletype) |
| 452 if env.getbool('SANDBOXED'): | 499 if env.getbool('SANDBOXED'): |
| 453 RunLLCSandboxed() | 500 RunLLCSandboxed() |
| 454 env.pop() | 501 env.pop() |
| 455 else: | 502 else: |
| 456 args = ["${RUN_LLC}"] | 503 args = ["${RUN_SZ}" if use_sz else "${RUN_LLC}"] |
| 457 if filetype.IsPNaClBitcode(infile): | 504 if filetype.IsPNaClBitcode(infile): |
| 458 args.append("-bitcode-format=pnacl") | 505 args.append("-bitcode-format=pnacl") |
| 459 elif filetype.IsLLVMBitcode(infile): | 506 elif filetype.IsLLVMBitcode(infile): |
| 460 if not env.getbool('ALLOW_LLVM_BITCODE_INPUT'): | 507 if not env.getbool('ALLOW_LLVM_BITCODE_INPUT'): |
| 461 Log.Fatal('Translator expects finalized PNaCl bitcode. ' | 508 Log.Fatal('Translator expects finalized PNaCl bitcode. ' |
| 462 'Pass --allow-llvm-bitcode-input to override.') | 509 'Pass --allow-llvm-bitcode-input to override.') |
| 463 driver_tools.Run(' '.join(args)) | 510 driver_tools.Run(' '.join(args)) |
| 464 env.pop() | 511 env.pop() |
| 465 return 0 | 512 return 0 |
| 466 | 513 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 535 The default output file type is .nexe, which assumes that the input file | 582 The default output file type is .nexe, which assumes that the input file |
| 536 type is .pexe. Native object files and assembly can also be generated | 583 type is .pexe. Native object files and assembly can also be generated |
| 537 with the -S and -c commandline flags. | 584 with the -S and -c commandline flags. |
| 538 | 585 |
| 539 ADVANCED OPTIONS: | 586 ADVANCED OPTIONS: |
| 540 -mattr=<+feat1,-feat2> Toggle specific cpu features on and off. | 587 -mattr=<+feat1,-feat2> Toggle specific cpu features on and off. |
| 541 -mcpu=<cpu-name> Target a specific cpu type. Tunes code as well as | 588 -mcpu=<cpu-name> Target a specific cpu type. Tunes code as well as |
| 542 turns cpu features on and off. | 589 turns cpu features on and off. |
| 543 -S Generate native assembly only. | 590 -S Generate native assembly only. |
| 544 -c Generate native object file only. | 591 -c Generate native object file only. |
| 545 --pnacl-sb Use the translator which runs inside the NaCl sandbox. | 592 --pnacl-sb Use the translator which runs inside the NaCl sandbox. |
|
jvoung (off chromium)
2015/03/21 18:06:30
Add --sz to the help message, if you want to adver
Jim Stichnoth
2015/03/22 04:20:42
Done.
| |
| 546 -O[0-3] Change translation-time optimization level. | 593 -O[0-3] Change translation-time optimization level. |
| 547 """ | 594 """ |
| OLD | NEW |