From b8c670c705279fae14ca7742531950b4f84c849d Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Fri, 21 Feb 2014 18:42:06 -0800 Subject: do not outline the entire stack prelude, including STACKTOP = .. --- tools/js-optimizer.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'tools/js-optimizer.js') diff --git a/tools/js-optimizer.js b/tools/js-optimizer.js index fc195e03..21fce2c2 100644 --- a/tools/js-optimizer.js +++ b/tools/js-optimizer.js @@ -4775,7 +4775,16 @@ function outline(ast) { for (var i = minIndex; i < stats.length; i++) { var stat = stats[i]; if (stat[0] == 'stat') stat = stat[1]; - if (stat[0] == 'assign' && stat[2][0] == 'name' && stat[2][1] == 'sp') minIndex = i+1; // cannot outline |sp = | + if (stat[0] == 'assign' && stat[2][0] == 'name' && stat[2][1] == 'sp') { + // cannot outline |sp = | + minIndex = i+1; + // When followed by a STACKTOP bump, preserve that too (we may need to replace it later) + stat = stats[i+1]; + if (stat[0] == 'stat') stat = stat[1]; + if (stat && stat[0] == 'assign' && stat[2][0] == 'name' && stat[2][1] == 'STACKTOP') { + minIndex = i+2; + } + } } } } -- cgit v1.2.3-70-g09d2 From a18bd727401a8495275c78149dbaae5a0adae0d2 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Sun, 23 Feb 2014 14:21:09 -0800 Subject: add stack bump if only sp is defined but no bump is present, when outlining --- tools/js-optimizer.js | 22 +++++++++++++++++++++- tools/test-js-optimizer-asm-outline2-output.js | 1 + 2 files changed, 22 insertions(+), 1 deletion(-) (limited to 'tools/js-optimizer.js') diff --git a/tools/js-optimizer.js b/tools/js-optimizer.js index 21fce2c2..d393b159 100644 --- a/tools/js-optimizer.js +++ b/tools/js-optimizer.js @@ -4935,7 +4935,27 @@ function outline(ast) { if ('sp' in asmData.vars) { // find stack bump (STACKTOP = STACKTOP + X | 0) and add the extra space var stackBumpNode = getStackBumpNode(stats); - if (stackBumpNode) stackBumpNode[3][2][3][1] = asmData.totalStackSize; + if (stackBumpNode) { + stackBumpNode[3][2][3][1] = asmData.totalStackSize; + } else { + // sp exists, but no stack bump, so we need to add it + var found = false; + for (var i = 0; i < stats.length; i++) { + var stat = stats[i]; + if (stat[0] === 'stat') stat = stat[1]; + if (stat[0] === 'assign' && stat[2][0] === 'name' && stat[2][1] === 'sp') { + var newNode = ['stat', makeAssign(['name', 'STACKTOP'], ['binary', '|', ['binary', '+', ['name', 'STACKTOP'], ['num', asmData.totalStackSize]], ['num', 0]])]; + if (i+1 < stats.length) { + stats.splice(i+1, 0, newNode); + } else { + stats.push(newNode); + } + found = true; + break; + } + } + assert(found); + } } else if (!('sp' in asmData.params)) { // if sp is a param, then we are an outlined function, no need to add stack support for us // add sp variable and stack bump var index = getFirstIndexInNormalized(func, asmData); diff --git a/tools/test-js-optimizer-asm-outline2-output.js b/tools/test-js-optimizer-asm-outline2-output.js index 2658fda0..923cd7df 100644 --- a/tools/test-js-optimizer-asm-outline2-output.js +++ b/tools/test-js-optimizer-asm-outline2-output.js @@ -25,6 +25,7 @@ function _free($mem) { $mem = $mem | 0; var $5 = 0, $10 = 0, $16 = 0, $21 = 0, $25 = 0, $26 = 0, $psize_0 = 0, $p_0 = 0, $189 = 0, $194 = 0, sp = 0, helper$0 = 0; sp = STACKTOP; + STACKTOP = STACKTOP + 864 | 0; if (($mem | 0) == 0) { STACKTOP = sp; return; -- cgit v1.2.3-70-g09d2 From fb9deefc5ac7caaa1b5d2c680a86d9b35238e004 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Sun, 23 Feb 2014 19:44:24 -0800 Subject: disable some outlining logging --- tools/js-optimizer.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'tools/js-optimizer.js') diff --git a/tools/js-optimizer.js b/tools/js-optimizer.js index d393b159..240ee2bd 100644 --- a/tools/js-optimizer.js +++ b/tools/js-optimizer.js @@ -4525,10 +4525,10 @@ function outline(ast) { var size = measureSize(func); if (size <= extraInfo.sizeToOutline) { sizeToOutline = Infinity; - printErr(' no point in trying to reduce the size of ' + func[1] + ' which is ' + size + ' <= ' + extraInfo.sizeToOutline); + //printErr(' no point in trying to reduce the size of ' + func[1] + ' which is ' + size + ' <= ' + extraInfo.sizeToOutline); } else { sizeToOutline = Math.round(size/Math.max(2, asmData.intendedPieces--)); - printErr('trying to reduce the size of ' + func[1] + ' which is ' + size + ' (>=? ' + extraInfo.sizeToOutline + '), aim for ' + sizeToOutline); + //printErr('trying to reduce the size of ' + func[1] + ' which is ' + size + ' (>=? ' + extraInfo.sizeToOutline + '), aim for ' + sizeToOutline); } } @@ -4753,7 +4753,7 @@ function outline(ast) { } } outliningParents[newIdent] = func[1]; - printErr('performed outline ' + [func[1], newIdent, 'pre size', originalCodeSize, 'resulting size', measureSize(code), 'overhead (w/r):', setSize(setSub(codeInfo.writes, owned)), setSize(setSub(codeInfo.reads, owned)), ' owned: ', setSize(owned), ' left: ', setSize(asmData.vars), setSize(asmData.params), ' loopsDepth: ', loops]); + //printErr('performed outline ' + [func[1], newIdent, 'pre size', originalCodeSize, 'resulting size', measureSize(code), 'overhead (w/r):', setSize(setSub(codeInfo.writes, owned)), setSize(setSub(codeInfo.reads, owned)), ' owned: ', setSize(owned), ' left: ', setSize(asmData.vars), setSize(asmData.params), ' loopsDepth: ', loops]); calculateThreshold(func, asmData); return [newFunc]; } @@ -4908,7 +4908,7 @@ function outline(ast) { var maxTotalFunctions = Infinity; // debugging tool - printErr('\n'); + //printErr('\n'); var more = true; while (more) { @@ -4990,7 +4990,7 @@ function outline(ast) { } if (ret) { ret.push(func); - printErr('... resulting sizes of ' + func[1] + ' is ' + ret.map(measureSize) + '\n'); + //printErr('... resulting sizes of ' + func[1] + ' is ' + ret.map(measureSize) + '\n'); } } denormalizeAsm(func, asmData); -- cgit v1.2.3-70-g09d2