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

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

Issue 1444363002: dart2js cps: Global value numbering and loop-invariant code motion. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Add comment Created 5 years, 1 month 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 library dart2js.cps_ir.loop_effects; 1 library dart2js.cps_ir.loop_effects;
2 2
3 import 'cps_ir_nodes.dart'; 3 import 'cps_ir_nodes.dart';
4 import 'loop_hierarchy.dart'; 4 import 'loop_hierarchy.dart';
5 import 'type_mask_system.dart'; 5 import 'type_mask_system.dart';
6 import '../universe/side_effects.dart'; 6 import '../universe/side_effects.dart';
7 import '../elements/elements.dart'; 7 import '../elements/elements.dart';
8 import '../world.dart'; 8 import '../world.dart';
9 9
10 /// Determines which the [SideEffects] that may occur during each loop in 10 /// Determines which the [SideEffects] that may occur during each loop in
(...skipping 28 matching lines...) Expand all
39 /// True if the length of an indexable object may change between the loop 39 /// True if the length of an indexable object may change between the loop
40 /// entry and a recursive invocation of the loop. 40 /// entry and a recursive invocation of the loop.
41 bool loopChangesLength(Continuation loop) { 41 bool loopChangesLength(Continuation loop) {
42 return loopsChangingLength.contains(loop); 42 return loopsChangingLength.contains(loop);
43 } 43 }
44 44
45 @override 45 @override
46 Expression traverseContinuation(Continuation cont) { 46 Expression traverseContinuation(Continuation cont) {
47 if (cont.isRecursive) { 47 if (cont.isRecursive) {
48 SideEffects oldEffects = currentLoopSideEffects; 48 SideEffects oldEffects = currentLoopSideEffects;
49 Continuation oldLoopHeader = currentLoopHeader;
50 bool oldChangesLength = currentLoopChangesLength; 49 bool oldChangesLength = currentLoopChangesLength;
51 currentLoopHeader = cont;
52 loopSideEffects[cont] = currentLoopSideEffects = new SideEffects.empty(); 50 loopSideEffects[cont] = currentLoopSideEffects = new SideEffects.empty();
53 exitContinuations[cont] = <Continuation>[]; 51 exitContinuations[cont] = <Continuation>[];
54 pushAction(() { 52 pushAction(() {
55 oldEffects.add(currentLoopSideEffects); 53 oldEffects.add(currentLoopSideEffects);
56 if (currentLoopChangesLength) { 54 if (currentLoopChangesLength) {
57 loopsChangingLength.add(cont); 55 loopsChangingLength.add(cont);
58 } 56 }
59 currentLoopChangesLength = currentLoopChangesLength || oldChangesLength; 57 currentLoopChangesLength = currentLoopChangesLength || oldChangesLength;
60 currentLoopHeader = oldLoopHeader;
61 currentLoopSideEffects = oldEffects; 58 currentLoopSideEffects = oldEffects;
62 exitContinuations[cont].forEach(push); 59 exitContinuations[cont].forEach(push);
63 }); 60 });
64 } 61 }
62 Continuation oldLoopHeader = currentLoopHeader;
63 currentLoopHeader = loopHierarchy.getLoopHeader(cont);
64 pushAction(() {
65 currentLoopHeader = oldLoopHeader;
66 });
65 return cont.body; 67 return cont.body;
66 } 68 }
67 69
68 @override 70 @override
69 Expression traverseLetHandler(LetHandler node) { 71 Expression traverseLetHandler(LetHandler node) {
70 enqueueContinuation(node.handler); 72 enqueueContinuation(node.handler);
71 return node.body; 73 return node.body;
72 } 74 }
73 75
74 @override 76 @override
75 Expression traverseLetCont(LetCont node) { 77 Expression traverseLetCont(LetCont node) {
76 node.continuations.forEach(enqueueContinuation); 78 node.continuations.forEach(enqueueContinuation);
77 return node.body; 79 return node.body;
78 } 80 }
79 81
80 void enqueueContinuation(Continuation cont) { 82 void enqueueContinuation(Continuation cont) {
81 Continuation loop = loopHierarchy.getEnclosingLoop(cont); 83 Continuation loop = loopHierarchy.getEnclosingLoop(cont);
82 if (loop == currentLoopHeader) { 84 if (loop == currentLoopHeader) {
83 push(cont); 85 push(cont);
84 } else { 86 } else {
85 // Multiple loops can be exited at once. 87 // Multiple loops can be exited at once.
86 // Register as an exit from the outermost loop being exited. 88 // Register as an exit from the outermost loop being exited.
87 Continuation inner = currentLoopHeader; 89 Continuation inner = currentLoopHeader;
88 Continuation outer = loopHierarchy.getEnclosingLoop(currentLoopHeader); 90 Continuation outer = loopHierarchy.getEnclosingLoop(currentLoopHeader);
89 while (outer != loop) { 91 while (outer != loop) {
92 if (inner == null) {
93 // The shrinking reductions pass must run before any pass that relies
94 // on computing loop side effects.
95 throw 'Unreachable continuations must be removed before computing '
96 'loop side effects.';
asgerf 2015/11/16 15:42:39 This is similar to the problem of putting unreacha
sra1 2015/11/17 05:41:14 Use the proper internal error (possibly as separat
asgerf 2015/11/17 12:43:43 Done.
97 }
90 inner = outer; 98 inner = outer;
91 outer = loopHierarchy.getEnclosingLoop(outer); 99 outer = loopHierarchy.getEnclosingLoop(outer);
92 } 100 }
93 exitContinuations[inner].add(cont); 101 exitContinuations[inner].add(cont);
94 } 102 }
95 } 103 }
96 104
97 void addSideEffects(SideEffects effects) { 105 void addSideEffects(SideEffects effects) {
98 currentLoopSideEffects.add(effects); 106 currentLoopSideEffects.add(effects);
99 if (effects.changesIndex()) { 107 if (effects.changesIndex()) {
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 172
165 void visitAwait(Await node) { 173 void visitAwait(Await node) {
166 addAllSideEffects(); 174 addAllSideEffects();
167 } 175 }
168 176
169 void visitYield(Yield node) { 177 void visitYield(Yield node) {
170 addAllSideEffects(); 178 addAllSideEffects();
171 } 179 }
172 180
173 void visitApplyBuiltinMethod(ApplyBuiltinMethod node) { 181 void visitApplyBuiltinMethod(ApplyBuiltinMethod node) {
182 currentLoopSideEffects.setChangesIndex();
174 currentLoopChangesLength = true; // Push and pop. 183 currentLoopChangesLength = true; // Push and pop.
175 } 184 }
176 } 185 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698