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

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

Issue 1519513002: dart2js cps: Retain refinement nodes and update refinements after GVN. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Undo removed passes Created 5 years 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.gvn; 5 library dart2js.cps_ir.gvn;
6 6
7 import 'cps_ir_nodes.dart'; 7 import 'cps_ir_nodes.dart';
8 import '../universe/side_effects.dart'; 8 import '../universe/side_effects.dart';
9 import '../elements/elements.dart'; 9 import '../elements/elements.dart';
10 import 'optimizers.dart' show Pass; 10 import 'optimizers.dart' show Pass;
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 void rewrite(FunctionDefinition node) { 88 void rewrite(FunctionDefinition node) {
89 gvnVectorBuilder = new GvnVectorBuilder(gvnFor, backend); 89 gvnVectorBuilder = new GvnVectorBuilder(gvnFor, backend);
90 loopHierarchy = new LoopHierarchy(node); 90 loopHierarchy = new LoopHierarchy(node);
91 loopEffects = 91 loopEffects =
92 new LoopSideEffects(node, world, loopHierarchy: loopHierarchy); 92 new LoopSideEffects(node, world, loopHierarchy: loopHierarchy);
93 visit(node); 93 visit(node);
94 } 94 }
95 95
96 // ------------------ GLOBAL VALUE NUMBERING --------------------- 96 // ------------------ GLOBAL VALUE NUMBERING ---------------------
97 97
98 /// True if [prim] can be eliminated if its value is already in scope.
99 bool canReplaceWithExistingValue(Primitive prim) {
100 // Primitives that have no side effects other than potentially throwing are
101 // known not the throw if the value is already in scope. Handling those
102 // specially is equivalent to updating refinements during GVN.
103 // GetLazyStatic cannot have side effects because the field has already
104 // been initialized.
105 // TODO(asgerf): Replace GetLazyStatic in an earlier pass so it does not
106 // confuse the LoopSideEffects pre-analysis.
107 return prim.isSafeForElimination ||
108 prim is GetField ||
109 prim is GetLength ||
110 prim is GetIndex ||
111 prim is GetLazyStatic;
112 }
113
98 @override 114 @override
99 Expression traverseLetPrim(LetPrim node) { 115 Expression traverseLetPrim(LetPrim node) {
100 Expression next = node.body; 116 Expression next = node.body;
101 Primitive prim = node.primitive; 117 Primitive prim = node.primitive;
102 118
103 loopHeaderFor[prim] = currentLoopHeader; 119 loopHeaderFor[prim] = currentLoopHeader;
104 120
105 if (prim is Refinement) { 121 if (prim is Refinement) {
106 // Do not share refinements (they have no runtime or code size cost), and 122 // Do not share refinements (they have no runtime or code size cost), and
107 // do not put them in the GVN table because GvnVectorBuilder unfolds 123 // do not put them in the GVN table because GvnVectorBuilder unfolds
(...skipping 14 matching lines...) Expand all
122 return next; 138 return next;
123 } 139 }
124 140
125 // Compute the GVN for this primitive. 141 // Compute the GVN for this primitive.
126 int gvn = gvnTable.insert(vector); 142 int gvn = gvnTable.insert(vector);
127 gvnFor[prim] = gvn; 143 gvnFor[prim] = gvn;
128 144
129 // Try to reuse a previously computed value with the same GVN. 145 // Try to reuse a previously computed value with the same GVN.
130 Primitive existing = environment[gvn]; 146 Primitive existing = environment[gvn];
131 if (existing != null && 147 if (existing != null &&
132 (prim.isSafeForElimination || prim is GetLazyStatic) && 148 canReplaceWithExistingValue(prim) &&
133 !isTrivialPrimitive(prim)) { 149 !isTrivialPrimitive(prim)) {
134 if (prim is Interceptor) { 150 if (prim is Interceptor) {
135 Interceptor interceptor = existing; 151 Interceptor interceptor = existing;
136 interceptor.interceptedClasses.addAll(prim.interceptedClasses); 152 interceptor.interceptedClasses.addAll(prim.interceptedClasses);
137 interceptor.flags |= prim.flags; 153 interceptor.flags |= prim.flags;
138 } 154 }
139 prim..replaceUsesWith(existing)..destroy(); 155 prim..replaceUsesWith(existing)..destroy();
140 node.remove(); 156 node.remove();
141 return next; 157 return next;
142 } 158 }
(...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after
697 713
698 @override 714 @override
699 processReference(Reference ref) { 715 processReference(Reference ref) {
700 callback(ref); 716 callback(ref);
701 } 717 }
702 718
703 static void forEach(Primitive node, ReferenceCallback callback) { 719 static void forEach(Primitive node, ReferenceCallback callback) {
704 new InputVisitor(callback).visit(node); 720 new InputVisitor(callback).visit(node);
705 } 721 }
706 } 722 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698