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

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

Issue 1380513002: Revert "dart2js cps: Add helpers for common IR manipulation." (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: 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 4
5 library dart2js.cps_ir.redundant_join_elimination; 5 library dart2js.cps_ir.redundant_join_elimination;
6 6
7 import 'cps_ir_nodes.dart'; 7 import 'cps_ir_nodes.dart';
8 import 'optimizers.dart'; 8 import 'optimizers.dart';
9 9
10 /// Eliminates redundant join points. 10 /// Eliminates redundant join points.
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 while (true) { 57 while (true) {
58 Node parent = node.parent; 58 Node parent = node.parent;
59 if (parent is LetCont) { 59 if (parent is LetCont) {
60 node = parent; 60 node = parent;
61 } else { 61 } else {
62 return parent; 62 return parent;
63 } 63 }
64 } 64 }
65 } 65 }
66 66
67 /// Removes [movedNode] from its current position and inserts it
68 /// before [target].
69 void moveToBefore(Expression target, LetCont movedNode) {
70 if (movedNode.parent != null) {
71 movedNode.parent.body = movedNode.body;
72 movedNode.body.parent = movedNode.parent;
73 }
74 InteriorNode parent = target.parent;
75 parent.body = movedNode;
76 movedNode.body = target;
77 target.parent = movedNode;
78 movedNode.parent = parent;
79 }
80
67 void rewriteBranch(Branch branch) { 81 void rewriteBranch(Branch branch) {
68 InteriorNode parent = getEffectiveParent(branch); 82 InteriorNode parent = getEffectiveParent(branch);
69 if (parent is! Continuation) return; 83 if (parent is! Continuation) return;
70 Continuation branchCont = parent; 84 Continuation branchCont = parent;
71 85
72 // Other optimizations take care of single-use continuations. 86 // Other optimizations take care of single-use continuations.
73 if (!branchCont.hasMultipleUses) return; 87 if (!branchCont.hasMultipleUses) return;
74 88
75 // It might be beneficial to rewrite calls to recursive continuations, 89 // It might be beneficial to rewrite calls to recursive continuations,
76 // but we currently do not support this. 90 // but we currently do not support this.
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 if (use is InvokeContinuation) { 154 if (use is InvokeContinuation) {
141 for (Parameter param in branchCont.parameters) { 155 for (Parameter param in branchCont.parameters) {
142 use.arguments.add(new Reference<Primitive>(param)); 156 use.arguments.add(new Reference<Primitive>(param));
143 } 157 }
144 } else { 158 } else {
145 // The branch will be eliminated, so don't worry about updating it. 159 // The branch will be eliminated, so don't worry about updating it.
146 assert(use == branch); 160 assert(use == branch);
147 } 161 }
148 } 162 }
149 } 163 }
150 innerLetCont.remove(); 164 moveToBefore(outerLetCont, innerLetCont);
151 innerLetCont.insertAbove(outerLetCont);
152 } 165 }
153 166
154 assert(branchCont.body == branch); 167 assert(branchCont.body == branch);
155 168
156 Continuation trueCont = branch.trueContinuation.definition; 169 Continuation trueCont = branch.trueContinuation.definition;
157 Continuation falseCont = branch.falseContinuation.definition; 170 Continuation falseCont = branch.falseContinuation.definition;
158 171
159 assert(branchCont != trueCont); 172 assert(branchCont != trueCont);
160 assert(branchCont != falseCont); 173 assert(branchCont != falseCont);
161 174
(...skipping 14 matching lines...) Expand all
176 } 189 }
177 assert(branchCont.firstRef != reference); 190 assert(branchCont.firstRef != reference);
178 } 191 }
179 192
180 // Remove the now-unused branchCont continuation. 193 // Remove the now-unused branchCont continuation.
181 assert(branchCont.hasNoUses); 194 assert(branchCont.hasNoUses);
182 branch.trueContinuation.unlink(); 195 branch.trueContinuation.unlink();
183 branch.falseContinuation.unlink(); 196 branch.falseContinuation.unlink();
184 outerLetCont.continuations.remove(branchCont); 197 outerLetCont.continuations.remove(branchCont);
185 if (outerLetCont.continuations.isEmpty) { 198 if (outerLetCont.continuations.isEmpty) {
186 outerLetCont.remove(); 199 InteriorNode parent = outerLetCont.parent;
200 parent.body = outerLetCont.body;
201 outerLetCont.body.parent = parent;
187 } 202 }
188 203
189 // We may have created new redundant join points in the two branches. 204 // We may have created new redundant join points in the two branches.
190 enqueueContinuation(trueCont); 205 enqueueContinuation(trueCont);
191 enqueueContinuation(falseCont); 206 enqueueContinuation(falseCont);
192 } 207 }
193 208
194 void enqueueContinuation(Continuation cont) { 209 void enqueueContinuation(Continuation cont) {
195 Expression body = getEffectiveBody(cont); 210 Expression body = getEffectiveBody(cont);
196 if (body is Branch) { 211 if (body is Branch) {
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 }); 266 });
252 } 267 }
253 268
254 processReference(Reference ref) { 269 processReference(Reference ref) {
255 Parameter target = renaming[ref.definition]; 270 Parameter target = renaming[ref.definition];
256 if (target != null) { 271 if (target != null) {
257 ref.changeTo(target); 272 ref.changeTo(target);
258 } 273 }
259 } 274 }
260 } 275 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/cps_ir/mutable_ssa.dart ('k') | pkg/compiler/lib/src/cps_ir/redundant_phi.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698