do not do redundant llvm optimizations on bitcode; do them only when actually generating js

This commit is contained in:
Alon Zakai 2012-01-07 18:36:42 -08:00
Родитель 5c02f40d34
Коммит 6c5cc41f83
2 изменённых файлов: 17 добавлений и 14 удалений

26
emcc
Просмотреть файл

@ -117,7 +117,10 @@ Options that are modified or new in %s include:
optimizations, and no runtime assertions
or C++ exception catching (to re-enable
C++ exception catching, use
-s DISABLE_EXCEPTION_CATCHING=0 )
-s DISABLE_EXCEPTION_CATCHING=0 ).
Note: Optimizations are only done when
compiling to JavaScript, not to intermediate
bitcode.
-O2 As -O1, plus the relooper (loop recreation),
plus closure compiler advanced opts
Warning: Compiling with this takes a long time!
@ -397,18 +400,10 @@ try:
if DEBUG: print >> sys.stderr, 'emcc: assembling assembly file: ', input_file
shared.Building.llvm_as(input_file, in_temp(unsuffixed_basename(input_file) + '.o'))
# Optimize, if asked to
if llvm_opt_level > 0 and not LEAVE_INPUTS_RAW:
if DEBUG: print >> sys.stderr, 'emcc: LLVM opts'
for input_file in input_files:
try:
shared.Building.llvm_opt(in_temp(unsuffixed_basename(input_file) + '.o'), LLVM_INTERNAL_OPT_LEVEL, safe=llvm_opt_level < 2)
except:
# This might be an invalid input, which will get ignored during linking later anyhow
print >> sys.stderr, 'emcc: warning: LLVM opt failed to run on %s, continuing without optimization' % input_file
# If we were just asked to generate bitcode, stop there
if final_suffix not in ['js', 'html']:
if llvm_opt_level > 0:
print >> sys.stderr, 'emcc: warning: -Ox flags ignored, since not generating JavaScript'
if not specified_target:
for input_file in input_files:
shutil.move(in_temp(unsuffixed_basename(input_file) + '.o'), unsuffixed_basename(input_file) + '.' + final_suffix)
@ -428,7 +423,7 @@ try:
## Continue on to create JavaScript
if DEBUG: print >> sys.stderr, 'emcc: generating JavaScript'
if DEBUG: print >> sys.stderr, 'emcc: will generate JavaScript'
extra_files_to_link = []
@ -473,10 +468,15 @@ try:
if not LEAVE_INPUTS_RAW:
shutil.move(in_temp(unsuffixed_basename(input_files[0]) + '.o'), in_temp(target_basename + '.bc'))
# Optimize, if asked to
if llvm_opt_level > 0 and not LEAVE_INPUTS_RAW:
if DEBUG: print >> sys.stderr, 'emcc: LLVM opts'
shared.Building.llvm_opt(in_temp(target_basename + '.bc'), LLVM_INTERNAL_OPT_LEVEL, safe=llvm_opt_level < 2)
# Emscripten
try:
if shared.Settings.RELOOP:
print >> sys.stderr, 'Warning: The relooper optimization can be very slow.'
print >> sys.stderr, 'emcc: warning: The relooper optimization can be very slow.'
except:
pass

Просмотреть файл

@ -5311,6 +5311,7 @@ Options that are modified or new in %s include:
(['-o', 'something.bc'], 1, ['-O1'], 0, 0),
(['-o', 'something.bc'], 2, ['-O2'], 1, 0),
(['-o', 'something.bc'], 3, ['-O3'], 1, 0),
(['-O1', '-o', 'something.bc'], 0, [], 0, 0), # -Ox is ignored and warned about
]:
#print params, opt_level, bc_params, closure
clear()
@ -5318,10 +5319,12 @@ Options that are modified or new in %s include:
stdout=PIPE, stderr=PIPE).communicate()
assert len(output[0]) == 0, output[0]
if bc_params is not None:
if '-O1' in params and 'something.bc' in params:
assert 'warning: -Ox flags ignored, since not generating JavaScript' in output[1]
assert os.path.exists('something.bc'), output[1]
output = Popen([compiler, 'something.bc', '-o', 'something.js'] + bc_params, stdout=PIPE, stderr=PIPE).communicate()
assert os.path.exists('something.js'), output[1]
assert ('Warning: The relooper optimization can be very slow.' in output[1]) == (opt_level >= 2), 'relooper warning should appear in opt >= 2'
assert ('warning: The relooper optimization can be very slow.' in output[1]) == (opt_level >= 2), 'relooper warning should appear in opt >= 2'
assert ('Warning: Applying some potentially unsafe optimizations!' in output[1]) == (opt_level >= 3), 'unsafe warning should appear in opt >= 3'
self.assertContained('hello, world!', run_js('something.js'))