Chromium Code Reviews| Index: lib/compiler/implementation/ssa/codegen.dart |
| diff --git a/lib/compiler/implementation/ssa/codegen.dart b/lib/compiler/implementation/ssa/codegen.dart |
| index 8784c2b9ffda835e34308f2dc83adf128a451fe9..fc2b1717ff3f0b13fc4347947c15b3045514b1c9 100644 |
| --- a/lib/compiler/implementation/ssa/codegen.dart |
| +++ b/lib/compiler/implementation/ssa/codegen.dart |
| @@ -85,6 +85,7 @@ class SsaCodeGenerator implements HVisitor { |
| final Map<HPhi, String> logicalOperations; |
| final Map<Element, ElementAction> breakAction; |
| final Map<Element, ElementAction> continueAction; |
| + final Equivalence<HPhi> phiEquivalence; |
| Element equalsNullElement; |
| int indent = 0; |
| @@ -125,7 +126,8 @@ class SsaCodeGenerator implements HVisitor { |
| generateAtUseSite = new Set<HInstruction>(), |
| logicalOperations = new Map<HPhi, String>(), |
| breakAction = new Map<Element, ElementAction>(), |
| - continueAction = new Map<Element, ElementAction>() { |
| + continueAction = new Map<Element, ElementAction>(), |
| + phiEquivalence = new Equivalence<HPhi>() { |
| for (final name in parameterNames.getValues()) { |
| prefixes[name] = 0; |
| @@ -167,6 +169,7 @@ class SsaCodeGenerator implements HVisitor { |
| new SsaInstructionMerger(generateAtUseSite).visitGraph(graph); |
| new SsaConditionMerger(generateAtUseSite, |
| logicalOperations).visitGraph(graph); |
| + new PhiEquivalator(phiEquivalence, logicalOperations).analyzeGraph(graph); |
| } |
| visitGraph(HGraph graph) { |
| @@ -570,6 +573,7 @@ class SsaCodeGenerator implements HVisitor { |
| addIndentation(); |
| buffer.add("}\n"); |
| } else { |
| + addIndentation(); |
| buffer.add(") {\n"); |
| indent++; |
| wrapLoopBodyForContinue(info); |
| @@ -633,15 +637,27 @@ class SsaCodeGenerator implements HVisitor { |
| // In case the phi is being generated by another |
| // instruction. |
| if (isLogicalOperation && isGenerateAtUseSite(phi)) return; |
| + HPhi canonicalPhi = phiEquivalence.getRepresentative(phi); |
| + HInstruction input = phi.inputs[index]; |
| + if (input is HPhi) { |
| + HPhi inputPhi = input; |
| + HPhi canonicalInput = phiEquivalence.getRepresentative(inputPhi); |
| + // If we use the same variable, we don't need to create an |
| + // assingment. |
|
floitsch
2012/04/11 11:44:39
assignment
Lasse Reichstein Nielsen
2012/04/11 11:55:26
Done.
|
| + if (canonicalInput == canonicalPhi) { |
| + assert(!isLogicalOperation); |
| + return; |
| + } |
| + } |
| if (isGeneratingExpression()) { |
| addExpressionSeparator(); |
| } else { |
| addIndentation(); |
| } |
| - if (!temporaryExists(phi)) { |
| - declareVariable(temporary(phi)); |
| + if (!temporaryExists(canonicalPhi)) { |
| + declareVariable(temporary(canonicalPhi)); |
| } else { |
| - buffer.add(temporary(phi)); |
| + buffer.add(temporary(canonicalPhi)); |
| } |
| buffer.add(" = "); |
| if (isLogicalOperation) { |
| @@ -1179,7 +1195,8 @@ class SsaCodeGenerator implements HVisitor { |
| if (operation !== null) { |
| emitLogicalOperation(node, operation); |
| } else { |
| - buffer.add('${temporary(node)}'); |
| + HPhi canonicalPhi = phiEquivalence.getRepresentative(node); |
| + buffer.add('${temporary(canonicalPhi)}'); |
| } |
| } |