Chromium Code Reviews| 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 1170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1181 compiler.enqueuer.codegen.registerRecompilationCandidate( | 1181 compiler.enqueuer.codegen.registerRecompilationCandidate( |
| 1182 work.element); | 1182 work.element); |
| 1183 } | 1183 } |
| 1184 break; | 1184 break; |
| 1185 case Compiler.PHASE_RECOMPILING: | 1185 case Compiler.PHASE_RECOMPILING: |
| 1186 if (!type.isConflicting() && !type.isUnknown()) { | 1186 if (!type.isConflicting() && !type.isUnknown()) { |
| 1187 // Check if optimistic type is based on a setter in the constructor | 1187 // Check if optimistic type is based on a setter in the constructor |
| 1188 // body. | 1188 // body. |
| 1189 if (backend.hasConstructorBodyFieldSetter(field)) { | 1189 if (backend.hasConstructorBodyFieldSetter(field)) { |
| 1190 // There is at least one field setter from the constructor. | 1190 // There is at least one field setter from the constructor. |
| 1191 // TODO(sgjesse): Collect the type for all the field setters so that | 1191 if (!compiler.codegenWorld.hasInvokedSetter(field, compiler)) { |
|
Mads Ager (google)
2012/07/05 13:55:19
Should this be the resolverWorld? Are you sure tha
Mads Ager (google)
2012/07/05 13:56:53
Ignore me, this is during recompilation so this is
| |
| 1192 // this could be a guarenteed type if all field setters have the | 1192 node.guaranteedType = |
| 1193 // same type and there are no invoked setters. | 1193 type.union(backend.fieldSettersTypeSoFar(node.element)); |
| 1194 node.propagatedType = type; | 1194 } else { |
| 1195 node.propagatedType = | |
| 1196 type.union(backend.fieldSettersTypeSoFar(node.element)); | |
| 1197 } | |
| 1195 } else { | 1198 } else { |
| 1196 // Optimistic type is based in field initializer list. | 1199 // Optimistic type is based on field initializer list. |
| 1197 if (!compiler.codegenWorld.hasFieldSetter(field, compiler) && | 1200 if (!compiler.codegenWorld.hasFieldSetter(field, compiler) && |
| 1198 !compiler.codegenWorld.hasInvokedSetter(field, compiler)) { | 1201 !compiler.codegenWorld.hasInvokedSetter(field, compiler)) { |
| 1199 node.guaranteedType = type; | 1202 node.guaranteedType = type; |
| 1200 } else { | 1203 } else { |
| 1201 node.propagatedType = type; | 1204 node.propagatedType = type; |
| 1202 } | 1205 } |
| 1203 } | 1206 } |
| 1204 } | 1207 } |
| 1205 break; | 1208 break; |
| 1206 } | 1209 } |
| 1207 } | 1210 } |
| 1208 | 1211 |
| 1209 HInstruction visitEquals(HEquals node) { | 1212 HInstruction visitEquals(HEquals node) { |
| 1210 // Try to optimize the case where a field which is known to always be an | 1213 // Try to optimize the case where a field which is known to always be an |
| 1211 // integer is compared with a constant integer literal. | 1214 // integer is compared with a constant integer literal. |
| 1212 if (node.left is HFieldGet && | 1215 if (node.left is HFieldGet && |
| 1213 node.right is HConstant && | 1216 node.right is HConstant && |
| 1214 node.right.isInteger()) { | 1217 node.right.isInteger()) { |
| 1215 HFieldGet left = node.left; | 1218 HFieldGet left = node.left; |
| 1216 HConstant right = node.right; | 1219 HConstant right = node.right; |
| 1217 if (left.element != null && left.element.enclosingElement.isClass()) { | 1220 if (left.element != null && left.element.enclosingElement.isClass()) { |
| 1218 switch (compiler.phase) { | 1221 switch (compiler.phase) { |
| 1219 case Compiler.PHASE_COMPILING: | 1222 case Compiler.PHASE_COMPILING: |
| 1220 if (backend.onlyFieldIntegerSettersSoFar(left.element) && | 1223 if ((backend.fieldSettersTypeSoFar(left.element).isUnknown() || |
|
Mads Ager (google)
2012/07/05 13:42:53
We should probably generalize these things as well
Søren Gjesse
2012/07/06 04:10:32
Will do.
| |
| 1224 backend.fieldSettersTypeSoFar(left.element).isInteger()) && | |
| 1221 backend.couldHaveFieldSingleTypeInitializers( | 1225 backend.couldHaveFieldSingleTypeInitializers( |
| 1222 left.element, HType.INTEGER)) { | 1226 left.element, HType.INTEGER)) { |
| 1223 compiler.enqueuer.codegen.registerRecompilationCandidate( | 1227 compiler.enqueuer.codegen.registerRecompilationCandidate( |
| 1224 work.element); | 1228 work.element); |
| 1225 } | 1229 } |
| 1226 break; | 1230 break; |
| 1227 case Compiler.PHASE_RECOMPILING: | 1231 case Compiler.PHASE_RECOMPILING: |
| 1228 if (backend.onlyFieldIntegerSettersSoFar(left.element) && | 1232 if (backend.fieldSettersTypeSoFar(left.element).isInteger() && |
| 1229 backend.hasFieldSingleTypeInitializers( | 1233 backend.hasFieldSingleTypeInitializers( |
| 1230 left.element, HType.INTEGER)) { | 1234 left.element, HType.INTEGER)) { |
| 1231 if (compiler.codegenWorld.hasInvokedSetter(left.element, | 1235 if (compiler.codegenWorld.hasInvokedSetter(left.element, |
| 1232 compiler)) { | 1236 compiler)) { |
| 1233 // If there are invoked setters we don't know for sure that the | 1237 // If there are invoked setters we don't know for sure that the |
| 1234 // field will hold an integer, but the fact that the class | 1238 // field will hold an integer, but the fact that the class |
| 1235 // itself always sets an integer in the fiels is still a strong | 1239 // itself always sets an integer in the fiels is still a strong |
| 1236 // signal to indiate the expected type of the field. | 1240 // signal to indiate the expected type of the field. |
| 1237 left.propagatedType = HType.INTEGER; | 1241 left.propagatedType = HType.INTEGER; |
| 1238 graph.highTypeLikelyhood = true; | 1242 graph.highTypeLikelyhood = true; |
| 1239 } else { | 1243 } else { |
| 1240 // If there are no invoked setters we know the type of this | 1244 // If there are no invoked setters we know the type of this |
| 1241 // field for sure. | 1245 // field for sure. |
| 1242 left.guaranteedType = HType.INTEGER; | 1246 left.guaranteedType = HType.INTEGER; |
| 1243 } | 1247 } |
| 1244 } | 1248 } |
| 1245 break; | 1249 break; |
| 1246 default: | 1250 default: |
| 1247 assert(false); | 1251 assert(false); |
| 1248 break; | 1252 break; |
| 1249 } | 1253 } |
| 1250 } | 1254 } |
| 1251 } | 1255 } |
| 1252 } | 1256 } |
| 1253 | 1257 |
| 1254 } | 1258 } |
| OLD | NEW |