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

Side by Side Diff: frog/leg/ssa/bailout.dart

Issue 9372107: A return and a throw should empty the environment. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | tests/language/src/ReturnInLoopTest.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 BailoutInfo { 5 class BailoutInfo {
6 int instructionId; 6 int instructionId;
7 int bailoutId; 7 int bailoutId;
8 BailoutInfo(this.instructionId, this.bailoutId); 8 BailoutInfo(this.instructionId, this.bailoutId);
9 } 9 }
10 10
(...skipping 28 matching lines...) Expand all
39 List<HInstruction> buildAndSetLast(HInstruction instruction) { 39 List<HInstruction> buildAndSetLast(HInstruction instruction) {
40 remove(instruction); 40 remove(instruction);
41 List<HInstruction> result = new List<HInstruction>.from(lives); 41 List<HInstruction> result = new List<HInstruction>.from(lives);
42 result.addLast(instruction); 42 result.addLast(instruction);
43 add(instruction); 43 add(instruction);
44 return result; 44 return result;
45 } 45 }
46 46
47 bool isEmpty() => lives.isEmpty(); 47 bool isEmpty() => lives.isEmpty();
48 bool contains(HInstruction instruction) => lives.contains(instruction); 48 bool contains(HInstruction instruction) => lives.contains(instruction);
49 void clear() => lives.clear();
49 } 50 }
50 51
51 /** 52 /**
52 * Computes the environment for each SSA instruction: visits the graph 53 * Computes the environment for each SSA instruction: visits the graph
53 * in post-dominator order. Removes an instruction from the environment 54 * in post-dominator order. Removes an instruction from the environment
54 * and adds its inputs to the environment at the instruction's 55 * and adds its inputs to the environment at the instruction's
55 * definition. 56 * definition.
56 */ 57 */
57 class SsaEnvironmentBuilder extends HBaseVisitor { 58 class SsaEnvironmentBuilder extends HBaseVisitor {
58 final Compiler compiler; 59 final Compiler compiler;
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 194
194 if (!branch.isDoWhile()) { 195 if (!branch.isDoWhile()) {
195 assert(block.successors[0] == block.dominatedBlocks[0]); 196 assert(block.successors[0] == block.dominatedBlocks[0]);
196 visitBasicBlock(block.successors[0]); 197 visitBasicBlock(block.successors[0]);
197 } 198 }
198 } 199 }
199 200
200 // Deal with all kinds of control flow instructions. In case we add 201 // Deal with all kinds of control flow instructions. In case we add
201 // a new one, we will hit an internal error. 202 // a new one, we will hit an internal error.
202 void visitExit(HExit exit) {} 203 void visitExit(HExit exit) {}
203 void visitReturn(HReturn instruction) {} 204
204 void visitThrow(HThrow instruction) {} 205 void visitReturn(HReturn instruction) {
206 environment.clear();
207 visitInstruction(instruction);
208 }
209
210 void visitThrow(HThrow instruction) {
211 environment.clear();
212 visitInstruction(instruction);
213 }
205 214
206 void visitControlFlow(HControlFlow instruction) { 215 void visitControlFlow(HControlFlow instruction) {
207 compiler.internalError('Control flow instructions already dealt with.', 216 compiler.internalError('Control flow instructions already dealt with.',
208 instruction: instruction); 217 instruction: instruction);
209 } 218 }
210 } 219 }
211 220
212 /** 221 /**
213 * Visits the graph and replaces guards with guards that capture the 222 * Visits the graph and replaces guards with guards that capture the
214 * environment. 223 * environment.
215 */ 224 */
216 class SsaTypeGuardBuilder extends SsaEnvironmentBuilder { 225 class SsaTypeGuardBuilder extends SsaEnvironmentBuilder {
217 226
218 SsaTypeGuardBuilder(Compiler compiler) : super(compiler); 227 SsaTypeGuardBuilder(Compiler compiler) : super(compiler);
219 228
220 HInstruction tryInsertTypeGuard(HInstruction instruction, 229 void tryInsertTypeGuard(HInstruction instruction,
221 HInstruction insertionPoint) { 230 HInstruction insertionPoint) {
222 // If we found a type for the instruction, but the instruction 231 // If we found a type for the instruction, but the instruction
223 // does not know if it produces that type, add a type guard. 232 // does not know if it produces that type, add a type guard.
224 if (instruction.type.isKnown() && !instruction.hasExpectedType()) { 233 if (instruction.type.isKnown() && !instruction.hasExpectedType()) {
225 // The type guard expects the guarded instruction to be at the 234 // The type guard expects the guarded instruction to be at the
226 // end of the inputs. 235 // end of the inputs.
227 List<HInstruction> inputs = environment.buildAndSetLast(instruction); 236 List<HInstruction> inputs = environment.buildAndSetLast(instruction);
228 HTypeGuard guard = 237 HTypeGuard guard =
229 new HTypeGuard(instruction.type, inputs, instruction.id); 238 new HTypeGuard(instruction.type, inputs, instruction.id);
230 // Remove the instruction's type, the guard is now holding that 239 // Remove the instruction's type, the guard is now holding that
231 // type. 240 // type.
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 compiler.internalError('Control flow instructions already dealt with.', 349 compiler.internalError('Control flow instructions already dealt with.',
341 instruction: instruction); 350 instruction: instruction);
342 } 351 }
343 352
344 visitBailoutTarget(HBailoutTarget target) { 353 visitBailoutTarget(HBailoutTarget target) {
345 blocks.forEach((HBasicBlock block) { 354 blocks.forEach((HBasicBlock block) {
346 block.bailouts.add(target); 355 block.bailouts.add(target);
347 }); 356 });
348 } 357 }
349 } 358 }
OLDNEW
« no previous file with comments | « no previous file | tests/language/src/ReturnInLoopTest.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698