aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2014-02-27 11:40:14 -0800
committerAlon Zakai <alonzakai@gmail.com>2014-02-27 12:47:33 -0800
commitd57fad6e2f987a4f8991865cdfc43456c0257e4b (patch)
tree502b0cb683ee3ef6dc9f1233940d4dc565c868fd
parent8dfb363acf5cbb9cf835b49f742d633283423808 (diff)
support -Os and -Oz as arguments to emcc
-rwxr-xr-xemcc19
-rw-r--r--tests/test_other.py17
2 files changed, 33 insertions, 3 deletions
diff --git a/emcc b/emcc
index a6bf9c6a..942ea1b3 100755
--- a/emcc
+++ b/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
diff --git a/tests/test_other.py b/tests/test_other.py
index f5a4ebc9..81e8f05c 100644
--- a/tests/test_other.py
+++ b/tests/test_other.py
@@ -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']
+