diff options
author | Alon Zakai <alonzakai@gmail.com> | 2013-08-05 13:14:51 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2013-08-05 13:14:51 -0700 |
commit | b2c870060073adcbfd4c753cd9e1246769b12ff0 (patch) | |
tree | d2205cd8226111227fa473bdc5b734be1eaa5bf5 /tools/js-optimizer.js | |
parent | 045a1ec3138e8a30fa24a9b6d979fdba59d24f47 (diff) |
infrastructure to track the costs of outlining, and to possibly change outlining thresholds as we go
Diffstat (limited to 'tools/js-optimizer.js')
-rw-r--r-- | tools/js-optimizer.js | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/tools/js-optimizer.js b/tools/js-optimizer.js index 29b36cad..c5b21175 100644 --- a/tools/js-optimizer.js +++ b/tools/js-optimizer.js @@ -3106,7 +3106,7 @@ function outline(ast) { // Reserve an extra two spots per possible outlining: one for control flow var, the other for control flow data // The control variables are zeroed out when calling an outlined function, and after using // the value after they return. - asmData.maxOutlinings = Math.round(3*measureSize(func)/sizeToOutline); + asmData.maxOutlinings = Math.round(3*measureSize(func)/extraInfo.sizeToOutline); asmData.totalStackSize = stackSize + (stack.length + 2*asmData.maxOutlinings)*8; asmData.controlStackPos = function(i) { return stackSize + (stack.length + i)*8 }; asmData.controlDataStackPos = function(i) { return stackSize + (stack.length + i)*8 + 4 }; @@ -3210,9 +3210,17 @@ function outline(ast) { var CONTROL_BREAK = 1, CONTROL_BREAK_LABEL = 2, CONTROL_CONTINUE = 3, CONTROL_CONTINUE_LABEL = 4, CONTROL_RETURN_VOID = 5, CONTROL_RETURN_INT = 6, CONTROL_RETURN_DOUBLE = 7; - var sizeToOutline = extraInfo.sizeToOutline; - var level = 0; + var sizeToOutline = null; // customized per function and as we make progress + function calculateThreshold(func) { + sizeToOutline = extraInfo.sizeToOutline; + var size = measureSize(func); + //var desiredChunks = Math.ceil(size/extraInfo.sizeToOutline); + ////sizeToOutline = Math.round((extraInfo.sizeToOutline + (2*size/desiredChunks))/3); + //sizeToOutline = Math.round(size/desiredChunks); + printErr('trying to reduce the size of ' + func[1] + ' which is ' + size + ' (>= ' + extraInfo.sizeToOutline + '), aim for ' + sizeToOutline); + } + var level = 0; var outliningParents = {}; // function name => parent it was outlined from function doOutline(func, asmData, stats, start, end) { @@ -3225,13 +3233,13 @@ function outline(ast) { // analyze variables, and find 'owned' variables - that only appear in the outlined code, and do not need any spill support var codeInfo = analyzeCode(func, asmData, code); var allCodeInfo = analyzeCode(func, asmData, func); - //printErr(' do outline ' + [func[1], level, 'range:', start, end, 'of', stats.length, newIdent, measureSize(code), JSON.stringify(codeInfo.labels), JSON.stringify(codeInfo.breaks), JSON.stringify(codeInfo.continues)]); var owned = { sp: 1 }; // sp is always owned, each has its own keys(setUnion(codeInfo.reads, codeInfo.writes)).forEach(function(v) { if (allCodeInfo.reads[v] === codeInfo.reads[v] && allCodeInfo.writes[v] === codeInfo.writes[v] && !(v in asmData.params)) { owned[v] = 1; } }); + printErr('attempting outline ' + [func[1], newIdent, 'overhead:', setSize(setSub(codeInfo.writes, owned)), setSize(setSub(codeInfo.reads, owned))]); var reps = []; // wipe out control variable reps.push(['stat', makeAssign(makeStackAccess(ASM_INT, asmData.controlStackPos(outlineIndex)), ['num', 0])]); @@ -3426,6 +3434,7 @@ function outline(ast) { } } outliningParents[newIdent] = func[1]; + calculateThreshold(func); return [newFunc]; } @@ -3452,7 +3461,7 @@ function outline(ast) { } while (1) { i--; - calcMinIndex(); + calcMinIndex(); // TODO: optimize if (i < minIndex) { // we might be done. but, if we have just outlined, do a further attempt from the beginning. // (but only if the total costs are not extravagant) @@ -3536,7 +3545,7 @@ function outline(ast) { var newFuncs = doOutline(func, asmData, stats, i, end); // outline [i, .. ,end] inclusive if (newFuncs.length) { ret.push.apply(ret, newFuncs); - printErr('performed outline on ' + func[1] + ' of ' + sizeSeen + ', func is now size ' + measureSize(func) + ' ==> ' + newFuncs[0][1]); + printErr('performed outline on ' + func[1] + ' of ' + sizeSeen + ', => ' + newFuncs[0][1]); } sizeSeen = 0; end = i-1; @@ -3566,10 +3575,10 @@ function outline(ast) { funcs.forEach(function(func) { var asmData = normalizeAsm(func); var size = measureSize(func); - if (size >= sizeToOutline) { - printErr('trying to reduce the size of ' + func[1] + ' which is ' + size + ' (>= ' + sizeToOutline + ')'); + if (size >= extraInfo.sizeToOutline) { aggressiveVariableElimination(func, asmData); flatten(func, asmData); + calculateThreshold(func); analyzeFunction(func, asmData); var stats = getStatements(func); var ret = outlineStatements(func, asmData, stats, 0.9*size); |