aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2012-10-27 17:15:51 -0700
committerAlon Zakai <alonzakai@gmail.com>2012-10-27 17:15:51 -0700
commitbdeaabb263dee309d5b64f4765183f056a064d19 (patch)
treebe09c718bc0a4428d7b70e763d04dae61aea5ae4
parenta4e8b5f5fc09aee9ec2efb5122d26c426e0f0fa3 (diff)
eliminate into returns
-rw-r--r--tools/eliminator/eliminator-test-output.js2
-rw-r--r--tools/eliminator/eliminator-test.js3
-rw-r--r--tools/js-optimizer.js6
3 files changed, 9 insertions, 2 deletions
diff --git a/tools/eliminator/eliminator-test-output.js b/tools/eliminator/eliminator-test-output.js
index 3d23ac50..c32266df 100644
--- a/tools/eliminator/eliminator-test-output.js
+++ b/tools/eliminator/eliminator-test-output.js
@@ -89,6 +89,7 @@ function b() {
}
var $156;
HEAP32[$139 + ($136 << 4) + 4 >> 2] = _sqlite3FindFunction($145, $147, $148, $156, $135, 0);
+ return cheez();
}
function c() {
var x = MEM[100], y = callMe(5);
@@ -101,6 +102,7 @@ function c() {
zoom(glob);
hail(w2);
sunk(y2);
+ return;
}
function f() {
HEAP[123] = (GLOB[1] + 1) / 2;
diff --git a/tools/eliminator/eliminator-test.js b/tools/eliminator/eliminator-test.js
index c968d4d7..1c6af7f3 100644
--- a/tools/eliminator/eliminator-test.js
+++ b/tools/eliminator/eliminator-test.js
@@ -109,6 +109,8 @@ function b() {
}
var $156;
HEAP32[$139 + ($136 << 4) + 4 >> 2] = _sqlite3FindFunction($145, $147, $148, $156, $135, 0);
+ var finality = cheez();
+ return finality;
}
function c() {
var x = MEM[100], y = callMe(5), z = glob; // do not eliminate vars with multiple variables, if there is a call!
@@ -122,6 +124,7 @@ function c() {
zoom(z2);
hail(w2);
sunk(y2);
+ return;
}
function f() {
var unused;
diff --git a/tools/js-optimizer.js b/tools/js-optimizer.js
index 21a0b3f7..855cf6a5 100644
--- a/tools/js-optimizer.js
+++ b/tools/js-optimizer.js
@@ -1395,9 +1395,9 @@ function registerize(ast) {
//
// to be optimized (f could replace FUNCTION_TABLE, so in general JS eliminating x is not valid).
-var ELIMINATION_SAFE_NODES = set('var', 'assign', 'call', 'if', 'toplevel', 'do'); // do is checked carefully, however
+var ELIMINATION_SAFE_NODES = set('var', 'assign', 'call', 'if', 'toplevel', 'do', 'return'); // do is checked carefully, however
var NODES_WITHOUT_ELIMINATION_SIDE_EFFECTS = set('name', 'num', 'string', 'binary', 'sub', 'unary-prefix');
-var IGNORABLE_ELIMINATOR_SCAN_NODES = set('num', 'toplevel', 'string', 'break', 'continue', 'dot', 'return'); // dot can only be STRING_TABLE.*
+var IGNORABLE_ELIMINATOR_SCAN_NODES = set('num', 'toplevel', 'string', 'break', 'continue', 'dot'); // dot can only be STRING_TABLE.*
var ABORTING_ELIMINATOR_SCAN_NODES = set('new', 'object', 'function', 'defun', 'switch', 'for', 'while', 'array', 'throw'); // we could handle some of these, TODO, but nontrivial (e.g. for while, the condition is hit multiple times after the body)
function eliminate(ast) {
@@ -1695,6 +1695,8 @@ function eliminate(ast) {
tracked = {};
abort = true;
}
+ } else if (type == 'return') {
+ if (node[1]) traverseInOrder(node[1]);
} else if (type == 'conditional') {
traverseInOrder(node[1]);
traverseInOrder(node[2]);