aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoralon@honor <none@none>2010-10-15 21:22:52 -0700
committeralon@honor <none@none>2010-10-15 21:22:52 -0700
commit5c33e208873515258c577350f2e006c1563b12af (patch)
treea6dd5dd23a4e77d1240c3c19ed2fbf899dcef3e3
parent518031af3274ba14eb0efdbd994d0986b61ee4f1 (diff)
do not wind/unwind stacks if initial stack size is 0; 20% speedup
-rw-r--r--src/analyzer.js7
-rw-r--r--src/jsifier.js3
-rw-r--r--src/runtime.js7
3 files changed, 12 insertions, 5 deletions
diff --git a/src/analyzer.js b/src/analyzer.js
index 2a0ee701..8d77b13d 100644
--- a/src/analyzer.js
+++ b/src/analyzer.js
@@ -313,10 +313,11 @@ function analyzer(data) {
var total = 0;
var lines = func.labels[0].lines;
for (var i = 0; i < lines.length; i++) {
- var item = lines[i].value;
+ var line = lines[i];
+ var item = line.value;
if (!item || item.intertype != 'alloca') break;
- // FIXME: This ignores nativized variables, but probably negligible
- item.allocatedSize = calcAllocatedSize(item.allocatedType, data.types);
+ item.allocatedSize = func.variables[line.ident].impl === VAR_EMULATED ?
+ calcAllocatedSize(item.allocatedType, data.types) : 0;
total += item.allocatedSize;
}
func.initialStack = total;
diff --git a/src/jsifier.js b/src/jsifier.js
index 597b0c31..32b284ad 100644
--- a/src/jsifier.js
+++ b/src/jsifier.js
@@ -546,7 +546,7 @@ function JSify(data) {
return ret;
});
makeFuncLineZyme('return', function(item) {
- var ret = RuntimeGenerator.stackExit() + '\n';
+ var ret = RuntimeGenerator.stackExit(item.funcData.initialStack) + ';\n';
if (LABEL_DEBUG) ret += "INDENT = INDENT.substr(0, INDENT.length-2);\n";
ret += 'return';
if (item.value) {
@@ -583,6 +583,7 @@ function JSify(data) {
});
makeFuncLineZyme('alloca', function(item) {
assert(typeof item.allocatedIndex === 'number'); // or, return RuntimeGenerator.stackAlloc(calcAllocatedSize(item.allocatedType, TYPES));
+ if (item.allocatedSize === 0) return ''; // This will not actually be shown - it's nativized
return getFastValue('STACKTOP', '-', item.allocatedIndex.toString());
});
makeFuncLineZyme('phi', function(item) {
diff --git a/src/runtime.js b/src/runtime.js
index 0ae70fa3..d6a545c2 100644
--- a/src/runtime.js
+++ b/src/runtime.js
@@ -26,6 +26,10 @@ RuntimeGenerator = {
},
stackEnter: function(initial) {
+ if (initial === 0) return ''; // XXX Note that we don't even push the stack! This is faster, but
+ // means that we don't clear stack allocations done in this function
+ // until the parent unwinds its stack. So potentially if we are in
+ // a loop, we can use a lot of memory.
var ret = 'STACK_STACK.push(STACKTOP); STACKTOP += ' + initial;
if (GUARD_MEMORY) {
ret += '; assert(STACKTOP < STACK_MAX)';
@@ -33,7 +37,8 @@ RuntimeGenerator = {
return ret;
},
- stackExit: function() {
+ stackExit: function(initial) {
+ if (initial === 0) return ''; // XXX See comment in stackEnter
return 'STACKTOP = STACK_STACK.pop();';
},