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

Side by Side Diff: pkg/compiler/lib/src/cps_ir/redundant_refinement.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
(Empty)
1 library dart2js.cps_ir.redundant_refinement;
2
3 import 'cps_ir_nodes.dart';
4 import 'optimizers.dart' show Pass;
5 import 'type_mask_system.dart';
6
7 /// Removes [Refinement] nodes where the input value is already known to
8 /// satisfy the refinement type.
9 ///
10 /// Note: This pass improves loop-invariant code motion in the GVN pass because
11 /// GVN will currently not hoist a primitive across a refinement guard.
12 /// But some opportunities for hoisting are still missed. Ideally, this pass
sra1 2015/11/17 05:41:15 Which are still missed?
asgerf 2015/11/17 12:43:43 Added example.
13 /// should go away and GVN should handle refinements directly.
14 class RedundantRefinementEliminator extends TrampolineRecursiveVisitor
15 implements Pass {
16 String get passName => 'Redundant refinement elimination';
17
18 TypeMaskSystem typeSystem;
19
20 RedundantRefinementEliminator(this.typeSystem);
21
22 void rewrite(FunctionDefinition node) {
23 visit(node);
24 }
25
26 Expression traverseLetPrim(LetPrim node) {
27 Expression next = node.body;
28 if (node.primitive is Refinement) {
29 Refinement refinement = node.primitive;
30 Primitive value = refinement.value.definition;
31 if (typeSystem.isMorePreciseOrEqual(value.type, refinement.refineType)) {
32 value.substituteFor(refinement);
33 refinement.destroy();
34 node.remove();
35 return next;
36 }
37 }
38 return next;
39 }
40 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698