aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2011-11-18 16:11:09 -0800
committerAlon Zakai <alonzakai@gmail.com>2011-11-18 16:11:09 -0800
commitfbfbdba4bf1913fe0a97d1e3ca5b1c14a38c8964 (patch)
treeaf2cde3c6f3dc6e8a9849107ce5d95916d554156
parent067f13f4c89c35011c722cd8441bbf1a1ffe4543 (diff)
minor optimization for phi
-rw-r--r--src/jsifier.js22
1 files changed, 17 insertions, 5 deletions
diff --git a/src/jsifier.js b/src/jsifier.js
index a4340623..2da90219 100644
--- a/src/jsifier.js
+++ b/src/jsifier.js
@@ -704,12 +704,10 @@ function JSify(data, functionsOnly, givenFunctions, givenGlobalVariables) {
function calcPhiSets(item) {
if (!item.phi) return null;
var phiSets = {};
- // TODO: Do not always rename them all
- // TODO: eliminate unneeded sets (to undefined etc.)
item.params.forEach(function(param) {
if (!phiSets[param.targetLabel]) phiSets[param.targetLabel] = [];
- phiSets[param.targetLabel].unshift('var ' + param.ident + '$phi = ' + finalizeLLVMParameter(param.value) + ';');
- phiSets[param.targetLabel].push(param.ident + ' = ' + param.ident + '$phi;');
+ phiSets[param.targetLabel].push(param);
+ param.valueJS = finalizeLLVMParameter(param.value);
});
return phiSets;
}
@@ -717,7 +715,21 @@ function JSify(data, functionsOnly, givenFunctions, givenGlobalVariables) {
function getPhiSetsForLabel(phiSets, label) {
label = getOldLabel(label);
if (!phiSets || !phiSets[label]) return '';
- return sumStringy(phiSets[label]);
+ var labelSets = phiSets[label];
+ if (labelSets.length == 1) {
+ return 'var ' + labelSets[0].ident + ' = ' + labelSets[0].valueJS + ';';
+ }
+ // TODO: optimize number of copies
+ // TODO: eliminate unneeded sets (to undefined etc.)
+ var ret = '';
+ for (var i = 0; i < labelSets.length-1; i++) {
+ ret += 'var ' + labelSets[i].ident + '$phi = ' + labelSets[i].valueJS + ';';
+ }
+ ret += labelSets[labelSets.length-1].ident + ' = ' + labelSets[labelSets.length-1].valueJS + ';';
+ for (var i = 0; i < labelSets.length-1; i++) {
+ ret += labelSets[i].ident + ' = ' + labelSets[i].ident + '$phi;';
+ }
+ return '/* phi */' + ret;
}
makeFuncLineActor('branch', function(item) {