Skip to content

Run binaryen wasm-opt on wasm backend output #6029

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jan 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions emcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -707,8 +707,10 @@ def detect_fixed_language_mode(args):
'BINARYEN_MEM_MAX': 'WASM_MEM_MAX',
# TODO: change most (all?) other BINARYEN* names to WASM*
}
settings_key_changes = set()
def setting_sub(s):
key, rest = s.split('=', 1)
settings_key_changes.add(key)
return '='.join([settings_aliases.get(key, key), rest])
settings_changes = list(map(setting_sub, settings_changes))

Expand Down Expand Up @@ -1172,6 +1174,12 @@ def check(input_file):
options.js_opts = None
shared.Settings.BINARYEN = shared.Settings.WASM = 1

# wasm backend output can benefit from the binaryen optimizer (in asm2wasm,
# we run the optimizer during asm2wasm itself). use it, if not overridden
if 'BINARYEN_PASSES' not in settings_key_changes:
if options.opt_level > 0 or options.shrink_level > 0:
shared.Settings.BINARYEN_PASSES = shared.Building.opt_level_to_str(options.opt_level, options.shrink_level)

# to bootstrap struct_info, we need binaryen
os.environ['EMCC_WASM_BACKEND_BINARYEN'] = '1'

Expand Down
13 changes: 7 additions & 6 deletions emscripten.py
Original file line number Diff line number Diff line change
Expand Up @@ -1782,7 +1782,7 @@ def emscript_wasm_backend(infile, settings, outfile, libraries=None, compiler_en
receiving = create_receiving_wasm(exported_implemented_functions, settings)

# finalize
module = create_module_wasm(sending, receiving, invoke_funcs, settings)
module = create_module_wasm(sending, receiving, invoke_funcs, exported_implemented_functions, settings)

write_output_file(outfile, post, module)
module = None
Expand Down Expand Up @@ -1948,7 +1948,7 @@ def create_receiving_wasm(exported_implemented_functions, settings):
return receiving


def create_module_wasm(sending, receiving, invoke_funcs, settings):
def create_module_wasm(sending, receiving, invoke_funcs, exported_implemented_functions, settings):
access_quote = access_quoter(settings)
invoke_wrappers = create_invoke_wrappers(invoke_funcs)

Expand Down Expand Up @@ -1983,10 +1983,11 @@ def create_module_wasm(sending, receiving, invoke_funcs, settings):
var establishStackSpace = Module['establishStackSpace'];
''' % shared.Settings.GLOBAL_BASE)

module.append('''
var setTempRet0 = Module['setTempRet0'];
var getTempRet0 = Module['getTempRet0'];
''')
# some runtime functionality may not have been generated in
# the wasm; provide a JS shim for it
for name in ['setTempRet0', 'getTempRet0', 'stackSave', 'stackRestore', 'stackAlloc']:
if name not in exported_implemented_functions:
module.append('var %s;\n' % name)

module.append(invoke_wrappers)
return module
Expand Down