summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--scripts/fuzz_opt.py15
-rw-r--r--src/tools/wasm2js.cpp33
-rw-r--r--test/wasm2js/br_table_to_loop.2asm.js.opt2
-rw-r--r--test/wasm2js/i64-ctz.2asm.js.opt2
-rw-r--r--test/wasm2js/stack-modified.2asm.js.opt2
-rw-r--r--test/wasm2js/unary-ops.2asm.js.opt4
6 files changed, 43 insertions, 15 deletions
diff --git a/scripts/fuzz_opt.py b/scripts/fuzz_opt.py
index 34bc90d7e..fb777d235 100644
--- a/scripts/fuzz_opt.py
+++ b/scripts/fuzz_opt.py
@@ -26,7 +26,7 @@ from test.shared import options, NODEJS
# parameters
-NANS = False
+NANS = True
FEATURE_OPTS = [] # '--all-features' etc
@@ -44,7 +44,7 @@ V8_OPTS = [
'--experimental-wasm-return-call'
]
-INPUT_SIZE_LIMIT = 50 * 1024
+INPUT_SIZE_LIMIT = 150 * 1024
LOG_LIMIT = 125
@@ -145,10 +145,7 @@ def run_bynterp(wasm):
def run_wasm2js(wasm):
wrapper = run([in_bin('wasm-opt'), wasm, '--emit-js-wrapper=/dev/stdout'] + FEATURE_OPTS)
- cmd = [in_bin('wasm2js'), wasm, '--emscripten']
- if random.random() < 0.5:
- cmd += ['-O']
- main = run(cmd + FEATURE_OPTS)
+ main = run([in_bin('wasm2js'), wasm, '--emscripten'] + FEATURE_OPTS)
with open(os.path.join(options.binaryen_root, 'scripts', 'wasm2js.js')) as f:
glue = f.read()
with open('js.js', 'w') as f:
@@ -165,9 +162,9 @@ def run_wasm2js(wasm):
def run_vms(prefix):
wasm = prefix + 'wasm'
results = []
- # results.append(run_bynterp(wasm))
- # results.append(fix_output(run_vm([os.path.expanduser('d8'), prefix + 'js'] + V8_OPTS + ['--', wasm])))
- results.append(run_wasm2js(wasm))
+ results.append(run_bynterp(wasm))
+ results.append(fix_output(run_vm([os.path.expanduser('d8'), prefix + 'js'] + V8_OPTS + ['--', wasm])))
+ # results.append(run_wasm2js(wasm))
# append to add results from VMs
# results += [fix_output(run_vm([os.path.expanduser('d8'), prefix + 'js'] + V8_OPTS + ['--', prefix + 'wasm']))]
diff --git a/src/tools/wasm2js.cpp b/src/tools/wasm2js.cpp
index 1c128390f..b3f8068e2 100644
--- a/src/tools/wasm2js.cpp
+++ b/src/tools/wasm2js.cpp
@@ -136,6 +136,12 @@ static void replaceInPlace(Ref target, Ref value) {
}
}
+static void replaceInPlaceIfPossible(Ref target, Ref value) {
+ if (target->isArray() && value->isArray()) {
+ replaceInPlace(target, value);
+ }
+}
+
static void optimizeJS(Ref ast) {
// Helpers
@@ -377,7 +383,8 @@ static void optimizeJS(Ref ast) {
}
});
- // Remove unnecessary break/continue labels, when referring to the top level.
+ // Remove unnecessary break/continue labels, when the name is that of the
+ // highest target anyhow, which we would reach without the name.
std::vector<Ref> breakCapturers;
std::vector<Ref> continueCapturers;
@@ -437,6 +444,30 @@ static void optimizeJS(Ref ast) {
}
}
});
+
+ // Remove unnecessary block/loop labels.
+
+ std::set<IString> usedLabelNames;
+
+ traversePost(ast, [&](Ref node) {
+ if (node->isArray() && !node->empty()) {
+ if (node[0] == BREAK || node[0] == CONTINUE) {
+ if (!node[1]->isNull()) {
+ auto label = node[1]->getIString();
+ usedLabelNames.insert(label);
+ }
+ } else if (node[0] == LABEL) {
+ auto label = node[1]->getIString();
+ if (usedLabelNames.count(label)) {
+ // It's used; just erase it from the data structure.
+ usedLabelNames.erase(label);
+ } else {
+ // It's not used - get rid of it.
+ replaceInPlaceIfPossible(node, node[2]);
+ }
+ }
+ }
+ });
}
static void emitWasm(Module& wasm,
diff --git a/test/wasm2js/br_table_to_loop.2asm.js.opt b/test/wasm2js/br_table_to_loop.2asm.js.opt
index 47e7dbea3..c1151d7ae 100644
--- a/test/wasm2js/br_table_to_loop.2asm.js.opt
+++ b/test/wasm2js/br_table_to_loop.2asm.js.opt
@@ -22,7 +22,7 @@ function asmFunc(global, env, buffer) {
var nan = global.NaN;
var infinity = global.Infinity;
function $0() {
- loop : while (1) continue;
+ while (1) continue;
}
function $1() {
diff --git a/test/wasm2js/i64-ctz.2asm.js.opt b/test/wasm2js/i64-ctz.2asm.js.opt
index d0a3c79a6..b16724295 100644
--- a/test/wasm2js/i64-ctz.2asm.js.opt
+++ b/test/wasm2js/i64-ctz.2asm.js.opt
@@ -57,7 +57,7 @@ function asmFunc(global, env, buffer) {
function __wasm_popcnt_i64($0, $1) {
var $2 = 0, $3 = 0, $4 = 0, $5 = 0;
- label$2 : while (1) {
+ while (1) {
$5 = $3;
$2 = $4;
if ($0 | $1) {
diff --git a/test/wasm2js/stack-modified.2asm.js.opt b/test/wasm2js/stack-modified.2asm.js.opt
index d7e96092d..e5f8da820 100644
--- a/test/wasm2js/stack-modified.2asm.js.opt
+++ b/test/wasm2js/stack-modified.2asm.js.opt
@@ -30,7 +30,7 @@ function asmFunc(global, env, buffer) {
var $2 = 0, $3 = 0, $4 = 0;
$2 = $1;
$3 = 1;
- label$2 : while (1) {
+ while (1) {
if ($0_1 | $2) {
$3 = _ZN17compiler_builtins3int3mul3Mul3mul17h070e9a1c69faec5bE($0_1, $2, $3, $4);
$4 = i64toi32_i32$HIGH_BITS;
diff --git a/test/wasm2js/unary-ops.2asm.js.opt b/test/wasm2js/unary-ops.2asm.js.opt
index 5a280d8e4..55b1155a2 100644
--- a/test/wasm2js/unary-ops.2asm.js.opt
+++ b/test/wasm2js/unary-ops.2asm.js.opt
@@ -98,7 +98,7 @@ function asmFunc(global, env, buffer) {
function __wasm_popcnt_i32($0) {
var $1_1 = 0, $2 = 0;
- label$2 : while (1) {
+ while (1) {
$2 = $1_1;
if ($0) {
$0 = $0 - 1 & $0;
@@ -112,7 +112,7 @@ function asmFunc(global, env, buffer) {
function __wasm_popcnt_i64($0, $1_1) {
var $2 = 0, $3 = 0, $4 = 0, $5 = 0;
- label$2 : while (1) {
+ while (1) {
$5 = $3;
$2 = $4;
if ($0 | $1_1) {