diff options
author | Alon Zakai <alonzakai@gmail.com> | 2013-03-09 19:36:05 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2013-03-09 19:36:05 -0800 |
commit | 4794e95b9ba2ab9104d6da7b0a6c7bf31c2f812a (patch) | |
tree | 666f2d9b435783a7549ba900462f1a9a6645c9b1 | |
parent | ca6e55cbf2fa746697527327aa6f9f5c3b3cab8b (diff) |
move addFinalReturns to simplyExpressionsPre so it runs even in -g
-rw-r--r-- | tools/js-optimizer.js | 36 |
1 files changed, 22 insertions, 14 deletions
diff --git a/tools/js-optimizer.js b/tools/js-optimizer.js index 8df467f8..834c99e3 100644 --- a/tools/js-optimizer.js +++ b/tools/js-optimizer.js @@ -540,9 +540,31 @@ function simplifyExpressionsPre(ast) { }); } + function addFinalReturns(ast) { + traverseGeneratedFunctions(ast, function(fun) { + var returnType = null; + traverse(fun, function(node, type) { + if (type == 'return' && node[1]) { + returnType = detectAsmCoercion(node[1]); + } + }); + // Add a final return if one is missing. + if (returnType !== null) { + var stats = getStatements(fun); + var last = stats[stats.length-1]; + if (last[0] != 'return') { + var returnValue = ['num', 0]; + if (returnType == ASM_DOUBLE) returnValue = ['unary-prefix', '+', returnValue]; + stats.push(['return', returnValue]); + } + } + }); + } + simplifyBitops(ast); joinAdditions(ast); // simplifyZeroComp(ast); TODO: investigate performance + if (asm) addFinalReturns(ast); } // In typed arrays mode 2, we can have @@ -1430,7 +1452,6 @@ function registerize(ast) { // We also mark local variables - i.e., having a var definition var localVars = {}; var hasSwitch = false; // we cannot optimize variables if there is a switch - var returnType = null; // for asm traverse(fun, function(node, type) { if (type == 'var') { node[1].forEach(function(defined) { localVars[defined[0]] = 1 }); @@ -1442,8 +1463,6 @@ function registerize(ast) { } } else if (type == 'switch') { hasSwitch = true; - } else if (asm && type == 'return' && node[1]) { - returnType = detectAsmCoercion(node[1]); } }); vacuum(fun); @@ -1685,17 +1704,6 @@ function registerize(ast) { } } denormalizeAsm(fun, finalAsmData); - // Add a final return if one is missing. This is not strictly a register operation, but - // this pass traverses the entire AST anyhow so adding it here is efficient. - if (returnType !== null) { - var stats = getStatements(fun); - var last = stats[stats.length-1]; - if (last[0] != 'return') { - var returnValue = ['num', 0]; - if (returnType == ASM_DOUBLE) returnValue = ['unary-prefix', '+', returnValue]; - stats.push(['return', returnValue]); - } - } } }); } |