| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 part of ssa; | 5 part of ssa; |
| 6 | 6 |
| 7 abstract class OptimizationPhase { | 7 abstract class OptimizationPhase { |
| 8 String get name; | 8 String get name; |
| 9 void visitGraph(HGraph graph); | 9 void visitGraph(HGraph graph); |
| 10 } | 10 } |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 } | 116 } |
| 117 | 117 |
| 118 visitBasicBlock(HBasicBlock block) { | 118 visitBasicBlock(HBasicBlock block) { |
| 119 HInstruction instruction = block.first; | 119 HInstruction instruction = block.first; |
| 120 while (instruction != null) { | 120 while (instruction != null) { |
| 121 HInstruction next = instruction.next; | 121 HInstruction next = instruction.next; |
| 122 HInstruction replacement = instruction.accept(this); | 122 HInstruction replacement = instruction.accept(this); |
| 123 if (replacement != instruction) { | 123 if (replacement != instruction) { |
| 124 block.rewrite(instruction, replacement); | 124 block.rewrite(instruction, replacement); |
| 125 | 125 |
| 126 // If we can replace [instruction] with [replacement], then | 126 // The intersection of double and int return conflicting, and |
| 127 // [replacement]'s type can be narrowed. | 127 // because of our number implementation for JavaScript, it |
| 128 TypeMask newType = replacement.instructionType.intersection( | 128 // might be that an operation thought to return double, can be |
| 129 instruction.instructionType, compiler); | 129 // simplified to an int. For example: |
| 130 replacement.instructionType = newType; | 130 // `2.5 * 10`. |
| 131 if (!(replacement.isNumberOrNull(compiler) |
| 132 && instruction.isNumberOrNull(compiler))) { |
| 133 // If we can replace [instruction] with [replacement], then |
| 134 // [replacement]'s type can be narrowed. |
| 135 TypeMask newType = replacement.instructionType.intersection( |
| 136 instruction.instructionType, compiler); |
| 137 replacement.instructionType = newType; |
| 138 } |
| 131 | 139 |
| 132 // If the replacement instruction does not know its | 140 // If the replacement instruction does not know its |
| 133 // source element, use the source element of the | 141 // source element, use the source element of the |
| 134 // instruction. | 142 // instruction. |
| 135 if (replacement.sourceElement == null) { | 143 if (replacement.sourceElement == null) { |
| 136 replacement.sourceElement = instruction.sourceElement; | 144 replacement.sourceElement = instruction.sourceElement; |
| 137 } | 145 } |
| 138 if (replacement.sourcePosition == null) { | 146 if (replacement.sourcePosition == null) { |
| 139 replacement.sourcePosition = instruction.sourcePosition; | 147 replacement.sourcePosition = instruction.sourcePosition; |
| 140 } | 148 } |
| (...skipping 1800 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1941 | 1949 |
| 1942 keyedValues.forEach((receiver, values) { | 1950 keyedValues.forEach((receiver, values) { |
| 1943 result.keyedValues[receiver] = | 1951 result.keyedValues[receiver] = |
| 1944 new Map<HInstruction, HInstruction>.from(values); | 1952 new Map<HInstruction, HInstruction>.from(values); |
| 1945 }); | 1953 }); |
| 1946 | 1954 |
| 1947 result.nonEscapingReceivers.addAll(nonEscapingReceivers); | 1955 result.nonEscapingReceivers.addAll(nonEscapingReceivers); |
| 1948 return result; | 1956 return result; |
| 1949 } | 1957 } |
| 1950 } | 1958 } |
| OLD | NEW |