support -Os and -Oz as arguments to emcc

This commit is contained in:
Alon Zakai 2014-02-27 11:40:14 -08:00
Родитель 8dfb363acf
Коммит d57fad6e2f
2 изменённых файлов: 33 добавлений и 3 удалений

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

@ -161,9 +161,17 @@ Options that are modified or new in %s include:
time in return for the smallest and fastest
output.
-O3 As -O2, plus additional optimizations that can
-Os Like -O2 with extra optimizations for size.
-Oz Like -Os but reduces code size further.
-O3 Like -O2 plus additional JS optimizations that can
take a significant amount of compilation time and/or
are relatively new.
are relatively new. Note that differs from -O2 only
during the bitcode to JS (final link + JS generation)
stage, as it is JS-specific, so you can run -Os
on your source files for example, and -O3 during
JS generation if you want.
For tips on optimizing your code, see
https://github.com/kripken/emscripten/wiki/Optimizing-Code
@ -810,8 +818,13 @@ try:
# Let -O default to -O2, which is what gcc does.
requested_level = newargs[i][2:] or '2'
if requested_level == 's':
llvm_opts = ['-Os']
requested_level = 2
settings_changes.append('INLINING_LIMIT=50')
elif requested_level == 'z':
llvm_opts = ['-Oz']
requested_level = 2
settings_changes.append('INLINING_LIMIT=25')
opt_level = validate_arg_level(requested_level, 3, 'Invalid optimization level: ' + newargs[i])
# We leave the -O option in place so that the clang front-end runs in that
# optimization mode, but we disable the actual optimization passes, as we'll
@ -1353,7 +1366,7 @@ try:
file_ending = filename_type_ending(input_file)
if file_ending.endswith(SOURCE_ENDINGS):
temp_file = temp_files[i]
logging.debug('optimizing %s with -O%s', input_file, llvm_opts)
logging.debug('optimizing %s', input_file)
shared.Building.llvm_opt(temp_file, llvm_opts)
# If we were just asked to generate bitcode, stop there

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

@ -2428,3 +2428,20 @@ int main(int argc, char **argv) {
assert ('_ZN5WasteILi2EED1Ev' in src) == exit, 'destructors should not appear if no exit'
assert ('atexit(' in src) == exit, 'atexit should not appear or be called'
def test_os_oz(self):
if os.environ.get('EMCC_DEBUG'): return self.skip('cannot run in debug mode')
try:
os.environ['EMCC_DEBUG'] = '1'
for args, expect in [
(['-O1'], 'LLVM opts: -O1'),
(['-O2'], 'LLVM opts: -O3'),
(['-Os'], 'LLVM opts: -Os'),
(['-Oz'], 'LLVM opts: -Oz'),
(['-O3'], 'LLVM opts: -O3'),
]:
print args, expect
output, err = Popen([PYTHON, EMCC, path_from_root('tests', 'hello_world.cpp')] + args, stdout=PIPE, stderr=PIPE).communicate()
self.assertContained(expect, err)
finally:
del os.environ['EMCC_DEBUG']