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

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

Issue 1583263007: dart2js cps: Update null checks when updating refinements. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Fix type annotations 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, Refinement> refinementFor = <Primitive, Refinement>{}; 23 Map<Primitive, Primitive> refinementFor = <Primitive, Primitive>{};
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;
32 visit(node.primitive); 33 visit(node.primitive);
33 return node.body; 34 return next;
34 } 35 }
35 36
36 @override 37 visitNullCheck(NullCheck node) {
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 Primitive old = refinementFor[value];
53 refinementFor[value] = node;
54 pushAction(() {
55 refinementFor[value] = old;
56 });
57 }
58
37 visitRefinement(Refinement node) { 59 visitRefinement(Refinement node) {
38 if (refine(node.value)) { 60 if (refine(node.value)) {
39 // Update the type if the input has changed. 61 // Update the type if the input has changed.
40 node.type = typeSystem.intersection(node.value.definition.type, 62 node.type = typeSystem.intersection(node.value.definition.type,
41 node.refineType); 63 node.refineType);
42 } 64 }
43 Primitive value = node.effectiveDefinition; 65 Primitive value = node.effectiveDefinition;
44 Refinement old = refinementFor[value]; 66 Primitive old = refinementFor[value];
45 refinementFor[value] = node; 67 refinementFor[value] = node;
46 pushAction(() { 68 pushAction(() {
47 refinementFor[value] = old; 69 refinementFor[value] = old;
48 }); 70 });
49 } 71 }
50 72
51 @override
52 processReference(Reference ref) { 73 processReference(Reference ref) {
53 refine(ref); 74 refine(ref);
54 } 75 }
55 76
56 bool refine(Reference ref) { 77 bool refine(Reference ref) {
57 Definition def = ref.definition; 78 Definition def = ref.definition;
58 if (def is Primitive) { 79 if (def is Primitive) {
59 Refinement refinement = refinementFor[def.effectiveDefinition]; 80 Primitive refinement = refinementFor[def.effectiveDefinition];
60 if (refinement != null && refinement != ref.definition) { 81 if (refinement != null && refinement != ref.definition) {
61 ref.changeTo(refinement); 82 ref.changeTo(refinement);
62 return true; 83 return true;
63 } 84 }
64 } 85 }
65 return false; 86 return false;
66 } 87 }
67 } 88 }
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