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

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

Issue 1605203002: Revert "dart2js cps: Update null checks when updating refinements." (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 11 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
« no previous file with comments | « no previous file | pkg/compiler/lib/src/js_backend/codegen/task.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 library dart2js.cps_ir.update_refinements; 1 library dart2js.cps_ir.update_refinements;
2 2
3 import 'cps_ir_nodes.dart'; 3 import 'cps_ir_nodes.dart';
4 import 'optimizers.dart' show Pass; 4 import 'optimizers.dart' show Pass;
5 import 'type_mask_system.dart'; 5 import 'type_mask_system.dart';
6 6
7 /// Updates all references to use the most refined version in scope. 7 /// Updates all references to use the most refined version in scope.
8 /// 8 ///
9 /// [GVN] and [RedundantJoinElimination], and possibly other passes, can create 9 /// [GVN] and [RedundantJoinElimination], and possibly other passes, can create
10 /// references that don't use the best refinement in scope. This pass improves 10 /// references that don't use the best refinement in scope. This pass improves
11 /// the refinement information. 11 /// the refinement information.
12 /// 12 ///
13 // 13 //
14 // TODO(asgerf): Could be done during GVN for another adjacent pass. 14 // TODO(asgerf): Could be done during GVN for another adjacent pass.
15 // It is easier to measure performance and rearrange passes when it has its 15 // It is easier to measure performance and rearrange passes when it has its
16 // own pass, but we can merge it with an adjacent pass later. 16 // own pass, but we can merge it with an adjacent pass later.
17 // 17 //
18 class UpdateRefinements extends TrampolineRecursiveVisitor implements Pass { 18 class UpdateRefinements extends TrampolineRecursiveVisitor implements Pass {
19 String get passName => 'Update refinements'; 19 String get passName => 'Update refinements';
20 20
21 final TypeMaskSystem typeSystem; 21 final TypeMaskSystem typeSystem;
22 22
23 Map<Primitive, Primitive> refinementFor = <Primitive, Primitive>{}; 23 Map<Primitive, Refinement> refinementFor = <Primitive, Refinement>{};
24 24
25 UpdateRefinements(this.typeSystem); 25 UpdateRefinements(this.typeSystem);
26 26
27 void rewrite(FunctionDefinition node) { 27 void rewrite(FunctionDefinition node) {
28 visit(node); 28 visit(node);
29 } 29 }
30 30
31 Expression traverseLetPrim(LetPrim node) { 31 Expression traverseLetPrim(LetPrim node) {
32 Expression next = node.body;
33 visit(node.primitive); 32 visit(node.primitive);
34 return next; 33 return node.body;
35 } 34 }
36 35
37 visitNullCheck(NullCheck node) { 36 @override
38 if (refine(node.value)) {
39 Primitive value = node.value.definition;
40 if (value.type.isNullable) {
41 // Update the type if the input has changed.
42 node.type = value.type.nonNullable();
43 } else {
44 node..replaceUsesWith(value)..destroy();
45 LetPrim letPrim = node.parent;
46 letPrim.remove();
47 return;
48 }
49 }
50 // Use the NullCheck as a refinement.
51 Primitive value = node.effectiveDefinition;
52 Refinement old = refinementFor[value];
53 refinementFor[value] = node;
54 pushAction(() {
55 refinementFor[value] = old;
56 });
57 }
58
59 visitRefinement(Refinement node) { 37 visitRefinement(Refinement node) {
60 if (refine(node.value)) { 38 if (refine(node.value)) {
61 // Update the type if the input has changed. 39 // Update the type if the input has changed.
62 node.type = typeSystem.intersection(node.value.definition.type, 40 node.type = typeSystem.intersection(node.value.definition.type,
63 node.refineType); 41 node.refineType);
64 } 42 }
65 Primitive value = node.effectiveDefinition; 43 Primitive value = node.effectiveDefinition;
66 Refinement old = refinementFor[value]; 44 Refinement old = refinementFor[value];
67 refinementFor[value] = node; 45 refinementFor[value] = node;
68 pushAction(() { 46 pushAction(() {
69 refinementFor[value] = old; 47 refinementFor[value] = old;
70 }); 48 });
71 } 49 }
72 50
51 @override
73 processReference(Reference ref) { 52 processReference(Reference ref) {
74 refine(ref); 53 refine(ref);
75 } 54 }
76 55
77 bool refine(Reference ref) { 56 bool refine(Reference ref) {
78 Definition def = ref.definition; 57 Definition def = ref.definition;
79 if (def is Primitive) { 58 if (def is Primitive) {
80 Refinement refinement = refinementFor[def.effectiveDefinition]; 59 Refinement refinement = refinementFor[def.effectiveDefinition];
81 if (refinement != null && refinement != ref.definition) { 60 if (refinement != null && refinement != ref.definition) {
82 ref.changeTo(refinement); 61 ref.changeTo(refinement);
83 return true; 62 return true;
84 } 63 }
85 } 64 }
86 return false; 65 return false;
87 } 66 }
88 } 67 }
OLDNEW
« no previous file with comments | « no previous file | pkg/compiler/lib/src/js_backend/codegen/task.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698