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

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 19 matching lines...) Expand all
30 add(instruction.inputs[i]); 30 add(instruction.inputs[i]);
31 } 31 }
32 } 32 }
33 } 33 }
34 34
35 void addAll(Environment other) { 35 void addAll(Environment other) {
36 lives.addAll(other.lives); 36 lives.addAll(other.lives);
37 } 37 }
38 38
39 List<HInstruction> buildAndSetLast(HInstruction instruction) { 39 List<HInstruction> buildAndSetLast(HInstruction instruction) {
40 remove(instruction);
floitsch 2012/02/22 17:22:32 keep.
41 List<HInstruction> result = new List<HInstruction>.from(lives); 40 List<HInstruction> result = new List<HInstruction>.from(lives);
42 result.addLast(instruction); 41 result.addLast(instruction);
43 add(instruction);
44 return result; 42 return result;
45 } 43 }
46 44
47 bool isEmpty() => lives.isEmpty(); 45 bool isEmpty() => lives.isEmpty();
48 bool contains(HInstruction instruction) => lives.contains(instruction); 46 bool contains(HInstruction instruction) => lives.contains(instruction);
47 void clear() => lives.clear();
49 } 48 }
50 49
51 /** 50 /**
52 * Computes the environment for each SSA instruction: visits the graph 51 * Computes the environment for each SSA instruction: visits the graph
53 * in post-dominator order. Removes an instruction from the environment 52 * in post-dominator order. Removes an instruction from the environment
54 * and adds its inputs to the environment at the instruction's 53 * and adds its inputs to the environment at the instruction's
55 * definition. 54 * definition.
56 */ 55 */
57 class SsaEnvironmentBuilder extends HBaseVisitor { 56 class SsaEnvironmentBuilder extends HBaseVisitor {
58 final Compiler compiler; 57 final Compiler compiler;
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 192
194 if (!branch.isDoWhile()) { 193 if (!branch.isDoWhile()) {
195 assert(block.successors[0] == block.dominatedBlocks[0]); 194 assert(block.successors[0] == block.dominatedBlocks[0]);
196 visitBasicBlock(block.successors[0]); 195 visitBasicBlock(block.successors[0]);
197 } 196 }
198 } 197 }
199 198
200 // Deal with all kinds of control flow instructions. In case we add 199 // Deal with all kinds of control flow instructions. In case we add
201 // a new one, we will hit an internal error. 200 // a new one, we will hit an internal error.
202 void visitExit(HExit exit) {} 201 void visitExit(HExit exit) {}
203 void visitReturn(HReturn instruction) {} 202
204 void visitThrow(HThrow instruction) {} 203 void visitReturn(HReturn instruction) {
204 environment.clear();
205 visitInstruction(instruction);
206 }
207
208 void visitThrow(HThrow instruction) {
209 environment.clear();
210 visitInstruction(instruction);
211 }
205 212
206 void visitControlFlow(HControlFlow instruction) { 213 void visitControlFlow(HControlFlow instruction) {
207 compiler.internalError('Control flow instructions already dealt with.', 214 compiler.internalError('Control flow instructions already dealt with.',
208 instruction: instruction); 215 instruction: instruction);
209 } 216 }
210 } 217 }
211 218
212 /** 219 /**
213 * Visits the graph and replaces guards with guards that capture the 220 * Visits the graph and replaces guards with guards that capture the
214 * environment. 221 * environment.
215 */ 222 */
216 class SsaTypeGuardBuilder extends SsaEnvironmentBuilder { 223 class SsaTypeGuardBuilder extends SsaEnvironmentBuilder {
217 224
218 SsaTypeGuardBuilder(Compiler compiler) : super(compiler); 225 SsaTypeGuardBuilder(Compiler compiler) : super(compiler);
219 226
220 HInstruction tryInsertTypeGuard(HInstruction instruction, 227 void tryInsertTypeGuard(HInstruction instruction,
221 HInstruction insertionPoint) { 228 HInstruction insertionPoint) {
222 // If we found a type for the instruction, but the instruction 229 // If we found a type for the instruction, but the instruction
223 // does not know if it produces that type, add a type guard. 230 // does not know if it produces that type, add a type guard.
224 if (instruction.type.isKnown() && !instruction.hasExpectedType()) { 231 if (instruction.type.isKnown() && !instruction.hasExpectedType()) {
225 // The type guard expects the guarded instruction to be at the 232 // The type guard expects the guarded instruction to be at the
226 // end of the inputs. 233 // end of the inputs.
227 List<HInstruction> inputs = environment.buildAndSetLast(instruction); 234 List<HInstruction> inputs = environment.buildAndSetLast(instruction);
228 HTypeGuard guard = 235 HTypeGuard guard =
229 new HTypeGuard(instruction.type, inputs, instruction.id); 236 new HTypeGuard(instruction.type, inputs, instruction.id);
230 // Remove the instruction's type, the guard is now holding that 237 // Remove the instruction's type, the guard is now holding that
231 // type. 238 // type.
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 compiler.internalError('Control flow instructions already dealt with.', 347 compiler.internalError('Control flow instructions already dealt with.',
341 instruction: instruction); 348 instruction: instruction);
342 } 349 }
343 350
344 visitBailoutTarget(HBailoutTarget target) { 351 visitBailoutTarget(HBailoutTarget target) {
345 blocks.forEach((HBasicBlock block) { 352 blocks.forEach((HBasicBlock block) {
346 block.bailouts.add(target); 353 block.bailouts.add(target);
347 }); 354 });
348 } 355 }
349 } 356 }
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