From b5e5ff80edd32911a15a40c5f33dd26fddd36262 Mon Sep 17 00:00:00 2001 From: Derek Schuff Date: Thu, 7 Nov 2024 16:14:17 -0800 Subject: [PATCH] Extend support for -### flag to optimized linking (#22877) This will cause the ### flag to print most Binaryen and acorn-optimizer subcommands in addtion to clang and ld. However accuracy isn't perfect because some steps (E.g. metadce) depend on the output of previous steps. --- test/test_other.py | 4 +++- tools/building.py | 14 +++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/test/test_other.py b/test/test_other.py index 0e6405845ed8a..bbfb1c8dd4ae5 100644 --- a/test/test_other.py +++ b/test/test_other.py @@ -321,9 +321,11 @@ def test_log_subcommands(self): def test_skip_subcommands(self): # The -### flag is like `-v` but it doesn't actaully execute the sub-commands - proc = self.run_process([EMCC, '-###', test_file('hello_world.c')], stdout=PIPE, stderr=PIPE) + proc = self.run_process([EMCC, '-###', '-O3', test_file('hello_world.c')], stdout=PIPE, stderr=PIPE) self.assertContained(CLANG_CC, proc.stderr) self.assertContained(WASM_LD, proc.stderr) + self.assertContained('wasm-opt', proc.stderr) + self.assertContained('acorn-optimizer.mjs', proc.stderr) self.assertNotExists('a.out.js') def test_emcc_check(self): diff --git a/tools/building.py b/tools/building.py index 12aa33689c17d..c070e540636f1 100644 --- a/tools/building.py +++ b/tools/building.py @@ -348,7 +348,7 @@ def js_optimizer(filename, passes): def acorn_optimizer(filename, passes, extra_info=None, return_output=False, worker_js=False): optimizer = path_from_root('tools/acorn-optimizer.mjs') original_filename = filename - if extra_info is not None: + if extra_info is not None and not shared.SKIP_SUBPROCS: temp_files = shared.get_temp_files() temp = temp_files.get('.js', prefix='emcc_acorn_info_').name shutil.copyfile(filename, temp) @@ -366,6 +366,9 @@ def acorn_optimizer(filename, passes, extra_info=None, return_output=False, work if settings.VERBOSE: cmd += ['--verbose'] if return_output: + shared.print_compiler_stage(cmd) + if shared.SKIP_SUBPROCS: + return '' return check_call(cmd, stdout=PIPE).stdout acorn_optimizer.counter += 1 @@ -375,6 +378,9 @@ def acorn_optimizer(filename, passes, extra_info=None, return_output=False, work output_file = basename + '.jso%d.js' % acorn_optimizer.counter shared.get_temp_files().note(output_file) cmd += ['-o', output_file] + shared.print_compiler_stage(cmd) + if shared.SKIP_SUBPROCS: + return output_file check_call(cmd) save_intermediate(output_file, '%s.js' % passes[0]) return output_file @@ -780,6 +786,9 @@ def metadce(js_file, wasm_file, debug_info, last): extra_info = '{ "exports": [' + ','.join(f'["{asmjs_mangle(x)}", "{x}"]' for x in exports) + ']}' txt = acorn_optimizer(js_file, ['emitDCEGraph', '--no-print'], return_output=True, extra_info=extra_info) + if shared.SKIP_SUBPROCS: + # The next steps depend on the output from this step, so we can't do them if we aren't actually running. + return js_file graph = json.loads(txt) # ensure that functions expected to be exported to the outside are roots required_symbols = user_requested_exports.union(set(settings.SIDE_MODULE_IMPORTS)) @@ -1209,6 +1218,9 @@ def run_binaryen_command(tool, infile, outfile=None, args=None, debug=False, std if settings.GENERATE_SOURCE_MAP and outfile and tool in ['wasm-opt', 'wasm-emscripten-finalize']: cmd += [f'--input-source-map={infile}.map'] cmd += [f'--output-source-map={outfile}.map'] + shared.print_compiler_stage(cmd) + if shared.SKIP_SUBPROCS: + return '' ret = check_call(cmd, stdout=stdout).stdout if outfile: save_intermediate(outfile, '%s.wasm' % tool)