| 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 class SsaOptimizerTask extends CompilerTask { | 5 class SsaOptimizerTask extends CompilerTask { |
| 6 SsaOptimizerTask(Compiler compiler) : super(compiler); | 6 SsaOptimizerTask(Compiler compiler) : super(compiler); |
| 7 String get name() => 'SSA optimizer'; | 7 String get name() => 'SSA optimizer'; |
| 8 | 8 |
| 9 void optimize(WorkItem work, HGraph graph) { | 9 void optimize(WorkItem work, HGraph graph) { |
| 10 measure(() { | 10 measure(() { |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 => node.fold(); | 96 => node.fold(); |
| 97 | 97 |
| 98 HInstruction visitAdd(HAdd node) { | 98 HInstruction visitAdd(HAdd node) { |
| 99 // String + is defined for all literals. We don't need to know which | 99 // String + is defined for all literals. We don't need to know which |
| 100 // literal type the right-hand side is. | 100 // literal type the right-hand side is. |
| 101 | 101 |
| 102 if (node.left.isString()) { | 102 if (node.left.isString()) { |
| 103 // First try to eliminate adding the empty string to a string. | 103 // First try to eliminate adding the empty string to a string. |
| 104 if (node.right.isLiteralString()) { | 104 if (node.right.isLiteralString()) { |
| 105 HLiteral right = node.right; | 105 HLiteral right = node.right; |
| 106 QuotedString rightString = right.value; | 106 DartString rightString = right.value; |
| 107 if (rightString.isEmpty()) { | 107 if (rightString.isEmpty()) { |
| 108 // String has no content, i.e., it's the empty string. | 108 // String has no content, i.e., it's the empty string. |
| 109 return node.left; | 109 return node.left; |
| 110 } | 110 } |
| 111 } | 111 } |
| 112 // Then, if both are literals, try to do the concatenation statically. | 112 // Then, if both are literals, try to do the concatenation statically. |
| 113 if (node.left.isLiteralString()) { | 113 if (node.left.isLiteralString()) { |
| 114 HLiteral left = node.left; | 114 HLiteral left = node.left; |
| 115 QuotedString leftString = left.value; | 115 DartString leftString = left.value; |
| 116 if (leftString.isEmpty()) { | 116 if (leftString.isEmpty()) { |
| 117 // Left is empty String. | 117 // Left is empty String. |
| 118 if (node.right.isString()) { | 118 if (node.right.isString()) { |
| 119 // Right is already a String, just return that. | 119 // Right is already a String, just return that. |
| 120 return node.right; | 120 return node.right; |
| 121 } | 121 } |
| 122 if (node.right is HLiteral) { | 122 if (node.right is HLiteral) { |
| 123 HLiteral right = node.right; | 123 HLiteral right = node.right; |
| 124 // Right is a literal, so we can statically convert it to String | 124 // Right is a literal, so we can statically convert it to String |
| 125 // and return that. | 125 // and return that. |
| 126 // Remaining literal types are represented by their Dart value. | 126 // Remaining literal types are represented by their Dart value. |
| 127 assert(right.isLiteralBoolean() || | 127 assert(right.isLiteralBoolean() || |
| 128 right.isLiteralNumber() || | 128 right.isLiteralNumber() || |
| 129 right.isLiteralNull()); | 129 right.isLiteralNull()); |
| 130 String str; | 130 String str; |
| 131 // Workaround Frog bug. Issue #595. | 131 // Workaround Frog bug. Issue #595. |
| 132 if (right.isLiteralNull()) { | 132 if (right.isLiteralNull()) { |
| 133 str = 'null'; | 133 str = 'null'; |
| 134 } else { | 134 } else { |
| 135 str = right.value.toString(); | 135 str = right.value.toString(); |
| 136 } | 136 } |
| 137 return new HLiteral(new QuotedString.literal(str), HType.STRING); | 137 return new HLiteral(new DartString.literal(str), HType.STRING); |
| 138 } | 138 } |
| 139 } | 139 } |
| 140 // TODO(lrn): Perform concatenation in Dart. | 140 // TODO(lrn): Perform concatenation in Dart. |
| 141 } | 141 } |
| 142 } | 142 } |
| 143 return visitInvokeBinary(node); | 143 return visitInvokeBinary(node); |
| 144 } | 144 } |
| 145 | 145 |
| 146 HInstruction visitEquals(HEquals node) { | 146 HInstruction visitEquals(HEquals node) { |
| 147 if (node.left is HLiteral && node.right is HLiteral) { | 147 if (node.left is HLiteral && node.right is HLiteral) { |
| (...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 605 } | 605 } |
| 606 } | 606 } |
| 607 if (!canBeMoved) continue; | 607 if (!canBeMoved) continue; |
| 608 | 608 |
| 609 // This is safe because we are running after GVN. | 609 // This is safe because we are running after GVN. |
| 610 // TODO(ngeoffray): ensure GVN has been run. | 610 // TODO(ngeoffray): ensure GVN has been run. |
| 611 set_.add(current); | 611 set_.add(current); |
| 612 } | 612 } |
| 613 } | 613 } |
| 614 } | 614 } |
| OLD | NEW |