aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2012-05-12 09:37:20 -0700
committerAlon Zakai <alonzakai@gmail.com>2012-05-12 09:37:20 -0700
commitb60d5fb0a60a2a95697a8547c6ae3010e97779af (patch)
treef85e7580593c4c34bc1f02ddb86f4af5628595e8
parent725d1a3ab6c3d5d504bc4db81bac36c95deae4f1 (diff)
simply compiler by always pushing back phis
-rw-r--r--src/analyzer.js111
-rw-r--r--src/jsifier.js24
2 files changed, 35 insertions, 100 deletions
diff --git a/src/analyzer.js b/src/analyzer.js
index cbb4f28e..23f56712 100644
--- a/src/analyzer.js
+++ b/src/analyzer.js
@@ -1278,89 +1278,44 @@ function analyzer(data, sidePass) {
recomputeLines(func);
}
- if (!MICRO_OPTS) {
- // 'Emulate' phis, by doing an if where the phi appears in the .ll. For this
- // we need __lastLabel__.
- func.needsLastLabel = false;
- func.labels.forEach(function(label) {
- var phis = [];
- label.lines.forEach(function(phi) {
- if (phi.intertype == 'phi') {
- for (var i = 0; i < phi.params.length; i++) {
- var sourceLabelId = getActualLabelId(phi.params[i].label);
- if (sourceLabelId) {
- var sourceLabel = func.labelsDict[sourceLabelId];
- var lastLine = sourceLabel.lines.slice(-1)[0];
- assert(lastLine.intertype in LLVM.PHI_REACHERS, 'Only some can lead to labels with phis:' + [func.ident, label.ident, lastLine.intertype]);
- lastLine.currLabelId = sourceLabelId;
- }
- }
- phis.push(phi);
- func.needsLastLabel = true;
- }
- });
+ // Properly implement phis, by pushing them back into the branch
+ // that leads to here. We will only have the |var| definition in this location.
- if (phis.length >= 2) {
- // Multiple phis have the semantics that they all occur 'in parallel', i.e., changes to
- // a variable that is the result of a phi should *not* affect the other results. We must
- // therefore be careful!
- phis[phis.length-1].postSet = '; /* post-phi: */';
- for (var i = 0; i < phis.length-1; i++) {
- var ident = phis[i].assignTo;
- var phid = ident+'$phi'
- phis[phis.length-1].postSet += ident + '=' + phid + ';';
- phis[i].assignTo = phid;
- func.variables[phid] = {
- ident: phid,
- type: func.variables[ident].type,
- origin: func.variables[ident].origin,
- lineNum: func.variables[ident].lineNum,
- uses: 1,
- impl: VAR_EMULATED
- };
- }
- }
- });
- } else {
- // MICRO_OPTS == 1: Properly implement phis, by pushing them back into the branch
- // that leads to here. We will only have the |var| definition in this location.
-
- // First, push phis back
- func.labels.forEach(function(label) {
- label.lines.forEach(function(phi) {
- if (phi.intertype == 'phi') {
- for (var i = 0; i < phi.params.length; i++) {
- var param = phi.params[i];
- assert(param.label);
- var sourceLabelId = getActualLabelId(param.label);
- if (sourceLabelId) {
- var sourceLabel = func.labelsDict[sourceLabelId];
- var lastLine = sourceLabel.lines.slice(-1)[0];
- assert(lastLine.intertype in LLVM.PHI_REACHERS, 'Only some can lead to labels with phis:' + [func.ident, label.ident, lastLine.intertype]);
- if (!lastLine.phi) {
- lastLine.phi = true;
- assert(!lastLine.dependent);
- lastLine.dependent = {
- intertype: 'phiassigns',
- params: []
- };
+ // First, push phis back
+ func.labels.forEach(function(label) {
+ label.lines.forEach(function(phi) {
+ if (phi.intertype == 'phi') {
+ for (var i = 0; i < phi.params.length; i++) {
+ var param = phi.params[i];
+ assert(param.label);
+ var sourceLabelId = getActualLabelId(param.label);
+ if (sourceLabelId) {
+ var sourceLabel = func.labelsDict[sourceLabelId];
+ var lastLine = sourceLabel.lines.slice(-1)[0];
+ assert(lastLine.intertype in LLVM.PHI_REACHERS, 'Only some can lead to labels with phis:' + [func.ident, label.ident, lastLine.intertype]);
+ if (!lastLine.phi) {
+ lastLine.phi = true;
+ assert(!lastLine.dependent);
+ lastLine.dependent = {
+ intertype: 'phiassigns',
+ params: []
};
- lastLine.dependent.params.push({
- intertype: 'phiassign',
- ident: phi.assignTo,
- value: param.value,
- targetLabel: label.ident
- });
- }
+ };
+ lastLine.dependent.params.push({
+ intertype: 'phiassign',
+ ident: phi.assignTo,
+ value: param.value,
+ targetLabel: label.ident
+ });
}
- // The assign to phi is now just a var
- phi.intertype = 'var';
- phi.ident = phi.assignTo;
- phi.assignTo = null;
}
- });
+ // The assign to phi is now just a var
+ phi.intertype = 'var';
+ phi.ident = phi.assignTo;
+ phi.assignTo = null;
+ }
});
- }
+ });
});
this.forwardItem(item, 'StackAnalyzer');
}
diff --git a/src/jsifier.js b/src/jsifier.js
index 89930918..6cbe8b88 100644
--- a/src/jsifier.js
+++ b/src/jsifier.js
@@ -558,9 +558,6 @@ function JSify(data, functionsOnly, givenFunctions) {
if (CLOSURE_ANNOTATIONS) func.JS += '/** @type {number} */';
func.JS += ' var __label__;\n';
}
- if (func.needsLastLabel) {
- func.JS += ' var __lastLabel__ = null;\n';
- }
// Walk function blocks and generate JS
function walkBlock(block, indent) {
@@ -751,7 +748,7 @@ function JSify(data, functionsOnly, givenFunctions) {
makeFuncLineActor('noop', function(item) {
return ';';
});
- makeFuncLineActor('var', function(item) { // assigns into phis become simple vars when MICRO_OPTS
+ makeFuncLineActor('var', function(item) { // assigns into phis become simple vars
return 'var ' + item.ident + ';';
});
makeFuncLineActor('store', function(item) {
@@ -792,11 +789,8 @@ function JSify(data, functionsOnly, givenFunctions) {
return label;
}
- function makeBranch(label, lastLabel, labelIsVariable) {
+ function makeBranch(label, lastLabel, labelIsVariable) { // lastLabel is deprecated
var pre = '';
- if (!MICRO_OPTS && lastLabel) {
- pre = '__lastLabel__ = ' + getLabelId(lastLabel) + '; ';
- }
if (label[0] == 'B') {
assert(!labelIsVariable, 'Cannot handle branches to variables with special branching options');
var parts = label.split('|');
@@ -1064,20 +1058,6 @@ function JSify(data, functionsOnly, givenFunctions) {
return RuntimeGenerator.stackAlloc(getFastValue(calcAllocatedSize(item.allocatedType), '*', item.allocatedNum));
}
});
- makeFuncLineActor('phi', function(item) {
- var params = item.params;
- assert(!MICRO_OPTS);
- function makeOne(i) {
- if (i === params.length-1) {
- return finalizeLLVMParameter(params[i].value);
- }
- return '__lastLabel__ == ' + getLabelId(params[i].label) + ' ? ' +
- finalizeLLVMParameter(params[i].value) + ' : (' + makeOne(i+1) + ')';
- }
- var ret = makeOne(0);
- if (item.postSet) ret += item.postSet;
- return ret;
- });
makeFuncLineActor('mathop', processMathop);