aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2013-07-18 16:07:46 -0700
committerAlon Zakai <alonzakai@gmail.com>2013-07-18 16:08:26 -0700
commita1a7cb6031f7120f229593e00879860ad01d09f5 (patch)
tree2f3fcbd53ecb0cdc0d383dc29abd62b6befa711e /tools
parent646e5af8883c87e4c9b8e709c18fb65520199dc6 (diff)
send variables to outlines code even if just written; they may not be written to, and we would write a zero incorrectly
Diffstat (limited to 'tools')
-rw-r--r--tools/js-optimizer.js8
-rw-r--r--tools/test-js-optimizer-asm-outline1-output.js18
-rw-r--r--tools/test-js-optimizer-asm-outline2-output.js6
3 files changed, 24 insertions, 8 deletions
diff --git a/tools/js-optimizer.js b/tools/js-optimizer.js
index dfc4d5dd..14d26a89 100644
--- a/tools/js-optimizer.js
+++ b/tools/js-optimizer.js
@@ -3118,11 +3118,11 @@ function outline(ast) {
// add spills and reads before and after the call to the outlined code, and in the outlined code itself
var codeInfo = analyzeCode(func, asmData, code);
var reps = [];
- for (var v in codeInfo.reads) {
+ keys(setUnion(codeInfo.reads, codeInfo.writes)).forEach(function(v) {
if (v != 'sp') {
reps.push(['stat', ['assign', true, ['sub', ['name', getAsmType(v, asmData) == ASM_INT ? 'HEAP32' : 'HEAPF32'], ['binary', '>>', ['binary', '+', ['name', 'sp'], ['num', asmData.stackPos[v]]], ['num', '2']]], ['name', v]]]);
}
- }
+ });
reps.push(['stat', ['call', ['name', newIdent], [['name', 'sp']]]]);
for (var v in codeInfo.writes) {
reps.push(['stat', ['assign', true, ['name', v], makeAsmCoercion(['sub', ['name', getAsmType(v, asmData) == ASM_INT ? 'HEAP32' : 'HEAPF32'], ['binary', '>>', ['binary', '+', ['name', 'sp'], ['num', asmData.stackPos[v]]], ['num', '2']]], getAsmType(v, asmData))]]);
@@ -3240,11 +3240,11 @@ function outline(ast) {
}
}
// add spills and unspills in outlined code outside the OL loop
- for (var v in codeInfo.reads) {
+ keys(setUnion(codeInfo.reads, codeInfo.writes)).forEach(function(v) {
if (v != 'sp') {
code.unshift(['stat', ['assign', true, ['name', v], makeAsmCoercion(['sub', ['name', getAsmType(v, asmData) == ASM_INT ? 'HEAP32' : 'HEAPF32'], ['binary', '>>', ['binary', '+', ['name', 'sp'], ['num', asmData.stackPos[v]]], ['num', '2']]], getAsmType(v, asmData))]]);
}
- }
+ });
for (var v in codeInfo.writes) {
code.push(['stat', ['assign', true, ['sub', ['name', getAsmType(v, asmData) == ASM_INT ? 'HEAP32' : 'HEAPF32'], ['binary', '>>', ['binary', '+', ['name', 'sp'], ['num', asmData.stackPos[v]]], ['num', '2']]], ['name', v]]]);
}
diff --git a/tools/test-js-optimizer-asm-outline1-output.js b/tools/test-js-optimizer-asm-outline1-output.js
index 382a7fc7..03d90cb7 100644
--- a/tools/test-js-optimizer-asm-outline1-output.js
+++ b/tools/test-js-optimizer-asm-outline1-output.js
@@ -183,11 +183,13 @@ function vars4(x, y) {
HEAPF32[sp + 8 >> 2] = y;
HEAP32[sp + 0 >> 2] = x;
HEAP32[sp + 16 >> 2] = a;
+ HEAPF32[sp + 24 >> 2] = b;
vars4$1(sp);
b = +HEAPF32[sp + 24 >> 2];
a = HEAP32[sp + 16 >> 2] | 0;
HEAP32[sp + 16 >> 2] = a;
HEAP32[sp + 0 >> 2] = x;
+ HEAPF32[sp + 24 >> 2] = b;
vars4$0(sp);
a = HEAP32[sp + 16 >> 2] | 0;
b = +HEAPF32[sp + 24 >> 2];
@@ -203,10 +205,12 @@ function vars_w_stack(x, y) {
HEAPF32[sp + 24 >> 2] = y;
HEAP32[sp + 16 >> 2] = x;
HEAP32[sp + 32 >> 2] = a;
+ HEAPF32[sp + 40 >> 2] = b;
vars_w_stack$1(sp);
b = +HEAPF32[sp + 40 >> 2];
a = HEAP32[sp + 32 >> 2] | 0;
HEAP32[sp + 32 >> 2] = a;
+ HEAPF32[sp + 40 >> 2] = b;
vars_w_stack$0(sp);
a = HEAP32[sp + 32 >> 2] | 0;
b = +HEAPF32[sp + 40 >> 2];
@@ -429,6 +433,7 @@ function vars3$1(sp) {
function vars4$0(sp) {
sp = sp | 0;
var a = 0, x = 0, b = +0;
+ b = +HEAPF32[sp + 24 >> 2];
x = HEAP32[sp + 0 >> 2] | 0;
a = HEAP32[sp + 16 >> 2] | 0;
a = c(4 + a);
@@ -440,19 +445,22 @@ function vars4$0(sp) {
}
function vars4$1(sp) {
sp = sp | 0;
- var y = +0, x = 0, a = 0;
+ var y = +0, x = 0, a = 0, b = +0;
+ b = +HEAPF32[sp + 24 >> 2];
a = HEAP32[sp + 16 >> 2] | 0;
x = HEAP32[sp + 0 >> 2] | 0;
y = +HEAPF32[sp + 8 >> 2];
+ b = y * x;
a = c(1 + a);
a = c(2 + a);
a = c(3 + a);
- HEAPF32[sp + 24 >> 2] = y * x;
+ HEAPF32[sp + 24 >> 2] = b;
HEAP32[sp + 16 >> 2] = a;
}
function vars_w_stack$0(sp) {
sp = sp | 0;
var a = 0, b = +0;
+ b = +HEAPF32[sp + 40 >> 2];
a = HEAP32[sp + 32 >> 2] | 0;
a = c(4 + a);
a = c(5 + a);
@@ -464,14 +472,16 @@ function vars_w_stack$0(sp) {
}
function vars_w_stack$1(sp) {
sp = sp | 0;
- var y = +0, x = 0, a = 0;
+ var y = +0, x = 0, a = 0, b = +0;
+ b = +HEAPF32[sp + 40 >> 2];
a = HEAP32[sp + 32 >> 2] | 0;
x = HEAP32[sp + 16 >> 2] | 0;
y = +HEAPF32[sp + 24 >> 2];
+ b = y * x;
a = c(1 + a);
a = c(2 + a);
a = c(3 + a);
- HEAPF32[sp + 40 >> 2] = y * x;
+ HEAPF32[sp + 40 >> 2] = b;
HEAP32[sp + 32 >> 2] = a;
}
diff --git a/tools/test-js-optimizer-asm-outline2-output.js b/tools/test-js-optimizer-asm-outline2-output.js
index ced6f71e..d9c292a0 100644
--- a/tools/test-js-optimizer-asm-outline2-output.js
+++ b/tools/test-js-optimizer-asm-outline2-output.js
@@ -68,6 +68,8 @@ function _free($mem) {
HEAP32[sp + 184 >> 2] = $120;
HEAP32[sp + 192 >> 2] = $151;
HEAP32[sp + 200 >> 2] = $164;
+ HEAP32[sp + 216 >> 2] = $p_0;
+ HEAP32[sp + 208 >> 2] = $psize_0;
_free$1(sp);
$p_0 = HEAP32[sp + 216 >> 2] | 0;
$psize_0 = HEAP32[sp + 208 >> 2] | 0;
@@ -166,6 +168,7 @@ function _free($mem) {
HEAP32[sp + 392 >> 2] = $320;
HEAP32[sp + 400 >> 2] = $351;
HEAP32[sp + 408 >> 2] = $364;
+ HEAP32[sp + 416 >> 2] = $psize_1;
_free$0(sp);
$220 = HEAP32[sp + 248 >> 2] | 0;
$227 = HEAP32[sp + 256 >> 2] | 0;
@@ -365,6 +368,7 @@ function linear$1(sp) {
function _free$0(sp) {
sp = sp | 0;
var $16 = 0, $220 = 0, $psize_0 = 0, $p_0 = 0, $189 = 0, $227 = 0, $194 = 0, $233 = 0, $mem = 0, $10 = 0, $236 = 0, $_pre_phi305 = 0, $267 = 0, $270 = 0, $273 = 0, $294 = 0, $299 = 0, $R7_1 = 0, $R7_0 = 0, $RP9_0 = 0, $301 = 0, $302 = 0, $305 = 0, $306 = 0, $278 = 0, $320 = 0, $351 = 0, $364 = 0, $psize_1 = 0;
+ $psize_1 = HEAP32[sp + 416 >> 2] | 0;
$364 = HEAP32[sp + 408 >> 2] | 0;
$351 = HEAP32[sp + 400 >> 2] | 0;
$320 = HEAP32[sp + 392 >> 2] | 0;
@@ -593,6 +597,8 @@ function _free$0(sp) {
function _free$1(sp) {
sp = sp | 0;
var $25 = 0, $mem = 0, $10 = 0, $26 = 0, $21 = 0, $37 = 0, $40 = 0, $5 = 0, $_pre_phi307 = 0, $69 = 0, $72 = 0, $75 = 0, $95 = 0, $100 = 0, $R_1 = 0, $R_0 = 0, $RP_0 = 0, $102 = 0, $103 = 0, $106 = 0, $107 = 0, $80 = 0, $120 = 0, $151 = 0, $164 = 0, $p_0 = 0, $psize_0 = 0;
+ $psize_0 = HEAP32[sp + 208 >> 2] | 0;
+ $p_0 = HEAP32[sp + 216 >> 2] | 0;
$164 = HEAP32[sp + 200 >> 2] | 0;
$151 = HEAP32[sp + 192 >> 2] | 0;
$120 = HEAP32[sp + 184 >> 2] | 0;