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

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

Issue 1699033003: dart2js cps: Combine integer type check with bounds check. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Update status Created 4 years, 10 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
OLDNEW
1 library dart2js.cps_ir.finalize; 1 library dart2js.cps_ir.finalize;
2 2
3 import 'cps_ir_nodes.dart'; 3 import 'cps_ir_nodes.dart';
4 import 'cps_fragment.dart'; 4 import 'cps_fragment.dart';
5 import 'optimizers.dart' show Pass; 5 import 'optimizers.dart' show Pass;
6 import '../js_backend/js_backend.dart' show JavaScriptBackend; 6 import '../js_backend/js_backend.dart' show JavaScriptBackend;
7 import '../js_backend/backend_helpers.dart'; 7 import '../js_backend/backend_helpers.dart';
8 import '../js/js.dart' as js; 8 import '../js/js.dart' as js;
9 9
10 /// A transformation pass that must run immediately before the tree IR builder. 10 /// A transformation pass that must run immediately before the tree IR builder.
(...skipping 24 matching lines...) Expand all
35 return first.parent == second.parent.parent; 35 return first.parent == second.parent.parent;
36 } 36 }
37 37
38 CpsFragment visitBoundsCheck(BoundsCheck node) { 38 CpsFragment visitBoundsCheck(BoundsCheck node) {
39 CpsFragment cps = new CpsFragment(node.sourceInformation); 39 CpsFragment cps = new CpsFragment(node.sourceInformation);
40 if (node.hasNoChecks) { 40 if (node.hasNoChecks) {
41 node..replaceUsesWith(node.object.definition)..destroy(); 41 node..replaceUsesWith(node.object.definition)..destroy();
42 return cps; 42 return cps;
43 } 43 }
44 Continuation fail = cps.letCont(); 44 Continuation fail = cps.letCont();
45 if (node.hasLowerBoundCheck) { 45 Primitive index = node.index.definition;
46 if (node.hasIntegerCheck) {
47 cps.ifTruthy(cps.applyBuiltin(BuiltinOperator.IsNotUnsigned32BitInteger,
48 [index, index]))
49 .invokeContinuation(fail);
50 } else if (node.hasLowerBoundCheck) {
46 cps.ifTruthy(cps.applyBuiltin(BuiltinOperator.NumLt, 51 cps.ifTruthy(cps.applyBuiltin(BuiltinOperator.NumLt,
47 [node.index.definition, cps.makeZero()])) 52 [index, cps.makeZero()]))
48 .invokeContinuation(fail); 53 .invokeContinuation(fail);
49 } 54 }
50 if (node.hasUpperBoundCheck) { 55 if (node.hasUpperBoundCheck) {
51 Primitive length = node.length.definition; 56 Primitive length = node.length.definition;
52 if (length is GetLength && 57 if (length is GetLength &&
53 length.hasExactlyOneUse && 58 length.hasExactlyOneUse &&
54 areAdjacent(length, node)) { 59 areAdjacent(length, node)) {
55 // Rebind the GetLength here, so it does not get stuck outside the 60 // Rebind the GetLength here, so it does not get stuck outside the
56 // condition, blocked from propagating by the lower bounds check. 61 // condition, blocked from propagating by the lower bounds check.
57 LetPrim lengthBinding = length.parent; 62 LetPrim lengthBinding = length.parent;
58 lengthBinding.remove(); 63 lengthBinding.remove();
59 cps.letPrim(length); 64 cps.letPrim(length);
60 } 65 }
61 cps.ifTruthy(cps.applyBuiltin(BuiltinOperator.NumGe, 66 cps.ifTruthy(cps.applyBuiltin(BuiltinOperator.NumGe,
62 [node.index.definition, length])) 67 [index, length]))
63 .invokeContinuation(fail); 68 .invokeContinuation(fail);
64 } 69 }
65 if (node.hasEmptinessCheck) { 70 if (node.hasEmptinessCheck) {
66 cps.ifTruthy(cps.applyBuiltin(BuiltinOperator.StrictEq, 71 cps.ifTruthy(cps.applyBuiltin(BuiltinOperator.StrictEq,
67 [node.length.definition, cps.makeZero()])) 72 [node.length.definition, cps.makeZero()]))
68 .invokeContinuation(fail); 73 .invokeContinuation(fail);
69 } 74 }
70 cps.insideContinuation(fail).invokeStaticThrower( 75 cps.insideContinuation(fail).invokeStaticThrower(
71 helpers.throwIndexOutOfRangeException, 76 helpers.throwIndexOutOfRangeException,
72 [node.object.definition, node.index.definition]); 77 [node.object.definition, index]);
73 node..replaceUsesWith(node.object.definition)..destroy(); 78 node..replaceUsesWith(node.object.definition)..destroy();
74 return cps; 79 return cps;
75 } 80 }
76 81
77 void visitGetStatic(GetStatic node) { 82 void visitGetStatic(GetStatic node) {
78 if (node.witness != null) { 83 if (node.witness != null) {
79 node..witness.unlink()..witness = null; 84 node..witness.unlink()..witness = null;
80 } 85 }
81 } 86 }
82 87
83 void visitForeignCode(ForeignCode node) { 88 void visitForeignCode(ForeignCode node) {
84 if (js.isIdentityTemplate(node.codeTemplate)) { 89 if (js.isIdentityTemplate(node.codeTemplate)) {
85 // The CPS builder replaces identity templates with refinements, except 90 // The CPS builder replaces identity templates with refinements, except
86 // when the refined type is an array type. Some optimizations assume the 91 // when the refined type is an array type. Some optimizations assume the
87 // type of an object is immutable, but the type of an array can change 92 // type of an object is immutable, but the type of an array can change
88 // after allocation. After the finalize pass, this assumption is no 93 // after allocation. After the finalize pass, this assumption is no
89 // longer needed, so we can replace the remaining idenitity templates. 94 // longer needed, so we can replace the remaining idenitity templates.
90 Refinement refinement = new Refinement( 95 Refinement refinement = new Refinement(
91 node.arguments.single.definition, 96 node.arguments.single.definition,
92 node.type)..type = node.type; 97 node.type)..type = node.type;
93 node.replaceWith(refinement); 98 node.replaceWith(refinement);
94 } 99 }
95 } 100 }
96 } 101 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698