| 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 534 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 545 } else if (expressionType.isExact()) { | 545 } else if (expressionType.isExact()) { |
| 546 return graph.addConstantBool(false); | 546 return graph.addConstantBool(false); |
| 547 } | 547 } |
| 548 } | 548 } |
| 549 } | 549 } |
| 550 return node; | 550 return node; |
| 551 } | 551 } |
| 552 | 552 |
| 553 HInstruction visitTypeConversion(HTypeConversion node) { | 553 HInstruction visitTypeConversion(HTypeConversion node) { |
| 554 HInstruction value = node.inputs[0]; | 554 HInstruction value = node.inputs[0]; |
| 555 // If the union of the types is still the input type then | 555 Type type = node.propagatedType.computeType(compiler); |
| 556 // no conversion is required. | 556 if (type.element === compiler.dynamicClass |
| 557 HType combinedType = value.propagatedType.union(node.propagatedType); | 557 || type.element === compiler.objectClass) { |
| 558 return value; |
| 559 } |
| 560 HType combinedType = value.propagatedType.intersection(node.propagatedType); |
| 558 return (combinedType == value.propagatedType) ? value : node; | 561 return (combinedType == value.propagatedType) ? value : node; |
| 559 } | 562 } |
| 560 | 563 |
| 561 HInstruction visitInvokeDynamicGetter(HInvokeDynamicGetter node) { | 564 HInstruction visitInvokeDynamicGetter(HInvokeDynamicGetter node) { |
| 562 HInstruction receiver = node.inputs[0]; | 565 HInstruction receiver = node.inputs[0]; |
| 563 if (!receiver.propagatedType.isUseful()) return node; | 566 if (!receiver.propagatedType.isUseful()) return node; |
| 564 Type type = receiver.propagatedType.computeType(compiler); | 567 Type type = receiver.propagatedType.computeType(compiler); |
| 565 if (type === null) return node; | 568 if (type === null) return node; |
| 566 if (!compiler.world.isOnlyFields(type, node.name)) return node; | 569 if (!compiler.world.isOnlyFields(type, node.name)) return node; |
| 567 return new HFieldGet(node.name, node.inputs[0]); | 570 return new HFieldGet(node.name, node.inputs[0]); |
| (...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1072 } | 1075 } |
| 1073 user.changeUse(input, newInput); | 1076 user.changeUse(input, newInput); |
| 1074 } | 1077 } |
| 1075 } | 1078 } |
| 1076 } | 1079 } |
| 1077 | 1080 |
| 1078 void visitIs(HIs instruction) { | 1081 void visitIs(HIs instruction) { |
| 1079 HInstruction input = instruction.expression; | 1082 HInstruction input = instruction.expression; |
| 1080 HType convertedType = | 1083 HType convertedType = |
| 1081 new HType.fromBoundedType(instruction.typeExpression, compiler); | 1084 new HType.fromBoundedType(instruction.typeExpression, compiler); |
| 1082 if (convertedType === null) return; | |
| 1083 | 1085 |
| 1084 List<HInstruction> ifUsers = <HInstruction>[]; | 1086 List<HInstruction> ifUsers = <HInstruction>[]; |
| 1085 List<HInstruction> notIfUsers = <HInstruction>[]; | 1087 List<HInstruction> notIfUsers = <HInstruction>[]; |
| 1086 | 1088 |
| 1087 for (HInstruction user in instruction.usedBy) { | 1089 for (HInstruction user in instruction.usedBy) { |
| 1088 if (user is HIf) { | 1090 if (user is HIf) { |
| 1089 ifUsers.add(user); | 1091 ifUsers.add(user); |
| 1090 } else if (user is HNot) { | 1092 } else if (user is HNot) { |
| 1091 for (HInstruction notUser in user.usedBy) { | 1093 for (HInstruction notUser in user.usedBy) { |
| 1092 if (notUser is HIf) notIfUsers.add(notUser); | 1094 if (notUser is HIf) notIfUsers.add(notUser); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1110 // the if block terminates. So any use of the instruction | 1112 // the if block terminates. So any use of the instruction |
| 1111 // after the join block should be changed to the new | 1113 // after the join block should be changed to the new |
| 1112 // instruction. | 1114 // instruction. |
| 1113 changeUsesDominatedBy(ifUser.joinBlock, input, convertedType); | 1115 changeUsesDominatedBy(ifUser.joinBlock, input, convertedType); |
| 1114 } | 1116 } |
| 1115 // TODO(ngeoffray): Also change uses for the then block on a HType | 1117 // TODO(ngeoffray): Also change uses for the then block on a HType |
| 1116 // that knows it is not of a specific Type. | 1118 // that knows it is not of a specific Type. |
| 1117 } | 1119 } |
| 1118 } | 1120 } |
| 1119 } | 1121 } |
| OLD | NEW |