Skip to content

Commit

Permalink
Add support for "-Ofast"
Browse files Browse the repository at this point in the history
Based on #11884
  • Loading branch information
sbc100 committed Mar 8, 2024
1 parent 71cee0e commit 0904f4d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
3 changes: 3 additions & 0 deletions emcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1147,6 +1147,9 @@ def consume_arg_file():
requested_level = 1
settings.SHRINK_LEVEL = 0
settings.DEBUG_LEVEL = max(settings.DEBUG_LEVEL, 1)
elif requested_level == 'fast':
requested_level = 3
settings.SHRINK_LEVEL = 0
else:
settings.SHRINK_LEVEL = 0
settings.OPT_LEVEL = validate_arg_level(requested_level, 3, 'invalid optimization level: ' + arg, clamp=True)
Expand Down
15 changes: 7 additions & 8 deletions test/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,8 @@ def test_dumpmachine(self):

@parameterized({
'c': [EMCC, '.c'],
'cxx': [EMXX, '.cpp']})
'cxx': [EMXX, '.cpp']
})
def test_emcc_2(self, compiler, suffix):
# emcc src.cpp -c and emcc -c src.cpp -o src.[o|foo|so] ==> should always give an object file
for args in [[], ['-o', 'src.o'], ['-o', 'src.foo'], ['-o', 'src.so']]:
Expand All @@ -513,7 +514,8 @@ def test_bc_output_warning(self):

@parameterized({
'c': [EMCC, '.c'],
'cxx': [EMXX, '.cpp']})
'cxx': [EMXX, '.cpp']
})
def test_emcc_3(self, compiler, suffix):
# handle singleton archives
self.run_process([compiler, '-c', test_file('hello_world' + suffix), '-o', 'a.o'])
Expand All @@ -538,9 +540,7 @@ def test_emcc_3(self, compiler, suffix):
delete_file(path)

@is_slow_test
@parameterized({
'c': [EMCC],
'cxx': [EMXX]})
@with_both_compilers
def test_emcc_4(self, compiler):
# Optimization: emcc src.cpp -o something.js [-Ox]. -O0 is the same as not specifying any optimization setting
# link_param are used after compiling first
Expand Down Expand Up @@ -4687,9 +4687,8 @@ def test_fs_after_main(self):
self.run_process([EMXX, test_file('fs_after_main.cpp')])
self.assertContained('Test passed.', self.run_js('a.out.js'))

def test_os_oz(self):
for opt in ['-O1', '-O2', '-Os', '-Oz', '-O3', '-Og']:
print(opt)
def test_opt_levels(self):
for opt in ['-O1', '-O2', '-Os', '-Oz', '-O3', '-Og', '-Ofast']:
proc = self.run_process([EMCC, '-v', test_file('hello_world.c'), opt], stderr=PIPE)
self.assertContained(opt, proc.stderr)
self.assertContained('hello, world!', self.run_js('a.out.js'))
Expand Down

0 comments on commit 0904f4d

Please sign in to comment.