aboutsummaryrefslogtreecommitdiff
path: root/tools/js-optimizer.js
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2013-06-06 17:16:30 -0700
committerAlon Zakai <alonzakai@gmail.com>2013-06-06 17:16:30 -0700
commitb970a019bfcf5413dec74f944a25cef633927f1c (patch)
tree24e0cfece9a57dbc65bdb2a4d2b3997da10a6e9d /tools/js-optimizer.js
parent24807a6d8f657b27e0ae6b73e73fa987a0672480 (diff)
move asm loop optimization into last phase
Diffstat (limited to 'tools/js-optimizer.js')
-rw-r--r--tools/js-optimizer.js36
1 files changed, 21 insertions, 15 deletions
diff --git a/tools/js-optimizer.js b/tools/js-optimizer.js
index 57c9cf79..df71ab86 100644
--- a/tools/js-optimizer.js
+++ b/tools/js-optimizer.js
@@ -1805,21 +1805,6 @@ function registerize(ast) {
}
denormalizeAsm(fun, finalAsmData);
}
-
- // Post-registerize optimizations. This is near the end of the pipeline, we can assume all other optimizations except for minification are done
- traverse(fun, function(node, type) {
- if (type == 'while' && node[1][0] == 'num' && node[1][1] == 1 && node[2][0] == 'block') {
- // while (1) { .. if (..) { break } } ==> do { .. } while(..)
- var stats = node[2][1];
- var last = stats[stats.length-1];
- if (last[0] == 'if' && !last[3] && last[2][0] == 'block' && last[2][1][0][0] == 'break' && !last[2][1][0][1]) {
- var conditionToBreak = last[1];
- stats.pop();
- node[0] = 'do';
- node[1] = simplifyNotComps(['unary-prefix', '!', conditionToBreak]);
- }
- }
- });
});
}
@@ -2471,6 +2456,26 @@ function fixDotZero(js) {
});
}
+function asmLoopOptimizer(ast) {
+ traverseGeneratedFunctions(ast, function(fun) {
+ // This is at the end of the pipeline, we can assume all other optimizations are done, and we modify loops
+ // into shapes that might confuse other passes
+ traverse(fun, function(node, type) {
+ if (type == 'while' && node[1][0] == 'num' && node[1][1] == 1 && node[2][0] == 'block') {
+ // while (1) { .. if (..) { break } } ==> do { .. } while(..)
+ var stats = node[2][1];
+ var last = stats[stats.length-1];
+ if (last[0] == 'if' && !last[3] && last[2][0] == 'block' && last[2][1][0][0] == 'break' && !last[2][1][0][1]) {
+ var conditionToBreak = last[1];
+ stats.pop();
+ node[0] = 'do';
+ node[1] = simplifyNotComps(['unary-prefix', '!', conditionToBreak]);
+ }
+ }
+ });
+ });
+}
+
// Passes table
var compress = false, printMetadata = true, asm = false, last = false;
@@ -2514,6 +2519,7 @@ arguments_.slice(1).forEach(function(arg) {
passes[arg](ast);
});
if (asm && last) {
+ asmLoopOptimizer(ast);
prepDotZero(ast);
}
var js = astToSrc(ast, compress), old;