aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2013-05-10 17:48:14 -0700
committerAlon Zakai <alonzakai@gmail.com>2013-05-10 17:48:14 -0700
commita6f1fec8fb8c6fde6f5178efa236fd2b73999c63 (patch)
treeb11d6f5574c78a3cbb1d526e1bfab2b98b83b9ea /tools
parent32444e9c75d082c97c6ee7fbca2ca53982a54957 (diff)
do not eliminate if there is a switch
Diffstat (limited to 'tools')
-rw-r--r--tools/eliminator/asm-eliminator-test-output.js10
-rw-r--r--tools/eliminator/asm-eliminator-test.js9
-rw-r--r--tools/js-optimizer.js13
3 files changed, 27 insertions, 5 deletions
diff --git a/tools/eliminator/asm-eliminator-test-output.js b/tools/eliminator/asm-eliminator-test-output.js
index 25ab23e4..8da7a5bc 100644
--- a/tools/eliminator/asm-eliminator-test-output.js
+++ b/tools/eliminator/asm-eliminator-test-output.js
@@ -107,18 +107,22 @@ function label() {
}
}
function switchy() {
- var no = 0, yes = 0;
+ var no = 0, yes = 0, a = 0, b = 0;
while (1) switch (label | 0) {
- case x:
+ case 1:
no = 100;
break;
- case y:
+ case 2:
yes = 111;
yes = yes * 2;
print(yes);
yes--;
print(yes / 2);
continue;
+ case 3:
+ a = 5;
+ b = a;
+ break;
}
}
function confuusion() {
diff --git a/tools/eliminator/asm-eliminator-test.js b/tools/eliminator/asm-eliminator-test.js
index e068e860..5f75e9c1 100644
--- a/tools/eliminator/asm-eliminator-test.js
+++ b/tools/eliminator/asm-eliminator-test.js
@@ -143,17 +143,22 @@ function label() {
}
function switchy() {
var no = 0, yes = 0;
+ var a = 0, b = 0;
while (1) switch (label | 0) {
- case x:
+ case 1:
no = 100; // eliminatable in theory, but eliminator does not look into switch. must leave def above as well.
break;
- case y:
+ case 2:
yes = 111;
yes = yes*2;
print(yes);
yes--;
print(yes/2);
continue;
+ case 3:
+ a = 5;
+ b = a;
+ break;
}
}
function confuusion() {
diff --git a/tools/js-optimizer.js b/tools/js-optimizer.js
index 2d0d51f9..ce67da89 100644
--- a/tools/js-optimizer.js
+++ b/tools/js-optimizer.js
@@ -1787,6 +1787,7 @@ function eliminate(ast, memSafe) {
if (asm) var asmData = normalizeAsm(func);
//printErr('eliminate in ' + func[1]);
+
// First, find the potentially eliminatable functions: that have one definition and one use
var definitions = {};
var uses = {};
@@ -1802,6 +1803,7 @@ function eliminate(ast, memSafe) {
}
}
// examine body and note locals
+ var hasSwitch = false;
traverse(func, function(node, type) {
if (type === 'var') {
var node1 = node[1];
@@ -1833,8 +1835,19 @@ function eliminate(ast, memSafe) {
uses[name]--; // because the name node will show up by itself in the previous case
}
}
+ } else if (type == 'switch') {
+ hasSwitch = true;
}
});
+
+ // we cannot eliminate variables if there is a switch
+ if (traverse(func, function(node, type) {
+ if (type == 'switch') return true;
+ })) {
+ if (asm) denormalizeAsm(func, asmData);
+ return;
+ }
+
var potentials = {}; // local variables with 1 definition and 1 use
var sideEffectFree = {}; // whether a local variable has no side effects in its definition