aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tools/eliminator/eliminator-test-output.js14
-rw-r--r--tools/eliminator/eliminator-test.js15
-rw-r--r--tools/js-optimizer.js6
3 files changed, 32 insertions, 3 deletions
diff --git a/tools/eliminator/eliminator-test-output.js b/tools/eliminator/eliminator-test-output.js
index eafdbee5..0d9c1be2 100644
--- a/tools/eliminator/eliminator-test-output.js
+++ b/tools/eliminator/eliminator-test-output.js
@@ -67,6 +67,18 @@ function b() {
var $156;
HEAP32[$139 + ($136 << 4) + 4 >> 2] = _sqlite3FindFunction($145, $147, $148, $156, $135, 0);
}
+function c() {
+ var x = MEM[100], y = callMe(5), z = glob;
+ zoom(z);
+ hail(x * 2);
+ sunk(y);
+ barrier();
+ var y2 = $callMe2;
+ var w2 = MEM[100] * 2;
+ zoom(glob);
+ hail(w2);
+ sunk(y2);
+}
function f() {
HEAP[123] = (GLOB[1] + 1) / 2;
}
@@ -6146,4 +6158,4 @@ function _mallocNoU($bytes) {
return $mem_0;
return null;
}
-// EMSCRIPTEN_GENERATED_FUNCTIONS: ["a", "b", "f", "g", "h", "py", "r", "t", "f2", "f3", "llvm3_1", "_inflate", "_malloc", "_mallocNoU"]
+// EMSCRIPTEN_GENERATED_FUNCTIONS: ["a", "b", "c", "f", "g", "h", "py", "r", "t", "f2", "f3", "llvm3_1", "_inflate", "_malloc", "_mallocNoU"]
diff --git a/tools/eliminator/eliminator-test.js b/tools/eliminator/eliminator-test.js
index e9ac89e0..b3343f89 100644
--- a/tools/eliminator/eliminator-test.js
+++ b/tools/eliminator/eliminator-test.js
@@ -82,6 +82,19 @@ function b() {
var $156;
HEAP32[$139 + ($136 << 4) + 4 >> 2] = _sqlite3FindFunction($145, $147, $148, $156, $135, 0);
}
+function c() {
+ var x = MEM[100], y = callMe(5), z = glob; // do not eliminate vars with multiple variables, if there is a call!
+ var w = x*2;
+ zoom(z);
+ hail(w);
+ sunk(y);
+ barrier();
+ var x2 = MEM[100], y2 = $callMe2, z2 = glob; // no call, so ok
+ var w2 = x2*2;
+ zoom(z2);
+ hail(w2);
+ sunk(y2);
+}
function f() {
var unused;
var x = GLOB[1];
@@ -8773,4 +8786,4 @@ function _mallocNoU($bytes) {
return $mem_0;
return null;
}
-// EMSCRIPTEN_GENERATED_FUNCTIONS: ["a", "b", "f", "g", "h", "py", "r", "t", "f2", "f3", "llvm3_1", "_inflate", "_malloc", "_mallocNoU"]
+// EMSCRIPTEN_GENERATED_FUNCTIONS: ["a", "b", "c", "f", "g", "h", "py", "r", "t", "f2", "f3", "llvm3_1", "_inflate", "_malloc", "_mallocNoU"]
diff --git a/tools/js-optimizer.js b/tools/js-optimizer.js
index 25ddf97e..2c9d3868 100644
--- a/tools/js-optimizer.js
+++ b/tools/js-optimizer.js
@@ -1474,6 +1474,7 @@ function eliminate(ast) {
var needMemoryInvalidated = false;
var neededDepInvalidations = [];
var needCallsInvalidated = false;
+ var seenCall = false;
function invalidateGlobals() {
//printErr('invalidate globals');
temp.length = 0;
@@ -1535,6 +1536,8 @@ function eliminate(ast) {
needGlobalsInvalidated = false;
needMemoryInvalidated = false;
neededDepInvalidations.length = 0;
+ needCallsInvalidated = false;
+ seenCall = false;
traverse(node, function(node, type) {
if (type == 'assign') {
if (node[2][0] == 'name') {
@@ -1567,6 +1570,7 @@ function eliminate(ast) {
} else if (type == 'call') {
needGlobalsInvalidated = true;
needMemoryInvalidated = true;
+ seenCall = true;
} else if (type == 'seq' || type in CONTROL_FLOW) {
tracked = {};
ok = false;
@@ -1650,7 +1654,7 @@ function eliminate(ast) {
// try to track
if (type == 'var') {
var node1 = node[1];
- // XXX if we have more than one, disallow tracking things with a call()
+ if (seenCall && node1.length > 1) continue; // if we have a call, we cannot track if there is more than one
for (var j = 0; j < node1.length; j++) {
var node1j = node1[j];
var name = node1j[0];