Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 class SsaTypePropagator extends HGraphVisitor implements OptimizationPhase { | 5 class SsaTypePropagator extends HGraphVisitor implements OptimizationPhase { |
| 6 | 6 |
| 7 final Map<int, HInstruction> workmap; | 7 final Map<int, HInstruction> workmap; |
| 8 final List<int> worklist; | 8 final List<int> worklist; |
| 9 final Compiler compiler; | 9 final Compiler compiler; |
| 10 String get name() => 'type propagator'; | 10 String get name() => 'type propagator'; |
| 11 | 11 |
| 12 SsaTypePropagator(Compiler this.compiler) | 12 SsaTypePropagator(Compiler this.compiler) |
| 13 : workmap = new Map<int, HInstruction>(), | 13 : workmap = new Map<int, HInstruction>(), |
| 14 worklist = new List<int>(); | 14 worklist = new List<int>(); |
| 15 | 15 |
| 16 | 16 |
| 17 HType computeType(HInstruction instruction) { | 17 HType computeType(HInstruction instruction) { |
| 18 return instruction.computeTypeFromInputTypes(); | 18 return instruction.computeTypeFromInputTypes(); |
| 19 } | 19 } |
| 20 | 20 |
| 21 // Re-compute and update the type of the instruction. Returns | 21 // Re-compute and update the type of the instruction. Returns |
| 22 // whether or not the type was changed. | 22 // whether or not the type was changed. |
| 23 bool updateType(HInstruction instruction) { | 23 bool updateType(HInstruction instruction) { |
| 24 if (instruction.propagatedType.isConflicting()) return false; | |
| 25 | |
| 26 HType oldType = instruction.propagatedType; | 24 HType oldType = instruction.propagatedType; |
| 27 HType newType = instruction.hasGuaranteedType() | 25 HType newType = instruction.hasGuaranteedType() |
| 28 ? instruction.guaranteedType | 26 ? instruction.guaranteedType |
| 29 : computeType(instruction); | 27 : computeType(instruction); |
| 30 instruction.propagatedType = oldType.combine(newType); | 28 // We unconditionally replace the propagated type with the new type. The |
| 31 return oldType !== instruction.propagatedType; | 29 // computeType must make sure that we eventually reach a stable state. |
| 30 instruction.propagatedType = newType; | |
| 31 return oldType !== newType; | |
| 32 } | 32 } |
| 33 | 33 |
| 34 void visitGraph(HGraph graph) { | 34 void visitGraph(HGraph graph) { |
| 35 visitDominatorTree(graph); | 35 visitDominatorTree(graph); |
| 36 processWorklist(); | 36 processWorklist(); |
| 37 } | 37 } |
| 38 | 38 |
| 39 visitBasicBlock(HBasicBlock block) { | 39 visitBasicBlock(HBasicBlock block) { |
| 40 if (block.isLoopHeader()) { | 40 if (block.isLoopHeader()) { |
| 41 block.forEachPhi((HPhi phi) { | 41 block.forEachPhi((HPhi phi) { |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 112 for (final user in instruction.usedBy) { | 112 for (final user in instruction.usedBy) { |
| 113 desiredType = | 113 desiredType = |
| 114 desiredType.combine(user.computeDesiredTypeForInput(instruction)); | 114 desiredType.combine(user.computeDesiredTypeForInput(instruction)); |
| 115 // No need to continue if two users disagree on the type. | 115 // No need to continue if two users disagree on the type. |
| 116 if (desiredType.isConflicting()) break; | 116 if (desiredType.isConflicting()) break; |
| 117 } | 117 } |
| 118 return desiredType; | 118 return desiredType; |
| 119 } | 119 } |
| 120 | 120 |
| 121 HType computeType(HInstruction instruction) { | 121 HType computeType(HInstruction instruction) { |
| 122 // Once we are in a conflicting state don't update the type anymore. | |
| 123 if (instruction.propagatedType.isConflicting()) { | |
|
kasperl
2012/04/18 11:46:15
Cache instruction.propagatedType in a local variab
floitsch
2012/04/18 17:18:46
Done.
| |
| 124 return instruction.propagatedType; | |
| 125 } | |
| 126 | |
| 122 HType newType = super.computeType(instruction); | 127 HType newType = super.computeType(instruction); |
| 123 // [computeDesiredType] goes to all usedBys and lets them compute their | 128 // [computeDesiredType] goes to all usedBys and lets them compute their |
| 124 // desired type. By setting the [newType] here we give them more context to | 129 // desired type. By setting the [newType] here we give them more context to |
| 125 // work with. | 130 // work with. |
| 126 instruction.propagatedType = newType; | 131 instruction.propagatedType = newType; |
| 127 HType desiredType = computeDesiredType(instruction); | 132 HType desiredType = computeDesiredType(instruction); |
| 128 // If the desired type is conflicting just return the computed type. | 133 // If the desired type is conflicting just return the computed type. |
| 129 if (desiredType.isConflicting()) return newType; | 134 if (desiredType.isConflicting()) return newType; |
| 130 return newType.combine(desiredType); | 135 return newType.combine(desiredType); |
| 131 } | 136 } |
| 132 } | 137 } |
| OLD | NEW |