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 | 4 |
5 library dart2js.cps_ir.let_sinking; | 5 library dart2js.cps_ir.let_sinking; |
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 /// Sinks single-use primitives to the use when this is safe and profitable. | 10 /// Sinks single-use primitives to the use when this is safe and profitable. |
(...skipping 20 matching lines...) Expand all Loading... |
31 LoopHierarchy loopHierarchy; | 31 LoopHierarchy loopHierarchy; |
32 List<Continuation> stack = <Continuation>[]; | 32 List<Continuation> stack = <Continuation>[]; |
33 Set<LetPrim> sunkNodes = new Set<LetPrim>(); | 33 Set<LetPrim> sunkNodes = new Set<LetPrim>(); |
34 | 34 |
35 void rewrite(FunctionDefinition node) { | 35 void rewrite(FunctionDefinition node) { |
36 new ParentVisitor().visit(node); | 36 new ParentVisitor().visit(node); |
37 loopHierarchy = new LoopHierarchy(node); | 37 loopHierarchy = new LoopHierarchy(node); |
38 visit(node.body); | 38 visit(node.body); |
39 } | 39 } |
40 | 40 |
41 void visitLetPrim(LetPrim node) { | 41 @override |
| 42 Expression traverseLetPrim(LetPrim node) { |
| 43 pushAction(() { |
| 44 if (node.primitive != null) { |
| 45 // The primitive could not be sunk. Sink dependencies to this location. |
| 46 visit(node.primitive); |
| 47 } else { |
| 48 // The primitive was sunk. Destroy the old LetPrim. |
| 49 InteriorNode parent = node.parent; |
| 50 parent.body = node.body; |
| 51 node.body.parent = parent; |
| 52 } |
| 53 }); |
| 54 |
42 // Visit the body, wherein this primitive may be sunk to its use site. | 55 // Visit the body, wherein this primitive may be sunk to its use site. |
43 visit(node.body); | 56 return node.body; |
44 | |
45 if (node.primitive != null) { | |
46 // The primitive could not be sunk. Sink dependencies to this location. | |
47 visit(node.primitive); | |
48 } else { | |
49 // The primitive was sunk. Destroy the old LetPrim. | |
50 InteriorNode parent = node.parent; | |
51 parent.body = node.body; | |
52 node.body.parent = parent; | |
53 } | |
54 } | 57 } |
55 | 58 |
56 void processReference(Reference ref) { | 59 void processReference(Reference ref) { |
57 Definition definition = ref.definition; | 60 Definition definition = ref.definition; |
58 if (definition is Primitive && | 61 if (definition is Primitive && |
59 definition is! Parameter && | 62 definition is! Parameter && |
60 definition.hasExactlyOneUse && | 63 definition.hasExactlyOneUse && |
61 definition.isSafeForReordering) { | 64 definition.isSafeForReordering) { |
62 // Check if use is in the same loop. | 65 // Check if use is in the same loop. |
63 LetPrim binding = definition.parent; | 66 LetPrim binding = definition.parent; |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 target = _markInnerLoop(target, catchLoop); | 237 target = _markInnerLoop(target, catchLoop); |
235 for (Continuation cont in callContinuations) { | 238 for (Continuation cont in callContinuations) { |
236 // Store the loop target on each call continuation in the basic block. | 239 // Store the loop target on each call continuation in the basic block. |
237 // Because we walk over call continuations as part of the basic block | 240 // Because we walk over call continuations as part of the basic block |
238 // traversal, these do not get their loop target set otherwise. | 241 // traversal, these do not get their loop target set otherwise. |
239 loopTarget[cont] = target; | 242 loopTarget[cont] = target; |
240 } | 243 } |
241 return target; | 244 return target; |
242 } | 245 } |
243 } | 246 } |
OLD | NEW |