Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(304)

Side by Side Diff: pkg/compiler/lib/src/cps_ir/scalar_replacement.dart

Issue 1375513002: dart2js cps: Add helpers for common IR manipulation. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Fix type annotation Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 '../closure.dart' show 10 import '../closure.dart' show
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 for (FieldElement field in writes) { 134 for (FieldElement field in writes) {
135 MutableVariable variable = new MutableVariable(field); 135 MutableVariable variable = new MutableVariable(field);
136 variable.type = new TypeMask.nonNullEmpty(); 136 variable.type = new TypeMask.nonNullEmpty();
137 cells[field] = variable; 137 cells[field] = variable;
138 Primitive initialValue = fieldInitialValues[field]; 138 Primitive initialValue = fieldInitialValues[field];
139 if (initialValue == null) { 139 if (initialValue == null) {
140 assert(allocation is CreateBox); 140 assert(allocation is CreateBox);
141 initialValue = new Constant(new NullConstantValue()); 141 initialValue = new Constant(new NullConstantValue());
142 LetPrim let = new LetPrim(initialValue); 142 LetPrim let = new LetPrim(initialValue);
143 let.primitive.parent = let; 143 let.primitive.parent = let;
144 insertionPoint = insertAtBody(insertionPoint, let); 144 insertionPoint = let..insertBelow(insertionPoint);
145 } 145 }
146 LetMutable let = new LetMutable(variable, initialValue); 146 LetMutable let = new LetMutable(variable, initialValue);
147 let.value.parent = let; 147 let.value.parent = let;
148 insertionPoint = insertAtBody(insertionPoint, let); 148 insertionPoint = let..insertBelow(insertionPoint);
149 } 149 }
150 150
151 // Replace references with MutableVariable operations or references to the 151 // Replace references with MutableVariable operations or references to the
152 // field's value. 152 // field's value.
153 for (Reference ref = allocation.firstRef; ref != null; ref = ref.next) { 153 for (Reference ref = allocation.firstRef; ref != null; ref = ref.next) {
154 Node use = ref.parent; 154 Node use = ref.parent;
155 if (use is GetField) { 155 if (use is GetField) {
156 GetField getField = use; 156 GetField getField = use;
157 MutableVariable variable = cells[getField.field]; 157 MutableVariable variable = cells[getField.field];
158 if (variable != null) { 158 if (variable != null) {
(...skipping 22 matching lines...) Expand all
181 } else { 181 } else {
182 assert(false); 182 assert(false);
183 } 183 }
184 } 184 }
185 185
186 // Delete [allocation] since that might 'free' another scalar replacement 186 // Delete [allocation] since that might 'free' another scalar replacement
187 // candidate by deleting the last non-field-access. 187 // candidate by deleting the last non-field-access.
188 deleteLetPrimOf(allocation); 188 deleteLetPrimOf(allocation);
189 } 189 }
190 190
191 InteriorNode insertAtBody(
192 InteriorNode insertionPoint, InteriorExpression let) {
193 let.parent = insertionPoint;
194 let.body = insertionPoint.body;
195 let.body.parent = let;
196 insertionPoint.body = let;
197 return let;
198 }
199
200 /// Replaces [old] with [primitive] in [old]'s parent [LetPrim]. 191 /// Replaces [old] with [primitive] in [old]'s parent [LetPrim].
201 void replacePrimitive(Primitive old, Primitive primitive) { 192 void replacePrimitive(Primitive old, Primitive primitive) {
202 LetPrim letPrim = old.parent; 193 LetPrim letPrim = old.parent;
203 letPrim.primitive = primitive; 194 letPrim.primitive = primitive;
204 } 195 }
205 196
206 void deleteLetPrimOf(Primitive primitive) { 197 void deleteLetPrimOf(Primitive primitive) {
207 assert(primitive.hasNoUses); 198 assert(primitive.hasNoUses);
208 LetPrim letPrim = primitive.parent; 199 LetPrim letPrim = primitive.parent;
209 Node child = letPrim.body; 200 letPrim.remove();
210 InteriorNode parent = letPrim.parent;
211 child.parent = parent;
212 parent.body = child;
213
214 deletePrimitive(primitive); 201 deletePrimitive(primitive);
215 } 202 }
216 203
217 void deletePrimitive(Primitive primitive) { 204 void deletePrimitive(Primitive primitive) {
218 assert(primitive.hasNoUses); 205 assert(primitive.hasNoUses);
219 removalVisitor.visit(primitive); 206 removalVisitor.visit(primitive);
220 } 207 }
221 208
222 void reconsider(Definition node) { 209 void reconsider(Definition node) {
223 if (node is CreateInstance || node is CreateBox) { 210 if (node is CreateInstance || node is CreateBox) {
(...skipping 25 matching lines...) Expand all
249 class ScalarReplacementRemovalVisitor extends RecursiveVisitor { 236 class ScalarReplacementRemovalVisitor extends RecursiveVisitor {
250 ScalarReplacementVisitor process; 237 ScalarReplacementVisitor process;
251 238
252 ScalarReplacementRemovalVisitor(this.process); 239 ScalarReplacementRemovalVisitor(this.process);
253 240
254 processReference(Reference reference) { 241 processReference(Reference reference) {
255 process.reconsider(reference.definition); 242 process.reconsider(reference.definition);
256 reference.unlink(); 243 reference.unlink();
257 } 244 }
258 } 245 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/cps_ir/remove_refinements.dart ('k') | pkg/compiler/lib/src/cps_ir/share_interceptors.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698