Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(114)

Side by Side Diff: pnacl/driver/pnacl-translate.py

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

Powered by Google App Engine
This is Rietveld 408576698