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 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 524 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
535 } | 535 } |
536 } else if (expressionType.isArray()) { | 536 } else if (expressionType.isArray()) { |
537 if (element === compiler.listClass | 537 if (element === compiler.listClass |
538 || Elements.isListSupertype(element, compiler)) { | 538 || Elements.isListSupertype(element, compiler)) { |
539 return graph.addConstantBool(true); | 539 return graph.addConstantBool(true); |
540 } else { | 540 } else { |
541 return graph.addConstantBool(false); | 541 return graph.addConstantBool(false); |
542 } | 542 } |
543 // TODO(karlklose): remove the hasTypeArguments check. | 543 // TODO(karlklose): remove the hasTypeArguments check. |
544 } else if (expressionType.isUseful() | 544 } else if (expressionType.isUseful() |
| 545 && !expressionType.canBeNull() |
545 && !compiler.codegenWorld.rti.hasTypeArguments(type)) { | 546 && !compiler.codegenWorld.rti.hasTypeArguments(type)) { |
546 Type receiverType = expressionType.computeType(compiler); | 547 Type receiverType = expressionType.computeType(compiler); |
547 if (receiverType !== null) { | 548 if (receiverType !== null) { |
548 if (compiler.types.isSubtype(receiverType, type)) { | 549 if (compiler.types.isSubtype(receiverType, type)) { |
549 return graph.addConstantBool(true); | 550 return graph.addConstantBool(true); |
550 } else if (expressionType.isExact()) { | 551 } else if (expressionType.isExact()) { |
551 return graph.addConstantBool(false); | 552 return graph.addConstantBool(false); |
552 } | 553 } |
553 } | 554 } |
554 } | 555 } |
555 return node; | 556 return node; |
556 } | 557 } |
557 | 558 |
558 HInstruction visitTypeConversion(HTypeConversion node) { | 559 HInstruction visitTypeConversion(HTypeConversion node) { |
559 HInstruction value = node.inputs[0]; | 560 HInstruction value = node.inputs[0]; |
560 Type type = node.propagatedType.computeType(compiler); | 561 Type type = node.propagatedType.computeType(compiler); |
561 if (type.element === compiler.dynamicClass | 562 if (type.element === compiler.dynamicClass |
562 || type.element === compiler.objectClass) { | 563 || type.element === compiler.objectClass) { |
563 return value; | 564 return value; |
564 } | 565 } |
565 HType combinedType = value.propagatedType.intersection(node.propagatedType); | 566 HType combinedType = value.propagatedType.intersection(node.propagatedType); |
566 return (combinedType == value.propagatedType) ? value : node; | 567 return (combinedType == value.propagatedType) ? value : node; |
567 } | 568 } |
568 | 569 |
569 HInstruction visitInvokeDynamicGetter(HInvokeDynamicGetter node) { | 570 HInstruction visitInvokeDynamicGetter(HInvokeDynamicGetter node) { |
570 HInstruction receiver = node.inputs[0]; | 571 HInstruction receiver = node.inputs[0]; |
571 if (!receiver.propagatedType.isUseful()) return node; | 572 if (!receiver.propagatedType.isUseful()) return node; |
| 573 if (receiver.propagatedType.canBeNull()) return node; |
572 Type type = receiver.propagatedType.computeType(compiler); | 574 Type type = receiver.propagatedType.computeType(compiler); |
573 if (type === null) return node; | 575 if (type === null) return node; |
574 Element field = compiler.world.locateSingleField(type, node.name); | 576 Element field = compiler.world.locateSingleField(type, node.name); |
575 if (field === null) return node; | 577 if (field === null) return node; |
576 Modifiers modifiers = field.modifiers; | 578 Modifiers modifiers = field.modifiers; |
577 bool isFinalOrConst = false; | 579 bool isFinalOrConst = false; |
578 if (modifiers != null) { | 580 if (modifiers != null) { |
579 isFinalOrConst = modifiers.isFinal() || modifiers.isConst(); | 581 isFinalOrConst = modifiers.isFinal() || modifiers.isConst(); |
580 } | 582 } |
581 return new HFieldGet(field, node.inputs[0], isFinalOrConst: isFinalOrConst); | 583 return new HFieldGet(field, node.inputs[0], isFinalOrConst: isFinalOrConst); |
582 } | 584 } |
583 | 585 |
584 HInstruction visitInvokeDynamicSetter(HInvokeDynamicSetter node) { | 586 HInstruction visitInvokeDynamicSetter(HInvokeDynamicSetter node) { |
585 HInstruction receiver = node.inputs[0]; | 587 HInstruction receiver = node.inputs[0]; |
586 if (!receiver.propagatedType.isUseful()) return node; | 588 if (!receiver.propagatedType.isUseful()) return node; |
| 589 if (receiver.propagatedType.canBeNull()) return node; |
587 Type type = receiver.propagatedType.computeType(compiler); | 590 Type type = receiver.propagatedType.computeType(compiler); |
588 if (type === null) return node; | 591 if (type === null) return node; |
589 Element field = compiler.world.locateSingleField(type, node.name); | 592 Element field = compiler.world.locateSingleField(type, node.name); |
590 if (field === null) return node; | 593 if (field === null) return node; |
591 return new HFieldSet(field, node.inputs[0], node.inputs[1]); | 594 return new HFieldSet(field, node.inputs[0], node.inputs[1]); |
592 } | 595 } |
593 | 596 |
594 HInstruction visitStringConcat(HStringConcat node) { | 597 HInstruction visitStringConcat(HStringConcat node) { |
595 DartString folded = const LiteralDartString(""); | 598 DartString folded = const LiteralDartString(""); |
596 for (int i = 0; i < node.inputs.length; i++) { | 599 for (int i = 0; i < node.inputs.length; i++) { |
(...skipping 540 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1137 // the if block terminates. So any use of the instruction | 1140 // the if block terminates. So any use of the instruction |
1138 // after the join block should be changed to the new | 1141 // after the join block should be changed to the new |
1139 // instruction. | 1142 // instruction. |
1140 changeUsesDominatedBy(ifUser.joinBlock, input, convertedType); | 1143 changeUsesDominatedBy(ifUser.joinBlock, input, convertedType); |
1141 } | 1144 } |
1142 // TODO(ngeoffray): Also change uses for the then block on a HType | 1145 // TODO(ngeoffray): Also change uses for the then block on a HType |
1143 // that knows it is not of a specific Type. | 1146 // that knows it is not of a specific Type. |
1144 } | 1147 } |
1145 } | 1148 } |
1146 } | 1149 } |
OLD | NEW |