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 537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 548 HInstruction value = node.inputs[0]; | 548 HInstruction value = node.inputs[0]; |
| 549 Type type = node.propagatedType.computeType(compiler); | 549 Type type = node.propagatedType.computeType(compiler); |
| 550 if (type.element === compiler.dynamicClass | 550 if (type.element === compiler.dynamicClass |
| 551 || type.element === compiler.objectClass) { | 551 || type.element === compiler.objectClass) { |
| 552 return value; | 552 return value; |
| 553 } | 553 } |
| 554 HType combinedType = value.propagatedType.intersection(node.propagatedType); | 554 HType combinedType = value.propagatedType.intersection(node.propagatedType); |
| 555 return (combinedType == value.propagatedType) ? value : node; | 555 return (combinedType == value.propagatedType) ? value : node; |
| 556 } | 556 } |
| 557 | 557 |
| 558 Element findConcreteFieldForDynamicAccess(HInstruction receiver, | |
|
kasperl
2012/08/16 12:47:57
Can you use a selector instead of the fieldName he
floitsch
2012/08/16 16:15:55
Done.
| |
| 559 SourceString fieldName) { | |
| 560 if (!receiver.propagatedType.isUseful()) return null; | |
| 561 if (receiver.propagatedType.canBeNull()) return null; | |
| 562 Type type = receiver.propagatedType.computeType(compiler); | |
| 563 if (type === null) return null; | |
| 564 // TODO(floitsch): the library should not come from the current work item. | |
| 565 // Otherwise we cannot inline. | |
| 566 LibraryElement library = work.element.getLibrary(); | |
| 567 Element field = compiler.world.locateSingleField(type, library, fieldName); | |
| 568 return field; | |
| 569 } | |
| 570 | |
| 558 HInstruction visitInvokeDynamicGetter(HInvokeDynamicGetter node) { | 571 HInstruction visitInvokeDynamicGetter(HInvokeDynamicGetter node) { |
| 559 HInstruction receiver = node.inputs[0]; | 572 Element field = findConcreteFieldForDynamicAccess(node.receiver, node.name); |
| 560 if (!receiver.propagatedType.isUseful()) return node; | 573 if (field == null) return node; |
| 561 if (receiver.propagatedType.canBeNull()) return node; | 574 |
| 562 Type type = receiver.propagatedType.computeType(compiler); | |
| 563 if (type === null) return node; | |
| 564 Element field = compiler.world.locateSingleField(type, node.name); | |
| 565 if (field === null) return node; | |
| 566 Modifiers modifiers = field.modifiers; | 575 Modifiers modifiers = field.modifiers; |
| 567 bool isFinalOrConst = false; | 576 bool isFinalOrConst = false; |
| 568 if (modifiers != null) { | 577 if (modifiers != null) { |
| 569 isFinalOrConst = modifiers.isFinal() || modifiers.isConst(); | 578 isFinalOrConst = modifiers.isFinal() || modifiers.isConst(); |
| 570 } | 579 } |
| 571 if (!compiler.resolverWorld.hasInvokedSetter(field, compiler)) { | 580 if (!compiler.resolverWorld.hasInvokedSetter(field, compiler)) { |
| 572 // If no setter is ever used for this field it is only initialized in the | 581 // If no setter is ever used for this field it is only initialized in the |
| 573 // initializer list. | 582 // initializer list. |
| 574 isFinalOrConst = true; | 583 isFinalOrConst = true; |
| 575 } | 584 } |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 587 // un-initialized or initialized in the constructor initializer list. | 596 // un-initialized or initialized in the constructor initializer list. |
| 588 isFinalOrConst = true; | 597 isFinalOrConst = true; |
| 589 break; | 598 break; |
| 590 } | 599 } |
| 591 } | 600 } |
| 592 return new HFieldGet.withElement( | 601 return new HFieldGet.withElement( |
| 593 field, node.inputs[0], isFinalOrConst: isFinalOrConst); | 602 field, node.inputs[0], isFinalOrConst: isFinalOrConst); |
| 594 } | 603 } |
| 595 | 604 |
| 596 HInstruction visitInvokeDynamicSetter(HInvokeDynamicSetter node) { | 605 HInstruction visitInvokeDynamicSetter(HInvokeDynamicSetter node) { |
| 597 HInstruction receiver = node.inputs[0]; | 606 Element field = findConcreteFieldForDynamicAccess(node.receiver, node.name); |
| 598 if (!receiver.propagatedType.isUseful()) return node; | |
| 599 if (receiver.propagatedType.canBeNull()) return node; | |
| 600 Type type = receiver.propagatedType.computeType(compiler); | |
| 601 if (type === null) return node; | |
| 602 Element field = compiler.world.locateSingleField(type, node.name); | |
| 603 if (field === null) return node; | 607 if (field === null) return node; |
| 604 return new HFieldSet.withElement(field, node.inputs[0], node.inputs[1]); | 608 return new HFieldSet.withElement(field, node.inputs[0], node.inputs[1]); |
| 605 } | 609 } |
| 606 | 610 |
| 607 HInstruction visitStringConcat(HStringConcat node) { | 611 HInstruction visitStringConcat(HStringConcat node) { |
| 608 DartString folded = const LiteralDartString(""); | 612 DartString folded = const LiteralDartString(""); |
| 609 for (int i = 0; i < node.inputs.length; i++) { | 613 for (int i = 0; i < node.inputs.length; i++) { |
| 610 HInstruction part = node.inputs[i]; | 614 HInstruction part = node.inputs[i]; |
| 611 if (!part.isConstant()) return node; | 615 if (!part.isConstant()) return node; |
| 612 HConstant constant = part; | 616 HConstant constant = part; |
| (...skipping 693 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1306 // this type for the field is still a strong signal | 1310 // this type for the field is still a strong signal |
| 1307 // indicating the expected type of the field. | 1311 // indicating the expected type of the field. |
| 1308 field.propagatedType = type; | 1312 field.propagatedType = type; |
| 1309 } else { | 1313 } else { |
| 1310 // If there are no invoked setters we know the type of | 1314 // If there are no invoked setters we know the type of |
| 1311 // this field for sure. | 1315 // this field for sure. |
| 1312 field.guaranteedType = type; | 1316 field.guaranteedType = type; |
| 1313 } | 1317 } |
| 1314 } | 1318 } |
| 1315 } | 1319 } |
| OLD | NEW |