| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 library dart2js.cps_ir.scalar_replacement; | 4 library dart2js.cps_ir.scalar_replacement; |
| 5 | 5 |
| 6 import 'optimizers.dart'; | 6 import 'optimizers.dart'; |
| 7 | 7 |
| 8 import 'dart:collection' show Queue; | 8 import 'dart:collection' show Queue; |
| 9 | 9 |
| 10 import '../common.dart'; | 10 import '../common.dart'; |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 _current = allocation; | 68 _current = allocation; |
| 69 tryScalarReplacement(allocation); | 69 tryScalarReplacement(allocation); |
| 70 } | 70 } |
| 71 } | 71 } |
| 72 | 72 |
| 73 void tryScalarReplacement(Primitive allocation) { | 73 void tryScalarReplacement(Primitive allocation) { |
| 74 | 74 |
| 75 // We can do scalar replacement of an aggregate if all uses of an allocation | 75 // We can do scalar replacement of an aggregate if all uses of an allocation |
| 76 // are reads or writes. | 76 // are reads or writes. |
| 77 for (Reference ref = allocation.firstRef; ref != null; ref = ref.next) { | 77 for (Reference ref = allocation.firstRef; ref != null; ref = ref.next) { |
| 78 // TODO(asgerf): Also handle ReadTypeVariable. |
| 78 Node use = ref.parent; | 79 Node use = ref.parent; |
| 79 if (use is GetField) continue; | 80 if (use is GetField) continue; |
| 80 if (use is SetField && use.object == ref) continue; | 81 if (use is SetField && use.object == ref) continue; |
| 81 return; | 82 return; |
| 82 } | 83 } |
| 83 | 84 |
| 84 Set<FieldElement> reads = new Set<FieldElement>(); | 85 Set<FieldElement> reads = new Set<FieldElement>(); |
| 85 Set<FieldElement> writes = new Set<FieldElement>(); | 86 Set<FieldElement> writes = new Set<FieldElement>(); |
| 86 for (Reference ref = allocation.firstRef; ref != null; ref = ref.next) { | 87 for (Reference ref = allocation.firstRef; ref != null; ref = ref.next) { |
| 87 Node use = ref.parent; | 88 Node use = ref.parent; |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 class ScalarReplacementRemovalVisitor extends TrampolineRecursiveVisitor { | 221 class ScalarReplacementRemovalVisitor extends TrampolineRecursiveVisitor { |
| 221 ScalarReplacementVisitor process; | 222 ScalarReplacementVisitor process; |
| 222 | 223 |
| 223 ScalarReplacementRemovalVisitor(this.process); | 224 ScalarReplacementRemovalVisitor(this.process); |
| 224 | 225 |
| 225 processReference(Reference reference) { | 226 processReference(Reference reference) { |
| 226 process.reconsider(reference.definition); | 227 process.reconsider(reference.definition); |
| 227 reference.unlink(); | 228 reference.unlink(); |
| 228 } | 229 } |
| 229 } | 230 } |
| OLD | NEW |