diff --git a/pkg/dart2wasm/tool/compile_benchmark b/pkg/dart2wasm/tool/compile_benchmark index 32f27a047b5..9095c8d3094 100755 --- a/pkg/dart2wasm/tool/compile_benchmark +++ b/pkg/dart2wasm/tool/compile_benchmark @@ -30,6 +30,9 @@ PROG_NAME="$(follow_links "$BASH_SOURCE")" PROG_DIR="$(cd "${PROG_NAME%/*}" ; pwd -P)" SDK_DIR="$(cd "${PROG_DIR}/../../.." ; pwd -P)" +# Use same binaryen flags as `dart compile exe` +BINARYEN_FLAGS="$(sed -n '/binaryenFlags =/,/end of binaryenFlags/ p' $SDK_DIR/pkg/dartdev/lib/src/commands/compile.dart | sed '1d' | sed '$d' | tr '\n' ' ')" + # Locate build directory, containing executables, snapshots and platform dill. if [[ `uname` == 'Darwin' ]]; then OUT_DIR="$SDK_DIR/xcodebuild" @@ -62,7 +65,7 @@ function measure_size() { dart2wasm_command=("$DART2WASM" "$1" "$2" $COMPILE_FLAGS) # Keep in sync with sdk/bin/dart2wasm. -binaryen_command=("$BINARYEN" -all --closed-world -tnh --type-unfinalizing -O3 --type-ssa --gufa -O3 --type-merging -O1 --type-finalizing "$2" -o "$2") +binaryen_command=("$BINARYEN" $BINARYEN_FLAGS "$2" -o "$2") if [ -n "$COMPILE_BENCHMARK_BASE_NAME" ]; then measure ${dart2wasm_command[@]} diff --git a/pkg/dartdev/lib/src/commands/compile.dart b/pkg/dartdev/lib/src/commands/compile.dart index a2d99b4eb8f..5507a008da8 100644 --- a/pkg/dartdev/lib/src/commands/compile.dart +++ b/pkg/dartdev/lib/src/commands/compile.dart @@ -21,6 +21,28 @@ import '../sdk.dart'; import '../utils.dart'; import '../vm_interop_handler.dart'; +// The unique place where we store dart2wasm binaryen flags. +// +// Other uses (e.g. in shell scripts) will grep in this file for the flags. So +// please keep it as a simple multi-line string of flags. +final List binaryenFlags = ''' + --all-features + --closed-world + --traps-never-happen + --type-unfinalizing + -O3 + --type-ssa + --gufa + -O3 + --type-merging + -O1 + --type-finalizing +''' // end of binaryenFlags + .split('\n') + .map((line) => line.trim()) + .where((line) => line.isNotEmpty) + .toList(); + const int compileErrorExitCode = 64; class Option { @@ -394,10 +416,14 @@ class CompileWasmCommand extends CompileSubcommandCommand { final String optimizer = path.join( binDir.path, 'utils', Platform.isWindows ? 'wasm-opt.exe' : 'wasm-opt'); - String optimizerFlags(bool outputNames) => - '-all --closed-world -tnh --type-unfinalizing -O3 --type-ssa' - ' --gufa -O3 --type-merging -O1 --type-finalizing' - '${outputNames ? ' -g' : ''}'; + String optimizerFlags(bool outputNames) { + final flags = [ + ...binaryenFlags, + if (outputNames) '-g', + ]; + return flags.join(' '); + } + static const String unoptExtension = '.unopt'; CompileWasmCommand({bool verbose = false}) diff --git a/sdk/bin/dart2wasm b/sdk/bin/dart2wasm index f6d20d0d6e3..7200b662fe3 100755 --- a/sdk/bin/dart2wasm +++ b/sdk/bin/dart2wasm @@ -24,6 +24,9 @@ PROG_NAME="$(follow_links "$BASH_SOURCE")" PROG_DIR="$(cd "${PROG_NAME%/*}" ; pwd -P)" SDK_DIR="$(cd "${PROG_DIR}/../.." ; pwd -P)" +# Use same binaryen flags as `dart compile exe` +BINARYEN_FLAGS="$(sed -n '/binaryenFlags =/,/end of binaryenFlags/ p' $SDK_DIR/pkg/dartdev/lib/src/commands/compile.dart | sed '1d' | sed '$d' | tr '\n' ' ')" + # Locate build directory, containing executables, snapshots and platform dill. if [[ `uname` == 'Darwin' ]]; then OUT_DIR="$SDK_DIR/xcodebuild" @@ -127,7 +130,6 @@ set -e "$DART_PRECOMPILED_RUNTIME" "--packages=$DART_ROOT/.packages" "${EXTRA_VM_OPTIONS[@]}" "$SNAPSHOT" "$SDK_ARG" "$PLATFORM_ARG" "${ARGS[@]}" if [[ "$OPTIMIZED" == 1 ]]; then - # Keep optimization parameters after `-g` in sync with pkg/dart2wasm/tool/compile_benchmark. - # Last argument must be the .wasm file. - "$BIN_DIR"/wasm-opt -g -all --closed-world -tnh --type-unfinalizing -O3 --type-ssa --gufa -O3 --type-merging -O1 --type-finalizing "${ARGS[-1]}" -o "${ARGS[-1]}" + # Keep the name section by passing `-g`. + "$BIN_DIR"/wasm-opt -g $BINARYEN_FLAGS "${ARGS[-1]}" -o "${ARGS[-1]}" fi