| 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 494 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 505 Element element = type.element; | 505 Element element = type.element; |
| 506 if (element.kind === ElementKind.TYPE_VARIABLE) { | 506 if (element.kind === ElementKind.TYPE_VARIABLE) { |
| 507 compiler.unimplemented("visitIs for type variables"); | 507 compiler.unimplemented("visitIs for type variables"); |
| 508 } | 508 } |
| 509 | 509 |
| 510 HType expressionType = types[node.expression]; | 510 HType expressionType = types[node.expression]; |
| 511 if (element === compiler.objectClass | 511 if (element === compiler.objectClass |
| 512 || element === compiler.dynamicClass) { | 512 || element === compiler.dynamicClass) { |
| 513 return graph.addConstantBool(true, constantSystem); | 513 return graph.addConstantBool(true, constantSystem); |
| 514 } else if (expressionType.isInteger()) { | 514 } else if (expressionType.isInteger()) { |
| 515 if (element === compiler.intClass || element === compiler.numClass) { | 515 if (element === compiler.intClass |
| 516 || element === compiler.numClass |
| 517 || Elements.isNumberOrStringSupertype(element, compiler)) { |
| 516 return graph.addConstantBool(true, constantSystem); | 518 return graph.addConstantBool(true, constantSystem); |
| 517 } else if (element === compiler.doubleClass) { | 519 } else if (element === compiler.doubleClass) { |
| 518 // We let the JS semantics decide for that check. Currently | 520 // We let the JS semantics decide for that check. Currently |
| 519 // the code we emit will always return true. | 521 // the code we emit will always return true. |
| 520 return node; | 522 return node; |
| 521 } else { | 523 } else { |
| 522 return graph.addConstantBool(false, constantSystem); | 524 return graph.addConstantBool(false, constantSystem); |
| 523 } | 525 } |
| 524 } else if (expressionType.isDouble()) { | 526 } else if (expressionType.isDouble()) { |
| 525 if (element === compiler.doubleClass || element === compiler.numClass) { | 527 if (element === compiler.doubleClass |
| 528 || element === compiler.numClass |
| 529 || Elements.isNumberOrStringSupertype(element, compiler)) { |
| 526 return graph.addConstantBool(true, constantSystem); | 530 return graph.addConstantBool(true, constantSystem); |
| 527 } else if (element === compiler.intClass) { | 531 } else if (element === compiler.intClass) { |
| 528 // We let the JS semantics decide for that check. Currently | 532 // We let the JS semantics decide for that check. Currently |
| 529 // the code we emit will return true for a double that can be | 533 // the code we emit will return true for a double that can be |
| 530 // represented as a 31-bit integer and for -0.0. | 534 // represented as a 31-bit integer and for -0.0. |
| 531 return node; | 535 return node; |
| 532 } else { | 536 } else { |
| 533 return graph.addConstantBool(false, constantSystem); | 537 return graph.addConstantBool(false, constantSystem); |
| 534 } | 538 } |
| 535 } else if (expressionType.isNumber()) { | 539 } else if (expressionType.isNumber()) { |
| 536 if (element === compiler.numClass) { | 540 if (element === compiler.numClass) { |
| 537 return graph.addConstantBool(true, constantSystem); | 541 return graph.addConstantBool(true, constantSystem); |
| 538 } | 542 } |
| 539 // We cannot just return false, because the expression may be of | 543 // We cannot just return false, because the expression may be of |
| 540 // type int or double. | 544 // type int or double. |
| 541 } else if (expressionType.isString()) { | 545 } else if (expressionType.isString()) { |
| 542 if (element === compiler.stringClass | 546 if (element === compiler.stringClass |
| 543 || Elements.isStringSupertype(element, compiler)) { | 547 || Elements.isStringOnlySupertype(element, compiler) |
| 548 || Elements.isNumberOrStringSupertype(element, compiler)) { |
| 544 return graph.addConstantBool(true, constantSystem); | 549 return graph.addConstantBool(true, constantSystem); |
| 545 } else { | 550 } else { |
| 546 return graph.addConstantBool(false, constantSystem); | 551 return graph.addConstantBool(false, constantSystem); |
| 547 } | 552 } |
| 548 } else if (expressionType.isArray()) { | 553 } else if (expressionType.isArray()) { |
| 549 if (element === compiler.listClass | 554 if (element === compiler.listClass |
| 550 || Elements.isListSupertype(element, compiler)) { | 555 || Elements.isListSupertype(element, compiler)) { |
| 551 return graph.addConstantBool(true, constantSystem); | 556 return graph.addConstantBool(true, constantSystem); |
| 552 } else { | 557 } else { |
| 553 return graph.addConstantBool(false, constantSystem); | 558 return graph.addConstantBool(false, constantSystem); |
| (...skipping 791 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1345 // this type for the field is still a strong signal | 1350 // this type for the field is still a strong signal |
| 1346 // indicating the expected type of the field. | 1351 // indicating the expected type of the field. |
| 1347 types[field] = type; | 1352 types[field] = type; |
| 1348 } else { | 1353 } else { |
| 1349 // If there are no invoked setters we know the type of | 1354 // If there are no invoked setters we know the type of |
| 1350 // this field for sure. | 1355 // this field for sure. |
| 1351 field.guaranteedType = type; | 1356 field.guaranteedType = type; |
| 1352 } | 1357 } |
| 1353 } | 1358 } |
| 1354 } | 1359 } |
| OLD | NEW |