| 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' : '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', |
| 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)\n" |
| 172 "env.set('SZ_UNSUPPORTED', '1')"), |
| 162 # These flags are usually used for linktime dead code/data | 173 # These flags are usually used for linktime dead code/data |
| 163 # removal but also help with reloc overflows on ARM | 174 # removal but also help with reloc overflows on ARM |
| 164 ( '(-fdata-sections)', "env.append('LLC_FLAGS_EXTRA', '-data-sections')"), | 175 ( '(-fdata-sections)', "env.append('LLC_FLAGS_EXTRA', '-data-sections')\n" |
| 176 "env.append('SZ_FLAGS_EXTRA', $0)"), |
| 165 ( '(-ffunction-sections)', | 177 ( '(-ffunction-sections)', |
| 166 "env.append('LLC_FLAGS_EXTRA', '-function-sections')"), | 178 "env.append('LLC_FLAGS_EXTRA', '-function-sections')\n" |
| 179 "env.append('SZ_FLAGS_EXTRA', $0)"), |
| 167 ( '(--gc-sections)', "env.append('LD_FLAGS', $0)"), | 180 ( '(--gc-sections)', "env.append('LD_FLAGS', $0)"), |
| 168 ( '(-mattr=.*)', "env.append('LLC_FLAGS_EXTRA', $0)"), | 181 ( '(-mattr=.*)', "env.append('LLC_FLAGS_EXTRA', $0)\n" |
| 182 "env.append('SZ_FLAGS_EXTRA', $0)"), |
| 169 ( '(-mcpu=.*)', "env.set('LLC_MCPU', '')\n" | 183 ( '(-mcpu=.*)', "env.set('LLC_MCPU', '')\n" |
| 170 "env.append('LLC_FLAGS_EXTRA', $0)"), | 184 "env.append('LLC_FLAGS_EXTRA', $0)"), |
| 171 ( '(-pnaclabi-verify=.*)', "env.append('LLC_FLAGS_EXTRA', $0)"), | 185 ( '(-pnaclabi-verify=.*)', "env.append('LLC_FLAGS_EXTRA', $0)"), |
| 172 ( '(-pnaclabi-verify-fatal-errors=.*)', "env.append('LLC_FLAGS_EXTRA', $0)"), | 186 ( '(-pnaclabi-verify-fatal-errors=.*)', "env.append('LLC_FLAGS_EXTRA', $0)"), |
| 173 # Allow overriding the -O level. | 187 # Allow overriding the -O level. |
| 174 ( '-O([0-3])', "env.set('OPT_LEVEL', $0)"), | 188 ( '-O([0-3])', "env.set('OPT_LEVEL', $0)"), |
| 175 | 189 |
| 176 # This adds arch specific flags to the llc invocation aimed at | 190 # This adds arch specific flags to the llc invocation aimed at |
| 177 # improving translation speed at the expense of code quality. | 191 # improving translation speed at the expense of code quality. |
| 178 ( '-translate-fast', "env.set('FAST_TRANSLATION', '1')"), | 192 ( '-translate-fast', "env.set('FAST_TRANSLATION', '1')"), |
| 193 # Allow Subzero. |
| 194 ( '--sz', "env.set('USE_SZ', '1')"), |
| 179 | 195 |
| 180 ( '-nostdlib', "env.set('USE_STDLIB', '0')"), | 196 ( '-nostdlib', "env.set('USE_STDLIB', '0')"), |
| 181 | 197 |
| 182 # Disables the default libraries. | 198 # Disables the default libraries. |
| 183 # This flag is needed for building libgcc_s.so. | 199 # This flag is needed for building libgcc_s.so. |
| 184 ( '-nodefaultlibs', "env.set('USE_DEFAULTLIBS', '0')"), | 200 ( '-nodefaultlibs', "env.set('USE_DEFAULTLIBS', '0')"), |
| 185 | 201 |
| 186 ( '--noirt', "env.set('USE_IRT', '0')"), | 202 ( '--noirt', "env.set('USE_IRT', '0')"), |
| 187 ( '--noirtshim', "env.set('USE_IRT_SHIM', '0')"), | 203 ( '--noirtshim', "env.set('USE_IRT_SHIM', '0')"), |
| 188 | 204 |
| 189 # Allowing zero-cost C++ exception handling causes a specific set of | 205 # Allowing zero-cost C++ exception handling causes a specific set of |
| 190 # native objects to get linked into the nexe. | 206 # native objects to get linked into the nexe. |
| 191 ( '--pnacl-allow-zerocost-eh', "env.set('ALLOW_ZEROCOST_CXX_EH', '1')"), | 207 ( '--pnacl-allow-zerocost-eh', "env.set('ALLOW_ZEROCOST_CXX_EH', '1')"), |
| 192 # TODO(mseaborn): Remove "--pnacl-allow-exceptions", replaced by | 208 # TODO(mseaborn): Remove "--pnacl-allow-exceptions", replaced by |
| 193 # "--pnacl-allow-zerocost-eh". | 209 # "--pnacl-allow-zerocost-eh". |
| 194 ( '--pnacl-allow-exceptions', "env.set('ALLOW_ZEROCOST_CXX_EH', '1')"), | 210 ( '--pnacl-allow-exceptions', "env.set('ALLOW_ZEROCOST_CXX_EH', '1')"), |
| 195 | 211 |
| 196 ( '--allow-llvm-bitcode-input', "env.set('ALLOW_LLVM_BITCODE_INPUT', '1')"), | 212 ( '--allow-llvm-bitcode-input', |
| 213 "env.set('ALLOW_LLVM_BITCODE_INPUT', '1')\n" |
| 214 "env.set('SZ_UNSUPPORTED', '1')"), |
| 197 | 215 |
| 198 ( '-fPIC', "env.set('PIC', '1')"), | 216 ( '-fPIC', "env.set('PIC', '1')\n" |
| 217 "env.set('SZ_UNSUPPORTED', '1')"), |
| 199 | 218 |
| 200 ( '(--build-id)', "env.append('LD_FLAGS', $0)"), | 219 ( '(--build-id)', "env.append('LD_FLAGS', $0)"), |
| 201 ( '-bitcode-stream-rate=([0-9]+)', "env.set('BITCODE_STREAM_RATE', $0)"), | 220 ( '-bitcode-stream-rate=([0-9]+)', "env.set('BITCODE_STREAM_RATE', $0)"), |
| 202 ( '-split-module=([0-9]+)', "env.set('SPLIT_MODULE', $0)"), | 221 ( '-split-module=([0-9]+)', "env.set('SPLIT_MODULE', $0)\n" |
| 222 "env.set('SZ_THREADS', $0)"), |
| 203 ( '-split-module-sched=(.*)', "env.set('SPLIT_MODULE_SCHED', $0)"), | 223 ( '-split-module-sched=(.*)', "env.set('SPLIT_MODULE_SCHED', $0)"), |
| 204 ( '-no-stream-bitcode', "env.set('STREAM_BITCODE', '0')"), | 224 ( '-no-stream-bitcode', "env.set('STREAM_BITCODE', '0')"), |
| 205 | 225 |
| 206 # Treat general linker flags as inputs so they don't get re-ordered | 226 # Treat general linker flags as inputs so they don't get re-ordered |
| 207 ( '-Wl,(.*)', "env.append('INPUTS', *($0).split(','))"), | 227 ( '-Wl,(.*)', "env.append('INPUTS', *($0).split(','))"), |
| 208 | 228 |
| 209 ( '(-.*)', driver_tools.UnrecognizedOption), | 229 ( '(-.*)', driver_tools.UnrecognizedOption), |
| 210 ( '(.*)', "env.append('INPUTS', pathtools.normalize($0))"), | 230 ( '(.*)', "env.append('INPUTS', pathtools.normalize($0))"), |
| 211 ] | 231 ] |
| 212 | 232 |
| (...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 | 279 # 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 | 280 # backend's datalayout matches the datalayout for "le32" used by the |
| 261 # frontend. The le32 datalayout uses 8-byte alignment for the types i64 | 281 # 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 | 282 # and double. i386's datalayout usually uses only 4-byte alignment for |
| 263 # these types, but -malign-double changes that to 8-byte alignment. | 283 # 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 | 284 # This is only needed when translating LLVM IR that hasn't had PNaCl's IR |
| 265 # simplification passes applied to it. | 285 # simplification passes applied to it. |
| 266 'X8632_NONSFI': ['-malign-double'], | 286 'X8632_NONSFI': ['-malign-double'], |
| 267 } | 287 } |
| 268 env.set('LLC_FLAGS_ARCH', *llc_flags_map.get(env.getone('ARCH'), [])) | 288 env.set('LLC_FLAGS_ARCH', *llc_flags_map.get(env.getone('ARCH'), [])) |
| 289 env.set('SZ_FLAGS_ARCH', '') |
| 269 # When linking against a host OS's libc (such as Linux glibc), don't | 290 # 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 | 291 # 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 | 292 # compatible with the libc's use of %gs:0. Similarly, Non-SFI Mode |
| 272 # currently offers no optimized path for reading the thread pointer. | 293 # currently offers no optimized path for reading the thread pointer. |
| 273 if env.getone('TARGET_OS') != 'nacl' or env.getbool('NONSFI_NACL'): | 294 if env.getone('TARGET_OS') != 'nacl' or env.getbool('NONSFI_NACL'): |
| 274 env.append('LLC_FLAGS_ARCH', '-mtls-use-call') | 295 env.append('LLC_FLAGS_ARCH', '-mtls-use-call') |
| 296 # For Subzero, determine -target and -sandbox options. |
| 297 env.append('SZ_FLAGS_ARCH', '--sandbox=' + |
| 298 ('1' if env.getone('TARGET_OS') == 'nacl' else '0')) |
| 299 env.append('SZ_FLAGS_ARCH', '--target=' + base_arch.lower()) |
| 300 if base_arch != 'X8632': |
| 301 env.set('SZ_UNSUPPORTED', '1') |
| 302 # Hard-fail on an unsupported architecture. |
| 303 if env.getbool('USE_SZ'): |
| 304 Log.Fatal('Unsupported architecture when using --sz: ' + base_arch) |
| 305 # This is a fine place to map OPT_LEVEL to the Subzero equivalent, with |
| 306 # default of -O2. |
| 307 sz_opt_map = { |
| 308 '0': '-Om1', |
| 309 '1': '-O2', |
| 310 '2': '-O2', |
| 311 } |
| 312 env.append('SZ_FLAGS_ARCH', sz_opt_map.get(env.getone('OPT_LEVEL'), '-O2')) |
| 313 # At this point, the only Subzero options left to set are -o, -filetype, and |
| 314 # -threads. |
| 275 | 315 |
| 276 | 316 |
| 277 def SetUpLinkOptions(): | 317 def SetUpLinkOptions(): |
| 278 if env.getbool('TRANSLATE_PSO'): | 318 if env.getbool('TRANSLATE_PSO'): |
| 279 # Using "-pie" rather than "-shared" has the effect of suppressing the | 319 # 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 | 320 # creation of a PLT and R_*_JUMP_SLOT relocations, which come from the |
| 281 # external symbol references that multi-threaded translation produces. | 321 # external symbol references that multi-threaded translation produces. |
| 282 env.append('LD_FLAGS', '-pie') | 322 env.append('LD_FLAGS', '-pie') |
| 283 return | 323 return |
| 284 | 324 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 296 env.append('LD_FLAGS', '--rosegment-gap=0xc00000') | 336 env.append('LD_FLAGS', '--rosegment-gap=0xc00000') |
| 297 | 337 |
| 298 | 338 |
| 299 def main(argv): | 339 def main(argv): |
| 300 env.update(EXTRA_ENV) | 340 env.update(EXTRA_ENV) |
| 301 driver_tools.ParseArgs(argv, TranslatorPatterns) | 341 driver_tools.ParseArgs(argv, TranslatorPatterns) |
| 302 driver_tools.GetArch(required = True) | 342 driver_tools.GetArch(required = True) |
| 303 SetUpArch() | 343 SetUpArch() |
| 304 SetUpLinkOptions() | 344 SetUpLinkOptions() |
| 305 | 345 |
| 346 # Now commit to whether or not Subzero is used. |
| 347 use_sz = env.getbool('USE_SZ') and not env.getbool('SZ_UNSUPPORTED') |
| 348 |
| 306 inputs = env.get('INPUTS') | 349 inputs = env.get('INPUTS') |
| 307 output = env.getone('OUTPUT') | 350 output = env.getone('OUTPUT') |
| 308 | 351 |
| 309 if len(inputs) == 0: | 352 if len(inputs) == 0: |
| 310 Log.Fatal("No input files") | 353 Log.Fatal("No input files") |
| 311 for path in inputs: | 354 for path in inputs: |
| 312 driver_tools.CheckPathLength(path) | 355 driver_tools.CheckPathLength(path) |
| 313 | 356 |
| 314 if output == '': | 357 if output == '': |
| 315 Log.Fatal("Please specify output file with -o") | 358 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 | 391 # The x86->arm emulator is very flaky when threading is used, so don't |
| 349 # do module splitting when using it. | 392 # do module splitting when using it. |
| 350 env.set('SPLIT_MODULE', '1') | 393 env.set('SPLIT_MODULE', '1') |
| 351 else: | 394 else: |
| 352 # Do not set -streaming-bitcode for sandboxed mode, because it is already | 395 # Do not set -streaming-bitcode for sandboxed mode, because it is already |
| 353 # in the default command line. | 396 # in the default command line. |
| 354 if not env.getbool('SANDBOXED') and env.getbool('STREAM_BITCODE'): | 397 if not env.getbool('SANDBOXED') and env.getbool('STREAM_BITCODE'): |
| 355 env.append('LLC_FLAGS_EXTRA', '-streaming-bitcode') | 398 env.append('LLC_FLAGS_EXTRA', '-streaming-bitcode') |
| 356 modules = env.getone('SPLIT_MODULE') | 399 modules = env.getone('SPLIT_MODULE') |
| 357 module_sched = env.getone('SPLIT_MODULE_SCHED') | 400 module_sched = env.getone('SPLIT_MODULE_SCHED') |
| 401 sz_threads = env.getone('SZ_THREADS') |
| 358 env.append('LLC_FLAGS_EXTRA', '-split-module=' + modules) | 402 env.append('LLC_FLAGS_EXTRA', '-split-module=' + modules) |
| 359 env.append('LD_FLAGS', '-split-module=' + modules) | 403 env.append('LD_FLAGS', '-split-module=' + ('1' if use_sz else modules)) |
| 360 env.append('LLC_FLAGS_EXTRA', '-split-module-sched=' + module_sched) | 404 env.append('LLC_FLAGS_EXTRA', '-split-module-sched=' + module_sched) |
| 405 env.append('SZ_FLAGS_EXTRA', '--threads=' + sz_threads) |
| 361 | 406 |
| 362 # If there's a bitcode file, translate it now. | 407 # If there's a bitcode file, translate it now. |
| 363 tng = driver_tools.TempNameGen(inputs + bcfiles, output) | 408 tng = driver_tools.TempNameGen(inputs + bcfiles, output) |
| 364 output_type = env.getone('OUTPUT_TYPE') | 409 output_type = env.getone('OUTPUT_TYPE') |
| 365 if bcfile: | 410 if bcfile: |
| 366 sfile = None | 411 sfile = None |
| 367 if output_type == 's': | 412 if output_type == 's': |
| 368 sfile = output | 413 sfile = output |
| 369 | 414 |
| 370 ofile = None | 415 ofile = None |
| 371 if output_type == 'o': | 416 if output_type == 'o': |
| 372 ofile = output | 417 ofile = output |
| 373 elif output_type != 's': | 418 elif output_type != 's': |
| 374 ofile = tng.TempNameForInput(bcfile, 'o') | 419 ofile = tng.TempNameForInput(bcfile, 'o') |
| 375 | 420 |
| 376 if sfile: | 421 if sfile: |
| 377 RunLLC(bcfile, sfile, outfiletype='asm') | 422 RunLLC(bcfile, sfile, outfiletype='asm', use_sz=use_sz) |
| 378 if ofile: | 423 if ofile: |
| 379 RunAS(sfile, ofile) | 424 RunAS(sfile, ofile) |
| 380 else: | 425 else: |
| 381 RunLLC(bcfile, ofile, outfiletype='obj') | 426 RunLLC(bcfile, ofile, outfiletype='obj', use_sz=use_sz) |
| 382 else: | 427 else: |
| 383 ofile = None | 428 ofile = None |
| 384 | 429 |
| 385 # If we've been told to stop after translation, stop now. | 430 # If we've been told to stop after translation, stop now. |
| 386 if output_type in ('o','s'): | 431 if output_type in ('o','s'): |
| 387 return 0 | 432 return 0 |
| 388 | 433 |
| 434 if use_sz: |
| 435 # Reset SPLIT_MODULE to 1 to fall back to normal linking behavior. |
| 436 env.set('SPLIT_MODULE', '1') |
| 437 |
| 389 # Replace the bitcode file with __BITCODE__ in the input list | 438 # Replace the bitcode file with __BITCODE__ in the input list |
| 390 if bcfile: | 439 if bcfile: |
| 391 inputs = ListReplace(inputs, bcfile, '__BITCODE__') | 440 inputs = ListReplace(inputs, bcfile, '__BITCODE__') |
| 392 env.set('INPUTS', *inputs) | 441 env.set('INPUTS', *inputs) |
| 393 if int(env.getone('SPLIT_MODULE')) > 1: | 442 if int(env.getone('SPLIT_MODULE')) > 1: |
| 394 modules = int(env.getone('SPLIT_MODULE')) | 443 modules = int(env.getone('SPLIT_MODULE')) |
| 395 for i in range(1, modules): | 444 for i in range(1, modules): |
| 396 filename = ofile + '.module%d' % i | 445 filename = ofile + '.module%d' % i |
| 397 TempFiles.add(filename) | 446 TempFiles.add(filename) |
| 398 env.append('INPUTS', filename) | 447 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')) | 488 + 'x86-32-%s/lib' % env.getone('TARGET_OS')) |
| 440 args = ['gcc', '-m32', infile, '-o', outfile, | 489 args = ['gcc', '-m32', infile, '-o', outfile, |
| 441 os.path.join(lib_dir, 'unsandboxed_irt.o'), | 490 os.path.join(lib_dir, 'unsandboxed_irt.o'), |
| 442 os.path.join(lib_dir, 'irt_random.o'), | 491 os.path.join(lib_dir, 'irt_random.o'), |
| 443 os.path.join(lib_dir, 'irt_query_list.o'), | 492 os.path.join(lib_dir, 'irt_query_list.o'), |
| 444 '-lpthread'] | 493 '-lpthread'] |
| 445 if env.getone('TARGET_OS') == 'linux': | 494 if env.getone('TARGET_OS') == 'linux': |
| 446 args.append('-lrt') # For clock_gettime() | 495 args.append('-lrt') # For clock_gettime() |
| 447 driver_tools.Run(args) | 496 driver_tools.Run(args) |
| 448 | 497 |
| 449 def RunLLC(infile, outfile, outfiletype): | 498 def RunLLC(infile, outfile, outfiletype, use_sz): |
| 450 env.push() | 499 env.push() |
| 451 env.setmany(input=infile, output=outfile, outfiletype=outfiletype) | 500 env.setmany(input=infile, output=outfile, outfiletype=outfiletype) |
| 452 if env.getbool('SANDBOXED'): | 501 if env.getbool('SANDBOXED'): |
| 453 RunLLCSandboxed() | 502 RunLLCSandboxed() |
| 454 env.pop() | 503 env.pop() |
| 455 else: | 504 else: |
| 456 args = ["${RUN_LLC}"] | 505 args = ["${RUN_SZ}" if use_sz else "${RUN_LLC}"] |
| 457 if filetype.IsPNaClBitcode(infile): | 506 if filetype.IsPNaClBitcode(infile): |
| 458 args.append("-bitcode-format=pnacl") | 507 args.append("-bitcode-format=pnacl") |
| 459 elif filetype.IsLLVMBitcode(infile): | 508 elif filetype.IsLLVMBitcode(infile): |
| 460 if not env.getbool('ALLOW_LLVM_BITCODE_INPUT'): | 509 if not env.getbool('ALLOW_LLVM_BITCODE_INPUT'): |
| 461 Log.Fatal('Translator expects finalized PNaCl bitcode. ' | 510 Log.Fatal('Translator expects finalized PNaCl bitcode. ' |
| 462 'Pass --allow-llvm-bitcode-input to override.') | 511 'Pass --allow-llvm-bitcode-input to override.') |
| 463 driver_tools.Run(' '.join(args)) | 512 driver_tools.Run(' '.join(args)) |
| 464 env.pop() | 513 env.pop() |
| 465 return 0 | 514 return 0 |
| 466 | 515 |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 536 type is .pexe. Native object files and assembly can also be generated | 585 type is .pexe. Native object files and assembly can also be generated |
| 537 with the -S and -c commandline flags. | 586 with the -S and -c commandline flags. |
| 538 | 587 |
| 539 ADVANCED OPTIONS: | 588 ADVANCED OPTIONS: |
| 540 -mattr=<+feat1,-feat2> Toggle specific cpu features on and off. | 589 -mattr=<+feat1,-feat2> Toggle specific cpu features on and off. |
| 541 -mcpu=<cpu-name> Target a specific cpu type. Tunes code as well as | 590 -mcpu=<cpu-name> Target a specific cpu type. Tunes code as well as |
| 542 turns cpu features on and off. | 591 turns cpu features on and off. |
| 543 -S Generate native assembly only. | 592 -S Generate native assembly only. |
| 544 -c Generate native object file only. | 593 -c Generate native object file only. |
| 545 --pnacl-sb Use the translator which runs inside the NaCl sandbox. | 594 --pnacl-sb Use the translator which runs inside the NaCl sandbox. |
| 595 Applies to both pnacl-llc and pnacl-sz translators. |
| 546 -O[0-3] Change translation-time optimization level. | 596 -O[0-3] Change translation-time optimization level. |
| 547 """ | 597 """ |
| OLD | NEW |