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 # IMPORTANT NOTE: If you make local mods to this file, you must run: | 6 # IMPORTANT NOTE: If you make local mods to this file, you must run: |
| 7 # % pnacl/build.sh driver | 7 # % pnacl/build.sh driver |
| 8 # in order for them to take effect in the scons build. This command | 8 # in order for them to take effect in the scons build. This command |
| 9 # updates the copy in the toolchain/ tree. | 9 # updates the copy in the toolchain/ tree. |
| 10 # | 10 # |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 117 ('-arm-reserve-r9 -sfi-disable-cp ' + | 117 ('-arm-reserve-r9 -sfi-disable-cp ' + |
| 118 '-sfi-load -sfi-store -sfi-stack -sfi-branch -sfi-data ' + | 118 '-sfi-load -sfi-store -sfi-stack -sfi-branch -sfi-data ' + |
| 119 '-no-inline-jumptables -float-abi=hard'), | 119 '-no-inline-jumptables -float-abi=hard'), |
| 120 | 120 |
| 121 'LLC_FLAGS_X8632' : '', | 121 'LLC_FLAGS_X8632' : '', |
| 122 'LLC_FLAGS_X8664' : '', | 122 'LLC_FLAGS_X8664' : '', |
| 123 | 123 |
| 124 'LLC_FLAGS_MIPS32': '-sfi-load -sfi-store -sfi-stack -sfi-branch -sfi-data', | 124 'LLC_FLAGS_MIPS32': '-sfi-load -sfi-store -sfi-stack -sfi-branch -sfi-data', |
| 125 | 125 |
| 126 # LLC flags which set the target and output type. | 126 # LLC flags which set the target and output type. |
| 127 # These are handled separately by libLTO. | 127 # These are handled separately by libLTO. |
|
Derek Schuff
2013/03/06 21:10:12
this line of the comment still relevant?
jvoung (off chromium)
2013/03/06 21:26:58
Probably not (the libLTO part?). It sounds like l
| |
| 128 'LLC_FLAGS_TARGET' : '-mcpu=${LLC_MCPU} ' + | 128 'LLC_FLAGS_TARGET' : '-mtriple=${TRIPLE} ' + |
| 129 '-mtriple=${TRIPLE} ' + | |
| 130 '-filetype=${filetype}', | 129 '-filetype=${filetype}', |
| 131 # Append additional non-default flags here. | 130 # Append additional non-default flags here. |
| 132 'LLC_FLAGS_EXTRA' : '${#OPT_LEVEL ? -O${OPT_LEVEL}} ' + | 131 'LLC_FLAGS_EXTRA' : '${FAST_TRANSLATION ? ${LLC_FLAGS_FAST}} ' + |
| 132 '${#OPT_LEVEL ? -O${OPT_LEVEL}} ' + | |
| 133 '${OPT_LEVEL == 0 ? -disable-fp-elim}', | 133 '${OPT_LEVEL == 0 ? -disable-fp-elim}', |
| 134 | 134 |
| 135 # Opt level from command line (if any) | 135 # Opt level from command line (if any) |
| 136 'OPT_LEVEL' : '', | 136 'OPT_LEVEL' : '', |
| 137 | 137 |
| 138 # slower translation == faster code | |
| 139 'LLC_FLAGS_SLOW': | |
| 140 # Due to a quadratic algorithm used for tail merging | |
| 141 # capping it at 50 helps speed up translation | |
| 142 '-tail-merge-threshold=50', | |
| 143 | |
| 144 # faster translation == slower code | 138 # faster translation == slower code |
| 145 'LLC_FLAGS_FAST' : '${LLC_FLAGS_FAST_%ARCH%}', | 139 'LLC_FLAGS_FAST' : '${LLC_FLAGS_FAST_%ARCH%}', |
| 146 | 140 |
| 147 'LLC_FLAGS_FAST_X8632': | 141 'LLC_FLAGS_FAST_X8632': '-O0 ' + |
| 148 '-O0 ' + | 142 # This, surprisingly, makes a measurable difference |
| 149 # This, surprisingly, makes a measurable difference | |
| 150 '-tail-merge-threshold=20', | 143 '-tail-merge-threshold=20', |
| 151 'LLC_FLAGS_FAST_X8664': | 144 'LLC_FLAGS_FAST_X8664': '-O0 ' + |
| 152 '-O0 ' + | |
| 153 '-tail-merge-threshold=20', | 145 '-tail-merge-threshold=20', |
| 154 'LLC_FLAGS_FAST_ARM': | 146 'LLC_FLAGS_FAST_ARM': '-O0 ' + |
| 155 # due to slow turn around times ARM settings have not been explored in depth | |
| 156 '-O0 ' + | |
| 157 '-tail-merge-threshold=20', | 147 '-tail-merge-threshold=20', |
| 158 'LLC_FLAGS_FAST_MIPS32': '-fast-isel -tail-merge-threshold=20', | 148 'LLC_FLAGS_FAST_MIPS32': '-fast-isel -tail-merge-threshold=20', |
| 159 | 149 |
| 160 'LLC_FLAGS': '${LLC_FLAGS_TARGET} ' + | 150 'LLC_FLAGS': '${LLC_FLAGS_TARGET} ${LLC_FLAGS_COMMON} ${LLC_FLAGS_%ARCH%} ' + |
| 161 '${LLC_FLAGS_COMMON} ' + | |
| 162 '${LLC_FLAGS_%ARCH%} ' + | |
| 163 '${FAST_TRANSLATION ? ${LLC_FLAGS_FAST} : ${LLC_FLAGS_SLOW}} ' + | |
| 164 '${LLC_FLAGS_EXTRA}', | 151 '${LLC_FLAGS_EXTRA}', |
| 165 | 152 |
| 166 # CPU that is representative of baseline feature requirements for NaCl | 153 # CPU that is representative of baseline feature requirements for NaCl |
| 167 # and/or chrome. We may want to make this more like "-mtune" | 154 # and/or chrome. We may want to make this more like "-mtune" |
| 168 # by specifying both "-mcpu=X" and "-mattr=+feat1,-feat2,...". | 155 # by specifying both "-mcpu=X" and "-mattr=+feat1,-feat2,...". |
| 169 # Note: this may be different from the in-browser translator, which may | 156 # Note: this may be different from the in-browser translator, which may |
| 170 # do auto feature detection based on CPUID, but constrained by what is | 157 # do auto feature detection based on CPUID, but constrained by what is |
| 171 # accepted by NaCl validators. | 158 # accepted by NaCl validators. |
| 172 'LLC_MCPU' : '${LLC_MCPU_%ARCH%}', | 159 'LLC_MCPU' : '-mcpu=${LLC_MCPU_%ARCH%}', |
| 173 'LLC_MCPU_ARM' : 'cortex-a8', | 160 'LLC_MCPU_ARM' : 'cortex-a8', |
| 174 'LLC_MCPU_X8632' : 'pentium4', | 161 'LLC_MCPU_X8632' : 'pentium4', |
| 175 'LLC_MCPU_X8664' : 'core2', | 162 'LLC_MCPU_X8664' : 'core2', |
| 176 'LLC_MCPU_MIPS32' : 'mips32r2', | 163 'LLC_MCPU_MIPS32' : 'mips32r2', |
| 177 | 164 |
| 178 # Note: this is only used in the unsandboxed case | 165 # Note: this is only used in the unsandboxed case |
| 179 'RUN_LLC' : '${LLVM_LLC} ${LLC_FLAGS} ${input} -o ${output} ' + | 166 'RUN_LLC' : '${LLVM_LLC} ${LLC_FLAGS} ${LLC_MCPU} ' |
| 167 '${input} -o ${output} ' + | |
| 180 '-metadata-text ${output}.meta', | 168 '-metadata-text ${output}.meta', |
| 181 # Rate in bits/sec to stream the bitcode from sel_universal over SRPC | 169 # Rate in bits/sec to stream the bitcode from sel_universal over SRPC |
| 182 # for testing. Defaults to 1Gbps (effectively unlimited). | 170 # for testing. Defaults to 1Gbps (effectively unlimited). |
| 183 'BITCODE_STREAM_RATE' : '1000000000', | 171 'BITCODE_STREAM_RATE' : '1000000000', |
| 184 } | 172 } |
| 185 | 173 |
| 186 TranslatorPatterns = [ | 174 TranslatorPatterns = [ |
| 187 ( '-o(.+)', "env.set('OUTPUT', pathtools.normalize($0))"), | 175 ( '-o(.+)', "env.set('OUTPUT', pathtools.normalize($0))"), |
| 188 ( ('-o', '(.+)'), "env.set('OUTPUT', pathtools.normalize($0))"), | 176 ( ('-o', '(.+)'), "env.set('OUTPUT', pathtools.normalize($0))"), |
| 189 | 177 |
| 190 ( '-S', "env.set('OUTPUT_TYPE', 's')"), # Stop at .s | 178 ( '-S', "env.set('OUTPUT_TYPE', 's')"), # Stop at .s |
| 191 ( '-c', "env.set('OUTPUT_TYPE', 'o')"), # Stop at .o | 179 ( '-c', "env.set('OUTPUT_TYPE', 'o')"), # Stop at .o |
| 192 | 180 |
| 193 # Expose a very limited set of llc flags. | 181 # Expose a very limited set of llc flags. |
| 194 ( '(-sfi-.+)', "env.append('LLC_FLAGS_EXTRA', $0)"), | 182 ( '(-sfi-.+)', "env.append('LLC_FLAGS_EXTRA', $0)"), |
| 195 ( '(-mtls-use-call)', "env.append('LLC_FLAGS_EXTRA', $0)"), | 183 ( '(-mtls-use-call)', "env.append('LLC_FLAGS_EXTRA', $0)"), |
| 196 # These flags are usually used for linktime dead code/data | 184 # These flags are usually used for linktime dead code/data |
| 197 # removal but also help with reloc overflows on ARM | 185 # removal but also help with reloc overflows on ARM |
| 198 ( '(-fdata-sections)', "env.append('LLC_FLAGS_EXTRA', $0)"), | 186 ( '(-fdata-sections)', "env.append('LLC_FLAGS_EXTRA', $0)"), |
| 199 ( '(-ffunction-sections)', "env.append('LLC_FLAGS_EXTRA', $0)"), | 187 ( '(-ffunction-sections)', "env.append('LLC_FLAGS_EXTRA', $0)"), |
| 200 ( '(--gc-sections)', "env.append('LD_FLAGS', $0)"), | 188 ( '(--gc-sections)', "env.append('LD_FLAGS', $0)"), |
| 201 ( '(-mattr=.*)', "env.append('LLC_FLAGS_EXTRA', $0)"), | 189 ( '(-mattr=.*)', "env.append('LLC_FLAGS_EXTRA', $0)"), |
| 202 ( '-mcpu=(.*)', "env.set('LLC_MCPU', $0)"), | 190 ( '(-mcpu=.*)', "env.set('LLC_MCPU', '')\n" |
| 191 "env.append('LLC_FLAGS_EXTRA', $0)"), | |
| 203 # Allow overriding the -O level. | 192 # Allow overriding the -O level. |
| 204 ( '-O([0-3])', "env.set('OPT_LEVEL', $0)"), | 193 ( '-O([0-3])', "env.set('OPT_LEVEL', $0)"), |
| 205 | 194 |
| 206 # This adds arch specific flags to the llc invocation aimed at | 195 # This adds arch specific flags to the llc invocation aimed at |
| 207 # improving translation speed at the expense of code quality. | 196 # improving translation speed at the expense of code quality. |
| 208 ( '-translate-fast', "env.set('FAST_TRANSLATION', '1')"), | 197 ( '-translate-fast', "env.set('FAST_TRANSLATION', '1')"), |
| 209 | 198 |
| 210 # If translating a .pexe which was linked statically against | 199 # If translating a .pexe which was linked statically against |
| 211 # glibc, then you must do pnacl-translate -static. This will | 200 # glibc, then you must do pnacl-translate -static. This will |
| 212 # be removed once GLibC is actually statically linked. | 201 # be removed once GLibC is actually statically linked. |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 458 | 447 |
| 459 def ToggleDefaultCommandlineLD(inputs, infile): | 448 def ToggleDefaultCommandlineLD(inputs, infile): |
| 460 if env.getbool('USE_DEFAULT_CMD_LINE'): | 449 if env.getbool('USE_DEFAULT_CMD_LINE'): |
| 461 reason, non_standard = RequiresNonStandardLDCommandline(inputs, infile) | 450 reason, non_standard = RequiresNonStandardLDCommandline(inputs, infile) |
| 462 if non_standard: | 451 if non_standard: |
| 463 Log.Info(reason + ' -- not using default SRPC commandline for LD!') | 452 Log.Info(reason + ' -- not using default SRPC commandline for LD!') |
| 464 inputs.append('--pnacl-driver-set-USE_DEFAULT_CMD_LINE=0') | 453 inputs.append('--pnacl-driver-set-USE_DEFAULT_CMD_LINE=0') |
| 465 | 454 |
| 466 | 455 |
| 467 def RequiresNonStandardLLCCommandline(): | 456 def RequiresNonStandardLLCCommandline(): |
| 468 if env.getbool('FAST_TRANSLATION'): | |
| 469 return ('FAST_TRANSLATION', True) | |
| 470 | |
| 471 extra_flags = env.get('LLC_FLAGS_EXTRA') | 457 extra_flags = env.get('LLC_FLAGS_EXTRA') |
| 472 if extra_flags != []: | 458 if extra_flags != []: |
| 473 reason = 'Has additional llc flags: %s' % extra_flags | 459 reason = 'Has additional llc flags: %s' % extra_flags |
| 474 return (reason, True) | 460 return (reason, True) |
| 475 | 461 |
| 476 return (None, False) | 462 return (None, False) |
| 477 | 463 |
| 478 | 464 |
| 479 def UseDefaultCommandlineLLC(): | 465 def UseDefaultCommandlineLLC(): |
| 480 if not env.getbool('USE_DEFAULT_CMD_LINE'): | 466 if not env.getbool('USE_DEFAULT_CMD_LINE'): |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 516 # As a side effect, this creates a temporary file | 502 # As a side effect, this creates a temporary file |
| 517 if not env.getbool('SAVE_TEMPS'): | 503 if not env.getbool('SAVE_TEMPS'): |
| 518 TempFiles.add(outfile + '.meta') | 504 TempFiles.add(outfile + '.meta') |
| 519 env.pop() | 505 env.pop() |
| 520 return 0 | 506 return 0 |
| 521 | 507 |
| 522 def RunLLCSandboxed(): | 508 def RunLLCSandboxed(): |
| 523 driver_tools.CheckTranslatorPrerequisites() | 509 driver_tools.CheckTranslatorPrerequisites() |
| 524 infile = env.getone('input') | 510 infile = env.getone('input') |
| 525 outfile = env.getone('output') | 511 outfile = env.getone('output') |
| 526 flags = env.get('LLC_FLAGS') | |
| 527 if not driver_tools.IsBitcode(infile): | 512 if not driver_tools.IsBitcode(infile): |
| 528 Log.Fatal('Input to sandboxed translator must be bitcode') | 513 Log.Fatal('Input to sandboxed translator must be bitcode') |
| 529 script = MakeSelUniversalScriptForLLC(infile, outfile, flags) | 514 script = MakeSelUniversalScriptForLLC(infile, outfile) |
| 530 command = ('${SEL_UNIVERSAL_PREFIX} ${SEL_UNIVERSAL} ${SEL_UNIVERSAL_FLAGS} ' | 515 command = ('${SEL_UNIVERSAL_PREFIX} ${SEL_UNIVERSAL} ${SEL_UNIVERSAL_FLAGS} ' |
| 531 '-- ${LLC_SB}') | 516 '-- ${LLC_SB}') |
| 532 _, stdout, _ = driver_tools.Run(command, | 517 _, stdout, _ = driver_tools.Run(command, |
| 533 stdin_contents=script, | 518 stdin_contents=script, |
| 534 # stdout/stderr will be automatically dumped | 519 # stdout/stderr will be automatically dumped |
| 535 # upon failure | 520 # upon failure |
| 536 redirect_stderr=subprocess.PIPE, | 521 redirect_stderr=subprocess.PIPE, |
| 537 redirect_stdout=subprocess.PIPE) | 522 redirect_stdout=subprocess.PIPE) |
| 538 # Get the values returned from the llc RPC to use in input to ld | 523 # Get the values returned from the llc RPC to use in input to ld |
| 539 is_shared = re.search(r'output\s+0:\s+i\(([0|1])\)', stdout).group(1) | 524 is_shared = re.search(r'output\s+0:\s+i\(([0|1])\)', stdout).group(1) |
| 540 is_shared = (is_shared == '1') | 525 is_shared = (is_shared == '1') |
| 541 soname = re.search(r'output\s+1:\s+s\("(.*)"\)', stdout).group(1) | 526 soname = re.search(r'output\s+1:\s+s\("(.*)"\)', stdout).group(1) |
| 542 needed_str = re.search(r'output\s+2:\s+s\("(.*)"\)', stdout).group(1) | 527 needed_str = re.search(r'output\s+2:\s+s\("(.*)"\)', stdout).group(1) |
| 543 # If the delimiter changes, this line needs to change | 528 # If the delimiter changes, this line needs to change |
| 544 needed_libs = [ lib for lib in needed_str.split(r'\n') if lib] | 529 needed_libs = [ lib for lib in needed_str.split(r'\n') if lib] |
| 545 return is_shared, soname, needed_libs | 530 return is_shared, soname, needed_libs |
| 546 | 531 |
| 547 def BuildLLCCommandLine(flags): | 532 def BuildOverrideLLCCommandLine(): |
| 533 extra_flags = env.get('LLC_FLAGS_EXTRA') | |
| 534 # The mcpu is not part of the default flags, so append that too. | |
| 535 mcpu = env.getone('LLC_MCPU') | |
| 536 if mcpu: | |
| 537 extra_flags.append(mcpu) | |
| 548 # command_line is a NUL (\x00) terminated sequence. | 538 # command_line is a NUL (\x00) terminated sequence. |
| 549 kTerminator = '\0' | 539 kTerminator = '\0' |
| 550 command_line = kTerminator.join(['llc'] + flags) + kTerminator | 540 command_line = kTerminator.join(extra_flags) + kTerminator |
| 551 command_line_escaped = command_line.replace(kTerminator, '\\x00') | 541 command_line_escaped = command_line.replace(kTerminator, '\\x00') |
| 552 return len(command_line), command_line_escaped | 542 return len(command_line), command_line_escaped |
| 553 | 543 |
| 554 def MakeSelUniversalScriptForLLC(infile, outfile, flags): | 544 def MakeSelUniversalScriptForLLC(infile, outfile): |
| 555 script = [] | 545 script = [] |
| 556 script.append('readwrite_file objfile %s' % outfile) | 546 script.append('readwrite_file objfile %s' % outfile) |
| 557 stream_rate = int(env.getraw('BITCODE_STREAM_RATE')) | 547 stream_rate = int(env.getraw('BITCODE_STREAM_RATE')) |
| 558 assert stream_rate != 0 | 548 assert stream_rate != 0 |
| 559 if UseDefaultCommandlineLLC(): | 549 if UseDefaultCommandlineLLC(): |
| 560 script.append('rpc StreamInit h(objfile) * s()') | 550 script.append('rpc StreamInit h(objfile) * s()') |
| 561 else: | 551 else: |
| 562 cmdline_len, cmdline_escaped = BuildLLCCommandLine(flags) | 552 cmdline_len, cmdline_escaped = BuildOverrideLLCCommandLine() |
| 563 script.append('rpc StreamInitWithCommandLine h(objfile) C(%d,%s) * s()' % | 553 script.append('rpc StreamInitWithOverrides h(objfile) C(%d,%s) * s()' % |
| 564 (cmdline_len, cmdline_escaped)) | 554 (cmdline_len, cmdline_escaped)) |
| 565 # specify filename, chunk size and rate in bits/s | 555 # specify filename, chunk size and rate in bits/s |
| 566 script.append('stream_file %s %s %s' % (infile, 64 * 1024, stream_rate)) | 556 script.append('stream_file %s %s %s' % (infile, 64 * 1024, stream_rate)) |
| 567 script.append('rpc StreamEnd * i() s() s() s()') | 557 script.append('rpc StreamEnd * i() s() s() s()') |
| 568 script.append('echo "llc complete"') | 558 script.append('echo "llc complete"') |
| 569 script.append('') | 559 script.append('') |
| 570 return '\n'.join(script) | 560 return '\n'.join(script) |
| 571 | 561 |
| 572 def get_help(argv): | 562 def get_help(argv): |
| 573 return """ | 563 return """ |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 590 | 580 |
| 591 ADVANCED OPTIONS: | 581 ADVANCED OPTIONS: |
| 592 -mattr=<+feat1,-feat2> Toggle specific cpu features on and off. | 582 -mattr=<+feat1,-feat2> Toggle specific cpu features on and off. |
| 593 -mcpu=<cpu-name> Target a specific cpu type. Tunes code as well as | 583 -mcpu=<cpu-name> Target a specific cpu type. Tunes code as well as |
| 594 turns cpu features on and off. | 584 turns cpu features on and off. |
| 595 -S Generate native assembly only. | 585 -S Generate native assembly only. |
| 596 -c Generate native object file only. | 586 -c Generate native object file only. |
| 597 --pnacl-sb Use the translator which runs inside the NaCl sandbox. | 587 --pnacl-sb Use the translator which runs inside the NaCl sandbox. |
| 598 -O[0-3] Change translation-time optimization level. | 588 -O[0-3] Change translation-time optimization level. |
| 599 """ | 589 """ |
| OLD | NEW |