| 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 interface OptimizationPhase { | 5 interface OptimizationPhase { |
| 6 String get name(); | 6 String get name(); |
| 7 void visitGraph(HGraph graph); | 7 void visitGraph(HGraph graph); |
| 8 } | 8 } |
| 9 | 9 |
| 10 class SsaOptimizerTask extends CompilerTask { | 10 class SsaOptimizerTask extends CompilerTask { |
| (...skipping 1178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1189 } | 1189 } |
| 1190 | 1190 |
| 1191 HInstruction visitEquals(HEquals node) { | 1191 HInstruction visitEquals(HEquals node) { |
| 1192 // Try to optimize the case where a field which is known to always be an | 1192 // Try to optimize the case where a field which is known to always be an |
| 1193 // integer is compared with a constant integer literal. | 1193 // integer is compared with a constant integer literal. |
| 1194 if (node.left is HFieldGet && | 1194 if (node.left is HFieldGet && |
| 1195 node.right is HConstant && | 1195 node.right is HConstant && |
| 1196 node.right.isInteger()) { | 1196 node.right.isInteger()) { |
| 1197 HFieldGet left = node.left; | 1197 HFieldGet left = node.left; |
| 1198 HConstant right = node.right; | 1198 HConstant right = node.right; |
| 1199 if (left.element != null) { | 1199 if (left.element != null && left.element.enclosingElement.isClass()) { |
| 1200 Type type = left.receiver.propagatedType.computeType(compiler); | |
| 1201 switch (compiler.phase) { | 1200 switch (compiler.phase) { |
| 1202 case Compiler.PHASE_COMPILING: | 1201 case Compiler.PHASE_COMPILING: |
| 1203 if (compiler.codegenWorld.couldHaveFieldOnlyIntegerSetters( | 1202 if (backend.onlyFieldIntegerSettersSoFar(left.element) && |
| 1204 type, left.element.name) && | 1203 backend.couldHaveFieldSingleTypeInitializers( |
| 1205 compiler.codegenWorld.hasFieldOnlyIntegerInitializers( | 1204 left.element, HType.INTEGER)) { |
| 1206 type, left.element.name)) { | |
| 1207 compiler.enqueuer.codegen.registerRecompilationCandidate( | 1205 compiler.enqueuer.codegen.registerRecompilationCandidate( |
| 1208 work.element); | 1206 work.element); |
| 1209 } | 1207 } |
| 1210 break; | 1208 break; |
| 1211 case Compiler.PHASE_RECOMPILING: | 1209 case Compiler.PHASE_RECOMPILING: |
| 1212 if (compiler.codegenWorld.hasFieldOnlyIntegerSetters( | 1210 if (backend.onlyFieldIntegerSettersSoFar(left.element) && |
| 1213 type, left.element.name) && | 1211 backend.hasFieldSingleTypeInitializers( |
| 1214 compiler.codegenWorld.hasFieldOnlyIntegerInitializers( | 1212 left.element, HType.INTEGER)) { |
| 1215 type, left.element.name)) { | |
| 1216 if (compiler.codegenWorld.hasInvokedSetter(left.element, | 1213 if (compiler.codegenWorld.hasInvokedSetter(left.element, |
| 1217 compiler)) { | 1214 compiler)) { |
| 1218 // If there are invoked setters we don't know for sure that the | 1215 // If there are invoked setters we don't know for sure that the |
| 1219 // field will hold an integer, but the fact that the class | 1216 // field will hold an integer, but the fact that the class |
| 1220 // itself always sets an integer in the fiels is still a strong | 1217 // itself always sets an integer in the fiels is still a strong |
| 1221 // signal to indiate the expected type of the field. | 1218 // signal to indiate the expected type of the field. |
| 1222 left.propagatedType = HType.INTEGER; | 1219 left.propagatedType = HType.INTEGER; |
| 1223 graph.highTypeLikelyhood = true; | 1220 graph.highTypeLikelyhood = true; |
| 1224 } else { | 1221 } else { |
| 1225 // If there are no invoked setters we know the type of this | 1222 // If there are no invoked setters we know the type of this |
| 1226 // field for sure. | 1223 // field for sure. |
| 1227 left.guaranteedType = HType.INTEGER; | 1224 left.guaranteedType = HType.INTEGER; |
| 1228 } | 1225 } |
| 1229 } | 1226 } |
| 1230 break; | 1227 break; |
| 1231 default: | 1228 default: |
| 1232 assert(false); | 1229 assert(false); |
| 1233 break; | 1230 break; |
| 1234 } | 1231 } |
| 1235 } | 1232 } |
| 1236 } | 1233 } |
| 1237 } | 1234 } |
| 1238 } | 1235 } |
| OLD | NEW |