aboutsummaryrefslogtreecommitdiff
path: root/tools/js-optimizer.js
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2012-05-16 11:15:36 -0700
committerAlon Zakai <alonzakai@gmail.com>2012-05-16 11:15:36 -0700
commit74fd2c236f8865d1a9c00bdace466bee8ed2eb1c (patch)
tree63e5f847a92fc54a2aed1de51582fdff9df6f6c3 /tools/js-optimizer.js
parentf0d31ed4996a3f194f81d40fc14d1cbc93dd9a42 (diff)
bugfix in registerize
Diffstat (limited to 'tools/js-optimizer.js')
-rw-r--r--tools/js-optimizer.js8
1 files changed, 6 insertions, 2 deletions
diff --git a/tools/js-optimizer.js b/tools/js-optimizer.js
index e76f58f2..59492dbd 100644
--- a/tools/js-optimizer.js
+++ b/tools/js-optimizer.js
@@ -1223,6 +1223,10 @@ function registerize(ast) {
// since they can potentially be returned to. Optimizable variables lock onto
// loops that they enter, unoptimizable variables lock in a conservative way
// into the topmost loop.
+ // Note that we cannot lock onto a variable in a loop if it was used and free'd
+ // before! (then they could overwrite us in the early part of the loop). For now
+ // we just use a fresh register to make sure we avoid this, but it could be
+ // optimized to check for safe registers (free, and not used in this loop level).
var varRegs = {}; // maps variables to the register they will use all their life
var freeRegs = [];
var nextReg = 1;
@@ -1238,7 +1242,7 @@ function registerize(ast) {
var reg = varRegs[name];
if (!reg) {
// acquire register
- if (freeRegs.length > 0) {
+ if (optimizables[name] && freeRegs.length > 0) {
reg = freeRegs.pop();
saved++;
} else {
@@ -1301,7 +1305,7 @@ function registerize(ast) {
}
getStatements(fun).unshift(['var', vars]);
}
- printErr(fun[1] + ': saved ' + saved + ' vars through registerization');
+ printErr(fun[1] + ': saved ' + saved + ' / ' + (saved + nextReg - 1) + ' vars through registerization'); // not totally accurate
});
}